Debug pods and nodes by attaching ephemeral containers.
low risk
kubectl debug creates ephemeral debug containers in running pods (K8s 1.23+), copies pods with different images, or attaches a shell to a node. The solution to debugging distroless/scratch images that have no shell or tools.
| Flag | Meaning |
|---|---|
-it | Interactive terminal |
--image | Debug container image |
--copy-to | Create a debug copy of the pod |
--target | Target container to share process namespace with |
kubectl debug -it mypod --image=busybox --target=mycontainerAdd busybox debug container sharing target's process namespace · explain & risk-check →kubectl debug node/mynode -it --image=ubuntuDebug a cluster node with ubuntu container · explain & risk-check →kubectl debug -it mypod --copy-to=mypod-debug --image=ubuntu -- bashCreate a debuggable copy of a pod · explain & risk-check →Use `kubectl debug` with `--image=nicolaka/netshoot` — the netshoot image has tcpdump, curl, dig, ss, and 50+ network tools pre-installed, perfect for K8s network debugging.
Reference text is hand-written and may be incomplete — check man kubectl for your version. Test destructive commands on a non-production system first.