1
- {% panel style="info", title="Under Development" %}
2
- This book is being actively developed.
3
- {% endpanel %}
4
-
5
1
# Project Creation and Structure {#project-creation-and-structure}
6
2
7
3
## Go package Structure
8
4
9
- Kubebuilder projects contain 4 important packages.
5
+ Kubebuilder projects contain 3 important packages.
10
6
11
7
##### cmd/...
12
8
13
- The ` cmd ` package contains the controller-manager main program which runs controllers. Users typically
14
- will not need to modify this package unless they are doing something special.
9
+ The ` cmd ` package contains the manager main program. Manager is responsible for initializing
10
+ shared dependencies and starting / stopping Controllers. Users typically
11
+ will not need to edit this package and can rely on the scaffolding.
12
+
13
+ The ` cmd ` package is scaffolded automatically by ` kubebuilder init ` .
15
14
16
15
##### pkg/apis/...
17
16
18
- The ` pkg/apis/... ` packages contains the * go * structs that define the resource schemas .
19
- Users edit ` *_types.go ` files under this director to implement their API definitions.
17
+ The ` pkg/apis/... ` packages contains the API resource definitions .
18
+ Users edit the ` *_types.go ` files under this director to implement their API definitions.
20
19
21
20
Each resource lives in a ` pkg/apis/<api-group-name>/<api-version-name>/<api-kind-name>_types.go `
22
21
file.
23
22
24
- For more information on API Group, Version and Kinds, see the * What is a Resource* chapter.
25
-
26
- {% panel style="info", title="Generated code" %}
27
- Kubebuilder will generate boilerplate code required for Resources by running
28
- ` kubebuilder generate ` . The generated files are named ` zz_generated.* ` .
29
- {% endpanel %}
23
+ The ` pkg/apis ` package is scaffolded automatically by ` kubebuilder create api ` when creating a Resource.
30
24
31
25
##### pkg/controller/...
32
26
33
- The ` pkg/controller/... ` packages contain the * go* types and functions that implement the
34
- business logic for APIs in * controllers* .
27
+ The ` pkg/controller/... ` packages contain the Controller implementations.
28
+ Users edit the ` *_controller.go ` files under this directory to implement their Controllers.
29
+
30
+ The ` pkg/controller ` package is scaffolded automatically by ` kubebuilder create api ` when creating a Controller.
35
31
36
- More information on Controllers in the * What is a Controller * chapter.
32
+ ## Additional directories and files
37
33
38
- ##### pkg/inject/.. .
34
+ In addition to the packages above, a Kubebuilder project has several other directories and files .
39
35
40
- The ` pkg/inject/... ` packages contain the generated code that registers annotated
41
- Controllers and Resources.
36
+ ##### Makefile
42
37
43
- * Note* : This package is unique to kubebuilder.
38
+ A Makefile is created with targets to build, test, run and deploy the controller artifacts
39
+ for development as well as production workflows
44
40
45
- ## Additional directories
41
+ ##### Dockerfile
46
42
47
- In addition to the packages above, a Kubebuilder project has several other directories .
43
+ A Dockerfile is scaffolded to build a container image for your Manager .
48
44
49
- ##### hack /...
45
+ ##### config /...
50
46
51
- Kubebuilder puts miscellaneous files into the hack directory .
47
+ Kubebuilder creates yaml config for installing the CRDs and related objects under config/ .
52
48
53
- - API installation yaml
54
- - Samples resource configs
55
- - Headers for generated files: ` boilerplate.go.txt `
49
+ - config/crds
50
+ - config/manager
56
51
57
52
##### docs/...
58
53
@@ -71,7 +66,7 @@ that will be required to build your project.
71
66
72
67
{% sample lang="bash" %}
73
68
``` bash
74
- $ kubebuilder init --domain k8s.io
69
+ $ kubebuilder init --domain k8s.io --license apache2 --owners " The Kubernetes Authors "
75
70
```
76
71
{% endmethod %}
77
72
@@ -85,12 +80,12 @@ and [What Is A Controller](../basics/what_is_a_controller.md)
85
80
86
81
{% sample lang="bash" %}
87
82
``` bash
88
- $ kubebuilder create resource --group mygroup --version v1beta1 --kind MyKind
83
+ $ kubebuilder create api --group mygroup --version v1beta1 --kind MyKind
89
84
```
90
85
{% endmethod %}
91
86
92
87
{% method %}
93
- ## Run your controller- manager locally against a Kubernetes cluster
88
+ ## Run your manager locally against a Kubernetes cluster
94
89
95
90
Users may run the controller-manager binary locally against a Kubernetes cluster. This will
96
91
install the APIs into the cluster and begin watching and reconciling the resources.
@@ -100,19 +95,21 @@ install the APIs into the cluster and begin watching and reconciling the resourc
100
95
# Create a minikube cluster
101
96
$ minikube start
102
97
103
- # Install the APIs into the minikube cluster and begin watching it
104
- $ GOBIN=${PWD} /bin go install ${PWD# $GOPATH / src/ } /cmd/controller-manager
105
- $ bin/controller-manager --kubeconfig ~ /.kube/config
98
+ # Install the CRDs into the cluster
99
+ $ make install
100
+
101
+ # Build and run the manager
102
+ $ make run
106
103
```
107
104
{% endmethod %}
108
105
109
106
{% method %}
110
- ## Create an object
107
+ ## Create an instance
111
108
112
- Create a new instance of your Resource. Observe the controller- manager logs after creating the object.
109
+ Create a new instance of your Resource. Observe the manager logs printed to the console after creating the object.
113
110
114
111
{% sample lang="bash" %}
115
112
``` bash
116
- $ kubectl apply -f hack/ sample/< resource> .yaml
113
+ $ kubectl apply -f sample/< resource> .yaml
117
114
```
118
115
{% endmethod %}
0 commit comments