Pod Debug with Ephemeral Containers
Intermediate10 minTrending
Debug running pods using ephemeral debug containers, especially useful for distroless images that lack debugging tools.
Prerequisites
- -kubectl configured
- -Kubernetes 1.25+ cluster
Steps
1
Attach an ephemeral debug container to a running pod
Add a temporary debug container with a full toolkit to an existing pod without restarting it.
$ kubectl debug -it <pod-name> --image=busybox --target=<container-name>
The --target flag shares the process namespace with the specified container so you can see its processes.
2
Debug with a copy of the pod
Create a copy of the pod with a debug container added, useful when you cannot modify the running pod.
$ kubectl debug <pod-name> -it --image=nicolaka/netshoot --copy-to=debug-pod --share-processes
3
Debug a node directly
Create a privileged pod on a specific node for host-level debugging.
$ kubectl debug node/<node-name> -it --image=ubuntu
This creates a privileged pod with host filesystem access at /host. Use with caution.
4
Inspect pod events and conditions
View events and conditions to understand why a pod is failing.
$ kubectl describe pod <pod-name> | tail -30
5
Clean up debug pods
Remove any debug pod copies you created.
$ kubectl delete pod debug-pod
Full Script
FAQ
Discussion
Loading comments...