Pcornel
Containers · Container Troubleshooting

Debugging with kubectl exec and Ephemeral Containers

Cheat sheet · https://pcornel.dk/topic.php?topic=6160

Back to the Topic

Answer

kubectl exec runs a command in a running container; kubectl debug adds an ephemeral debug container (with tools) to a pod or creates a debug copy, even for distroless images.

Remember

Distroless images have no shell — use kubectl debug -it <pod> --image=busybox --target=<container>. Exec access is powerful — restrict with RBAC.

First checks

  • kubectl exec -it <pod> -c <c> -- sh — first check for this topic
  • kubectl get pods -o wide — pods, status, node, IP
  • kubectl describe pod <pod> — events and conditions
  • kubectl logs <pod> [-c <c>] [--previous] — container logs (incl. previous crash)
  • kubectl get events --sort-by=.lastTimestamp — recent cluster events

Commands

debug
kubectl exec -it <pod> -c <container> -- sh
kubectl debug -it <pod> --image=busybox:1.36 --target=<container>
kubectl debug <pod> -it --copy-to=<pod>-dbg --container=<c> -- sh
kubectl debug node/<node> -it --image=busybox:1.36
ss -ltn
nslookup
curl localhost:<port>
kubectl debug node/…
kubectl delete pod node-debugger-…
kubectl debug

Verify in this order

exec/debug → container shares the pod's namespaces → tools run

Where it usually breaks

Distroless images have no shell, so exec fails.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6160

Confirmation

Confirm action

Continue?