|
| 1 | +# Introduction |
| 2 | +The `kubectl` command of Kubernetes offers a `debug` sub-command to investigate pods running (or crashing) on a node using ephemeral debug containers. |
| 3 | +The `nginx-utils` image can be spun into a debug container that includes various tools such as curl, tcpdump, iperf, netcat to name a few. |
| 4 | + |
| 5 | +Benefits: |
| 6 | +* Minimal image |
| 7 | +* Scanned for vulnerabilities |
| 8 | +* Includes well-known troubleshooting tools |
| 9 | +* Ability to include custom tools |
| 10 | + |
| 11 | +# Usage |
| 12 | +#### The command to start the debug container using the nginx-utils image version `ghcr.io/nginx/nginx-utils:latest`: |
| 13 | +``` |
| 14 | +kubectl -n <namespace> debug -it <nic-pod-name> --image=ghcr.io/nginx/nginx-utils:latest --target=nginx-ingress |
| 15 | +``` |
| 16 | + |
| 17 | +Please refer to the [nginx-utils packages page](https://github.com/nginx/nginx-supportpkg-for-k8s/pkgs/container/nginx-utils) for versions. |
| 18 | + |
| 19 | +-------------- |
| 20 | +#### Example usage of `api_stats.sh` found in the container: |
| 21 | +The `api_stats.sh` script is designed to facilitate accessing the [/api](https://nginx.org/en/docs/http/ngx_http_api_module.html#api) endpoint to query various status information, configuring upstream server groups on-the-fly, and managing key-value pairs without the need of reconfiguring nginx. |
| 22 | + |
| 23 | +> **NOTE:** The `api_stats.sh` script requires an `/api` endpoint that is listening on `loopback`, in a given `port`. |
| 24 | +``` |
| 25 | +kubectl -n <namespace> debug -it <nic-pod-name> --image=ghcr.io/nginx/nginx-utils:latest --target=nginx-ingress |
| 26 | +
|
| 27 | +v4nic-0-nginx-ingress-controller-854796ff97-hhkk5:~# ls |
| 28 | +api_stats.sh memory_stats.sh |
| 29 | +
|
| 30 | +v4nic-0-nginx-ingress-controller-854796ff97-hhkk5:~# ./api_stats.sh -h |
| 31 | +
|
| 32 | +Usage: ./api_stats.sh [-p port] |
| 33 | +
|
| 34 | +v4nic-0-nginx-ingress-controller-854796ff97-hhkk5:~# ./api_stats.sh -p 8080 |
| 35 | +API_VERSION: 9 |
| 36 | +**** /api/9/nginx **** |
| 37 | +{ |
| 38 | + "version": "1.27.2", |
| 39 | + "build": "nginx-plus-r33-p2", |
| 40 | + "address": "127.0.0.1", |
| 41 | + "generation": 8, |
| 42 | +.... |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +# Building |
| 47 | +Please go to the root directory of this project, `nginx-supportpkg-for-k8s` and run the command: |
| 48 | +``` |
| 49 | +make nginx-utils |
| 50 | +``` |
0 commit comments