Sub topic 3
Choosing a debug image
This chapter assumes you know pods, containers and namespaces, and that you have used kubectl exec. It also assumes you can run kubectl debug against a cluster on version 1.25 or later. The earlier chapters covered why exec fails on minimal images and what ephemeral containers are. Here you decide which image to put in the ephemeral container.
Why the image matters
An ephemeral container is a normal container with its own image. It does not borrow tools from the application container. Whatever you need during the session, such as a shell, ps, dig or tcpdump, must be in the image you pass to --image.
The wrong choice costs time in two ways:
- The image lacks the tool you need, so you restart the session with a different image.
- The image is large or unreachable, so the container sits in a pull state while the incident continues.
You cannot remove an ephemeral container once it is added, and you cannot change its image. Switching images means adding another container to the pod.
Common choices
| Image | Approximate size | Good for | Missing |
|---|---|---|---|
| `busybox` | A few MB | A shell, `ps`, `ls`, `cat`, `wget`, `nslookup`, `nc`, `vi` | `curl`, `tcpdump`, `dig`, `strace` |
| `alpine` | About 8 MB | A shell plus `apk add` for extra packages | Tools until you install them, which needs network access |
| `nicolaka/netshoot` | Hundreds of MB | Network work: `curl`, `dig`, `tcpdump`, `ss`, `iperf3`, `strace` | It is large, and it runs as a broad toolbox, not a minimal one |
| The application's own image | Varies | Matching library versions and runtime tools | It may be distroless, which is the problem you started with |
Start with busybox for filesystem and process questions. Use netshoot when the problem is DNS, connectivity or TLS. Use alpine when you need one specific tool and the pod can reach a package mirror.
Using an image
The image is passed with --image. Pin a tag so the session behaves the same each time.
kubectl debug -it web-7d4b9c-abcde --image=busybox:1.36 --target=appFor network problems, swap the image and add a profile that grants the needed capabilities:
kubectl debug -it web-7d4b9c-abcde --image=nicolaka/netshoot --target=app --profile=netadminCapture tools such as tcpdump need NET_ADMIN and NET_RAW, which the netadmin profile adds. Tools such as strace need other capabilities, such as SYS_PTRACE. An image having a tool does not mean the container is allowed to use it. Profiles are covered in a later chapter.
Checking what the image provides
Before you rely on a tool, check that it exists. Inside the session:
which curl tcpdump dig nslookupA missing tool prints nothing for that name. With busybox, wget -qO- http://localhost:8080/healthz often replaces curl for a quick HTTP check.
Things that break image choice
- Architecture mismatch. The image must support the node's CPU architecture. An
amd64-only image on anarm64node fails to start. - Private or air-gapped registries. The node pulls the image. If your cluster cannot reach Docker Hub, mirror the debug images into your own registry and pass the full path. If the registry needs credentials, the pod's
imagePullSecretsapply, so a pod without them cannot pull from a private registry. - The
latesttag. It can change between sessions and may trigger a pull every time. Pin versions. - Policy controllers. Admission policies that allow only approved registries also apply to ephemeral containers. A rejected image shows up as an error from
kubectl debug.
A decision path
Check your understanding
Exercise
A pod cannot resolve a service name. You attach a busybox:1.36 ephemeral container, but you want dig to inspect the DNS answers, and it is not there. What are two ways to continue, and what constraint applies to the way you add the new container?
Show answer
Add a second ephemeral container using an image that includes dig, such as nicolaka/netshoot. You can also use alpine and run apk add bind-tools, if the pod can reach a package mirror. Either way, you cannot change or remove the first ephemeral container. You add a new one under a new name, and the busybox container stays in the pod spec until the pod is replaced.
Exercise
kubectl debug with --image=nicolaka/netshoot is accepted, but the container stays in a waiting state and never starts. Name two causes related to image choice and how you would check them.
Show answer
The node may not be able to pull the image, because of an unreachable registry or missing credentials. The image may also not support the node's architecture. Run kubectl describe pod and read the ephemeral container's state and the pod events for pull errors. Then check the node's architecture with kubectl get node -o wide. Fix it by mirroring the image to a reachable registry or choosing a multi-architecture image.