Debugging Running Pods on Kubernetes

Executing commands using kubectl exec

If you run software on Kubernetes, you will, at some point, want to debug some aspect of what you deploy. A simple approach to debugging that is natural to people used to working with VMs is to connect to a running pod and hack away:

kubectl exec -it podname -c containername -- bash

This often works and is very useful. However, there are at least two Kubernetes “best practices” limiting exec’s usefulness in the real world:

  • Not running as root. Containers run with as few privileges as possible and may even run with randomized UIDs.
  • Minimal images. Images are kept as small as possible, with binaries installed into a distroless image as an extreme.

Learn More