Skip to content

Commit d98b92b

Browse files
committed
Update wording and syntax of README.md
1 parent 14eedcb commit d98b92b

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

README.md

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,40 @@
1-
### Preface
1+
# Preface
22

3-
In this article you are going to learn, how to remotely debug a go service in kubernetes. If you are a developer with an unusual power, your services have no dependencies to other services or all those dependencies are mocked in unit tests, you don't need to debug anything in kubernetes. All other developers need to setup debugging and they want to do it in the kubernetes environment as well. Let us share our exciting and painful experience with you now.
3+
In this article we want to show you how it´s possible to remote debug a go service in a kubernetes cluster.
44

5-
### Prerequisites
5+
## Software Prerequisites
66

7-
1. Docker Desktop: https://docs.docker.com/get-docker/
7+
1. Docker Desktop: <https://docs.docker.com/get-docker/> (used version: 19.03.8)
8+
2. kind (Kubernetes in Docker): <https://kind.sigs.k8s.io.> (used version: v0.7.0) We decided to use kind instead of minikube, since it is a very good tool for testing kubernetes locally.
9+
3. Kubectl: <https://kubernetes.io/de/docs/tasks/tools/install-kubectl/> (used version: 1.17.2)
10+
4. Visual Studio Code: <https://code.visualstudio.com/download> (used version: 1.32.3)
811

9-
Our version: 19.03.8
10-
2. Kind (Kubernetes in Docker): https://kind.sigs.k8s.io. We decided to use kind instead of minikube, since it is a very good tool for testing kubernetes locally.
12+
## Big Picture
1113

12-
Our version: v0.7.0
13-
3. Kubectl: https://kubernetes.io/de/docs/tasks/tools/install-kubectl/
14+
First we will briefly explain how it works:
1415

15-
Our version: 1.17.2
16-
4. Visual Studio Code: https://code.visualstudio.com/download
16+
* you need a docker container with delve (<https://github.com/go-delve/delve>) as main process
17+
* delve needs access to the path with the project data. This is done by mounting `$GOPATH/src` on the pod which is running in the kubernetes cluster
18+
* we start the delve container on port 30123 and bind this port to localhost, so that only our local debugger can communicate with delve
19+
* to debug an API with delve, it´s necessary to set up an ingress network. For this we use port 8090.
1720

18-
Our version: 1.32.3
21+
A picture serves to illustrate the communication:
1922

20-
### Big Picture
21-
22-
First, we are going to briefly explain, how it works:
23-
* you need a docker container with delve started as a main process in it
24-
* delve (Go debugger) must have an access to the folder with project files. That is done by mounting $GOPATH/src into the pod running in the kubernetes environment
25-
* we start the delve server on the port 30123 and mount this port to the localhost, so that debugger can communicate with the server through it
26-
* in order to trigger API functions we want to debug it is necessary to establish an ingress network. We use the port 8090 for that
27-
28-
All-in-all it will look like this picture demonstrates:
29-
3023
![Overview](images/big-picture.png "Big Picture")
3124

32-
### Creating the Kubernetes cluster
33-
34-
#### Start the cluster
25+
### Creating a Kubernetes cluster
3526

36-
Before starting we need to adjust the cluster config file to your environment. Unfortunately, `kind` does not use the environment variables and we have to inject them into the config file with `sed`:
27+
`kind` unfortunately doesn´t use the environment variable `GOPATH`, so we have to update this in [cluster/config.yaml#L21](config.yaml):
3728

29+
```sh
3830
`sed -i.bak 's|'{GOPATH}'|'${GOPATH}'|g' cluster/config.yaml`
31+
```
32+
33+
<!-- To be checked! -->
3934

40-
You can also open `cluster/config.yaml` and replace {GOPATH} with the absolute path manually:
35+
36+
37+
You can also open [cluster/config.yaml#L21](config.yaml) and replace `{GOPATH}` with the absolute path manually:
4138

4239
extraMounts:
4340
- hostPath: {GOPATH}/src
@@ -48,7 +45,8 @@ Assuming you already have installed kind (Kubernetes in Docker) on your local ma
4845

4946
The cluster has the name `local-debug-k8s` and is created with the custom configuration (parameter `--config cluster/config.yaml`). Let us take a look at `cluster/config.yaml` and explain it:
5047

51-
```kind: Cluster
48+
```yml
49+
kind: Cluster
5250
apiVersion: kind.x-k8s.io/v1alpha4
5351
nodes:
5452
- role: control-plane
@@ -97,7 +95,7 @@ Activate the kube-context, so that _kubectl_ can communicate with the newly crea
9795

9896
#### Install nginx-ingress
9997

100-
Source: https://kind.sigs.k8s.io/docs/user/ingress/#ingress-nginx
98+
Source: <https://kind.sigs.k8s.io/docs/user/ingress/#ingress-nginx>
10199

102100
In order to make both port mounts working (8090 and 30123), it is necessary to deploy the nginx controller as well.
103101
Run the following command for it:
@@ -120,7 +118,7 @@ So, we label a worker node with _debug=true_:
120118

121119
Our service has only one `/hello` endpoint and writes just a few logs. The interesting part is in the Dockerfile:
122120

123-
```
121+
```Dockerfile
124122
FROM golang:1.13-alpine
125123
126124
ENV CGO_ENABLED=0 # compile gcc statically
@@ -212,7 +210,7 @@ Let's go through the deployment.
212210

213211
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_:
214212

215-
```
213+
```sh
216214
NAME READY STATUS RESTARTS AGE
217215
pod/debug-k8s-6d69b65cf-4fl6t 1/1 Running 0 1h
218216

0 commit comments

Comments
 (0)