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
sed -i.bak 's|'{GOPATH}'|'${GOPATH}'|g' cluster/config.yaml
35
35
```
36
36
37
37
You can also open [config.yaml](cluster/config.yaml#L21) and replace `{GOPATH}` with the absolute path manually. If you already installed kind (Kubernetes in Docker) on your local system, you can create the cluster with this command:
@@ -115,7 +115,9 @@ We suggest labelling a worker node where the pod is going to be deployed. By def
This message will be shown, and it is just saying that the image was not there:
154
160
161
+
```
155
162
Image: "setlog/debug-k8s:latest" with ID "sha256:944baa03d49698b9ca1f22e1ce87b801a20ce5aa52ccfc648a6c82cf8708a783" not present on node "local-debug-k8s-worker"
163
+
```
156
164
157
165
### Starting the delve server in the cluster
158
166
159
167
Now we want to create a persistent volume and its claim in order to mount the project path into the worker node:
@@ -173,24 +183,31 @@ Let's take a look at the full chain of mounting the local project path into the
173
183
174
184
Check, if your persistent volume claim has been successfully created (STATUS must be Bound):
175
185
176
-
`kubectl get pvc`
186
+
```sh
187
+
kubectl get pvc
177
188
178
189
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
179
190
go-pvc Bound go-pv 256Mi RWO hostpath 51s
191
+
```
180
192
181
193
You are ready to start the service in debug mode:
182
194
183
-
`kubectl create -f cluster/deploy-service.yaml`
195
+
```sh
196
+
kubectl create -f cluster/deploy-service.yaml
197
+
```
184
198
185
199
Let's go through the deployment.
186
200
187
201
* Image name is what we loaded into the kind cluster with the command `kind load image...`. _imagePullPolicy_ must be set to _IfNotPresent_, because it is already loaded, we don't want Kubernetes to try loading it again.
188
202
189
-
image: setlog/debug-k8s:latest
190
-
imagePullPolicy: IfNotPresent
203
+
```yaml
204
+
image: setlog/debug-k8s:latest
205
+
imagePullPolicy: IfNotPresent
206
+
```
191
207
192
208
* We use the persistent volume claim to mount the project path into the pod and make `/go/src` to be linked with `${GOPATH}/src` on your computer:
193
209
210
+
```yaml
194
211
containers:
195
212
- name: debug-k8s
196
213
...
@@ -201,19 +218,22 @@ Let's go through the deployment.
201
218
- name: go-volume
202
219
persistentVolumeClaim:
203
220
claimName: go-pvc
221
+
````
204
222
205
223
* As there might be several workers in your cluster, we deploy the pod on the one, that is labelled with _debug=true_. The docker image _setlog/debug-k8s_ has been loaded earlier in it already.
206
224
225
+
```yaml
207
226
nodeSelector:
208
227
debug: "true"
228
+
```
209
229
210
230
* Service _service-debug_ has the type _NodePort_ and is mounted into the worker node. This port 30123 is equal to the parameter _--listen=:30123_ in the Dockerfile, which makes it possible to send debug commands to the delve server.
211
231
212
232
* Service _debug-k8s_ will be connected to the ingress server in the final step. It serves for exposing the API endpoints we are going to debug.
213
233
214
234
If you did all steps correctly, your pod should be up and running. Check it with `kubectl get pod`. You should see the output with the pod status _Running_ and two additional services _debug-k8s_ and _service-debug_:
215
235
216
-
```sh
236
+
```
217
237
NAME READY STATUS RESTARTS AGE
218
238
pod/debug-k8s-6d69b65cf-4fl6t 1/1 Running 0 1h
219
239
@@ -230,8 +250,9 @@ Usually it takes a couple of seconds to start the debugging process with delve.
230
250
Also, you can output logs of the pod by performing `kubectl logs $PODNAME` in order to make sure the delve API server is listening at 30123.
231
251
232
252
Output:
233
-
253
+
```
234
254
API server listening at: [::]:30123
255
+
```
235
256
236
257
_Hint: always wait until this log message is shown for this pod before you start the debugging process. Otherwise, the delve server is not up yet and cannot answer to the debugger._
237
258
@@ -269,11 +290,15 @@ After starting the debug process there is a new log created by the go service:
269
290
270
291
We are ready to debug, but we have to trigger the API functions through the ingress service. Deploy it with kubectl:
271
292
272
-
`kubectl create -f cluster/ingress.yaml`
293
+
```sh
294
+
kubectl create -f cluster/ingress.yaml
295
+
```
273
296
274
297
And try accessing it now:
275
298
276
-
`curl http://localhost:8090/hello`
299
+
```sh
300
+
curl http://localhost:8090/hello
301
+
```
277
302
278
303
Which should trigger the debugger:
279
304
@@ -285,4 +310,6 @@ Happy debugging!
285
310
286
311
If you don't need your kind cluster anymore, it can be removed with following command:
0 commit comments