kubectl exec
works when the container has a shell and the debugging tools you need. But many production images are minimal or distroless — they don't include sh
, curl
, or nslookup
.
kubectl debug
solves this by attaching an ephemeral container to a running Pod. The ephemeral container shares the Pod's network and process namespace, so you can inspect everything without modifying the original image.
# Attach a debug container to a running Pod
kubectl debug -it
--image=busybox --target=app
# Create a copy of the Pod with a debug container (doesn't affect the original)
kubectl debug --copy-to=debug-pod --image=ubuntu --share-processes
Use kubectl exec
when the container already has the tools you need. Use kubectl debug
when it doesn't, or when you don't want to risk disrupting a running container by installing packages inside it.