Debugging with kubectl exec and Ephemeral Containers
Cheat sheet · https://pcornel.dk/topic.php?topic=6160
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 topickubectl get pods -o wide— pods, status, node, IPkubectl describe pod <pod>— events and conditionskubectl logs <pod> [-c <c>] [--previous]— container logs (incl. previous crash)kubectl get events --sort-by=.lastTimestamp— recent cluster events
Commands
debugkubectl exec -it <pod> -c <container> -- shkubectl debug -it <pod> --image=busybox:1.36 --target=<container>kubectl debug <pod> -it --copy-to=<pod>-dbg --container=<c> -- shkubectl debug node/<node> -it --image=busybox:1.36ss -ltnnslookupcurl 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