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
Problem: No documentation on how to debug NGF in Kubernetes
Solution: Add a developer guide with step-by-step instructions
on how to inject an ephemeral dlv debug container into NGF while
it's running in a cluster. Includes makefile targets to make the
process easier and a dockerfile for the dlv debug image.
install-ngf-local-build: build-images load-images helm-install-local ## Install NGF from local build on configured kind cluster.
162
+
163
+
.PHONY: install-ngf-local-build-with-plus
164
+
install-ngf-local-build-with-plus: build-images-with-plus load-images-with-plus helm-install-local-with-plus ## Install NGF with NGINX Plus from local build on configured kind cluster.
165
+
166
+
.PHONY: helm-install-local
167
+
helm-install-local: ## Helm install NGF on configured kind cluster with local images. To build, load, and install with helm run make install-ngf-local-build.
helm-install-local-with-plus: ## Helm install NGF with NGINX Plus on configured kind cluster with local images. To build, load, and install with helm run make install-ngf-local-build-with-plus.
debug-build-images: debug-build build-ngf-image build-nginx-image debug-build-dlv-image ## Build all images used in debugging.
188
+
189
+
.PHONY: debug-build-images-with-plus
190
+
debug-build-images-with-plus: debug-build build-ngf-image build-nginx-plus-image debug-build-dlv-image ## Build all images with NGINX plus used in debugging.
191
+
192
+
.PHONY: debug-load-images
193
+
debug-load-images: load-images ## Load all images used in debugging to kind cluster.
194
+
kind load docker-image dlv-debug:edge
195
+
196
+
.PHONY: debug-load-images-with-plus
197
+
debug-load-images-with-plus: load-images-with-plus ## Load all images with NGINX Plus used in debugging to kind cluster.
198
+
kind load docker-image dlv-debug:edge
199
+
200
+
.PHONY: debug-install-local-build
201
+
debug-install-local-build: debug-build-images debug-load-images helm-install-local ## Install NGF from local build using debug NGF binary on configured kind cluster.
202
+
203
+
.PHONY: debug-install-local-build-with-plus
204
+
debug-install-local-build-with-plus: debug-build-images-with-plus debug-load-images-with-plus helm-install-local-with-plus ## Install NGF with NGINX Plus from local build using debug NGF binary on configured kind cluster.
157
205
158
206
.PHONY: dev-all
159
207
dev-all: deps fmt njs-fmt vet lint unit-test njs-unit-test ## Run all the development checks
This section will walk you through how to attach an ephemeral [dlv](https://github.com/go-delve/delve) debugger
6
+
container to NGF while it's running in Kubernetes. This will allow you to remotely debug NGF running in Kubernetes
7
+
using your IDE.
8
+
9
+
- Create a `kind` cluster:
10
+
11
+
```console
12
+
make create-kind-cluster
13
+
```
14
+
15
+
- Set GOARCH environment variable:
16
+
17
+
The [Makefile](/Makefile) uses the GOARCH variable to build the binary and container images. The default value of GOARCH is `amd64`.
18
+
19
+
If you are deploying NGINX Gateway Fabric on a kind cluster, and the architecture of your machine is not `amd64`, you will want to set the GOARCH variable to the architecture of your local machine. You can find the value of GOARCH by running `go env`. Export the GOARCH variable in your `~/.zshrc` or `~/.bashrc`.
20
+
21
+
```console
22
+
echo "export GOARCH=< Your architecture (e.g. arm64 or amd64) >" >> ~/.bashrc
23
+
source ~/.bashrc
24
+
```
25
+
26
+
or for zsh:
27
+
28
+
```console
29
+
echo "export GOARCH=< Your architecture (e.g. arm64 or amd64) >" >> ~/.zshrc
30
+
source ~/.zshrc
31
+
```
32
+
33
+
- Build debug images and install NGF on your kind cluster:
34
+
35
+
-**For NGINX OSS:**
36
+
37
+
```console
38
+
make GOARCH=$GOARCH debug-install-local-build
39
+
```
40
+
41
+
- **For NGINX Plus:**
42
+
43
+
```console
44
+
make GOARCH=$GOARCH debug-install-local-build-with-plus
45
+
```
46
+
47
+
> Note: The default value of GOARCH in the [Makefile](/Makefile) is `amd64`. If you try and debug an amd64 container on an ARM machine you will see the following error in the dlv container logs: `could not attach to pid <pid>: function not implemented`.
48
+
> This is a known issue and the only workaround is to create an arm64 image by specifying `GOARCH=arm64` the above commands.
49
+
> For more information, see this [issue](https://github.com/docker/for-mac/issues/5191)
50
+
51
+
- Start kubectl proxy in the background:
52
+
53
+
```console
54
+
kubectl proxy &
55
+
```
56
+
57
+
- Save the NGF Pod name:
58
+
59
+
```console
60
+
POD_NAME=<NGF Pod>
61
+
```
62
+
63
+
- Run the following curl command to create an ephemeral debug container:
@@ -50,12 +51,30 @@ Follow these steps to set up your development environment.
50
51
51
52
## Build the Binary and Images
52
53
54
+
### Setting GOARCH
55
+
56
+
The [Makefile](/Makefile) uses the GOARCH variable to build the binary and container images. The default value of GOARCH is `amd64`.
57
+
58
+
If you are deploying NGINX Gateway Fabric on a kind cluster, and the architecture of your machine is not `amd64`, you will want to set the GOARCH variable to the architecture of your local machine. You can find the value of GOARCH by running `go env`. Export the GOARCH variable in your `~/.zshrc` or `~/.bashrc`.
59
+
60
+
```shell
61
+
echo"export GOARCH=< Your architecture (e.g. arm64 or amd64) >">>~/.bashrc
62
+
source~/.bashrc
63
+
```
64
+
65
+
or for zsh:
66
+
67
+
```shell
68
+
echo"export GOARCH=< Your architecture (e.g. arm64 or amd64) >">>~/.zshrc
69
+
source~/.zshrc
70
+
```
71
+
53
72
### Build the Binary
54
73
55
74
To build the binary, run the make build command from the project's root directory:
56
75
57
76
```makefile
58
-
make build
77
+
make GOARCH=$GOARCH build
59
78
```
60
79
61
80
This command will build the binary and output it to the `/build/.out` directory.
@@ -65,7 +84,7 @@ This command will build the binary and output it to the `/build/.out` directory.
65
84
To build the NGINX Gateway Fabric and NGINX container images from source run the following make command:
66
85
67
86
```makefile
68
-
make TAG=$(whoami) build-images
87
+
make GOARCH=$GOARCH TAG=$(whoami) build-images
69
88
```
70
89
71
90
This will build the docker images `nginx-gateway-fabric:<your-user>` and `nginx-gateway-fabric/nginx:<your-user>`.
0 commit comments