You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Initialize a new project and Go module for your controllers:
44
+
Create a directory, and then run the following command inside of it to initialize a new project:
35
45
36
46
```bash
37
47
kubebuilder init --domain my.domain
38
48
```
39
49
50
+
<asideclass="note">
51
+
<h1>Not in $GOPATH</h1>
52
+
40
53
If you're not in `GOPATH`, you'll need to run `go mod init <modulename>`
41
-
in order to tell kubebuilder and Go the base import path of your module.
54
+
in order to tell kubebuilder and Go the base import path of your module.
55
+
56
+
</aside>
57
+
58
+
<asideclass="note">
59
+
<h1>Go package issues</h1>
60
+
61
+
Ensure that you activate the module support by running `$ export GO111MODULE=on`
62
+
to solve issues as `cannot find package ... (from $GOROOT)`.
63
+
64
+
</aside>
65
+
42
66
43
67
## Create an API
44
68
45
-
Create a new API group-version called `webapp/v1`, and a kind `Guestbook`
46
-
in that API group-version:
69
+
Run the following command to create a new API (group/version) as `webapp/v1` and the new Kind(CRD) `Guestbook` on it:
47
70
48
71
```bash
49
72
kubebuilder create api --group webapp --version v1 --kind Guestbook
50
73
```
51
74
52
-
This will create the files `api/v1/guestbook_types.go` and
53
-
`controller/guestbook_controller.go` for you to edit.
75
+
<asideclass="note">
76
+
<h1>Press Options</h1>
77
+
78
+
If you press `y` for Create Resource [y/n] and for Create Controller [y/n] then this will create the files `api/v1/guestbook_types.go` where the API is defined
79
+
and the `controller/guestbook_controller.go` where the reconciliation business logic is implemented for this Kind(CRD).
80
+
81
+
</aside>
82
+
83
+
84
+
**OPTIONAL:** Edit the API definition and the reconciliation business
85
+
logic. For more info see [Designing an API](/cronjob-tutorial/api-design.md) and [What's in
86
+
a Controller](cronjob-tutorial/controller-overview.md).
87
+
88
+
<details><summary>Click here to see an example. `(api/v1/guestbook_types.go)` </summary>
89
+
<p>
90
+
91
+
```go
92
+
// GuestbookSpec defines the desired state of Guestbook
93
+
typeGuestbookSpecstruct {
94
+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
95
+
// Important: Run "make" to regenerate code after modifying this file
96
+
97
+
// Quantity of instances
98
+
// +kubebuilder:validation:Minimum=1
99
+
// +kubebuilder:validation:Maximum=10
100
+
Sizeint32`json:"size"`
101
+
102
+
// Name of the ConfigMap for GuestbookSpec's configuration
Run your controller (this will run in the foreground, so switch to a new
76
160
terminal if you want to leave it running):
77
-
78
161
```bash
79
162
make run
80
163
```
81
164
82
-
## Install Samples
165
+
## Install Instances of Custom Resources
83
166
84
-
Create your samples (make sure to edit them first if you've changed the
167
+
If you pressed `y` for Create Resource [y/n] then you created an (CR)Custom Resource for your (CRD)Custom Resource Definition in your samples (make sure to edit them first if you've changed the
Build and push your image to the location specified by `IMG`:
94
177
95
178
```bash
96
-
make docker-build docker-push IMG=<some-registry>/controller
179
+
make docker-build docker-push IMG=<some-registry>/<project-name>:tag
97
180
```
98
181
99
182
Deploy the controller to the cluster with image specified by `IMG`:
100
183
101
184
```bash
102
-
make deploy IMG=<some-registry>/controller
185
+
make deploy IMG=<some-registry>/<project-name>:tag
103
186
```
104
187
188
+
<asideclass="note">
189
+
<h1>RBAC errors</h1>
190
+
105
191
If you encounter RBAC errors, you may need to grant yourself cluster-admin
106
-
privileges:
192
+
privileges or be logged in as admin. See [Prerequisites for using Kubernetes RBAC on GKE cluster v1.11.x and older][pre-rbc-gke] which may can be your case.
193
+
194
+
</aside>
195
+
196
+
Now, follow up the tutorial for you understanding better how it works and check an full example project working.
0 commit comments