@@ -17,7 +17,8 @@ This guide walks through an example of building a simple memcached-operator usin
17
17
The Operator SDK has a CLI tool that helps the developer to create, build, and deploy a new operator project.
18
18
19
19
Checkout the desired release tag and install the SDK CLI tool:
20
- ```
20
+
21
+ ``` sh
21
22
$ git checkout tags/v0.0.2
22
23
$ go install github.com/coreos/operator-sdk/commands/operator-sdk
23
24
```
@@ -28,7 +29,7 @@ This installs the CLI binary `operator-sdk` at `$GOPATH/bin`.
28
29
29
30
Use the CLI to create a new memcached-operator project:
30
31
31
- ```
32
+ ``` sh
32
33
$ cd $GOPATH /src/github.com/example-inc/
33
34
$ operator-sdk new memcached-operator --api-version=cache.example.com/v1alpha1 --kind=Memcached
34
35
$ cd memcached-operator
@@ -73,7 +74,7 @@ type MemcachedStatus struct {
73
74
```
74
75
Update the generated code for the CR:
75
76
76
- ```
77
+ ``` sh
77
78
$ operator-sdk generate k8s
78
79
```
79
80
@@ -97,14 +98,14 @@ Kubernetes deployment manifests are generated in `deploy/operator.yaml`. The dep
97
98
98
99
Deploy the memcached-operator:
99
100
100
- ```
101
- kubectl create -f deploy/rbac.yaml
102
- kubectl create -f deploy/operator.yaml
101
+ ``` sh
102
+ $ kubectl create -f deploy/rbac.yaml
103
+ $ kubectl create -f deploy/operator.yaml
103
104
```
104
105
105
106
Verify that the memcached-operator is up and running:
106
107
107
- ```
108
+ ``` sh
108
109
$ kubectl get deployment
109
110
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
110
111
memcached-operator 1 1 1 1 1m
127
128
128
129
Ensure that the memcached-operator creates the deployment for the CR:
129
130
130
- ```
131
+ ``` sh
131
132
$ kubectl get deployment
132
133
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
133
134
memcached-operator 1 1 1 1 2m
@@ -136,7 +137,7 @@ example-memcached 3 3 3 3 1m
136
137
137
138
Check the pods and CR status to confirm the status is updated with the memcached pod names:
138
139
139
- ```
140
+ ``` sh
140
141
$ kubectl get pods
141
142
NAME READY STATUS RESTARTS AGE
142
143
example-memcached-6fd7c98d8-7dqdr 1/1 Running 0 1m
@@ -145,7 +146,7 @@ example-memcached-6fd7c98d8-m7vn7 1/1 Running 0 1m
145
146
memcached-operator-7cc7cfdf86-vvjqk 1/1 Running 0 2m
146
147
```
147
148
148
- ```
149
+ ``` sh
149
150
$ kubectl get memcached/example-memcached -o yaml
150
151
apiVersion: cache.example.com/v1alpha1
151
152
kind: Memcached
@@ -170,12 +171,14 @@ status:
170
171
### Update the size
171
172
172
173
Change the ` spec.size ` field in the memcached CR from 3 to 4:
173
- ```
174
+
175
+ ``` sh
174
176
$ kubectl get memcached/example-memcached -o yaml | sed ' s|size: 3|size: 4|g' | kubectl apply -f -
175
177
```
176
178
177
179
Confirm that the operator changes the deployment size:
178
- ```
180
+
181
+ ``` sh
179
182
$ kubectl get deployment
180
183
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
181
184
example-memcached 4 4 4 4 5m
@@ -185,9 +188,9 @@ example-memcached 4 4 4 4 5m
185
188
186
189
Clean up the resources:
187
190
188
- ```
189
- kubectl delete memcached example-memcached
190
- kubectl delete -f deploy/operator.yaml
191
+ ``` sh
192
+ $ kubectl delete memcached example-memcached
193
+ $ kubectl delete -f deploy/operator.yaml
191
194
```
192
195
193
196
[ memcached_handler ] : ../../example/memcached-operator/handler.go
0 commit comments