kubectl Debugging#
When something breaks in Kubernetes, you need to move through a specific sequence of commands. Here is every debugging command you will reach for, plus a step-by-step workflow for a pod that will not start.
Logs#
kubectl logs <pod-name> -n <namespace> # basic
kubectl logs <pod-name> -c <container-name> -n <namespace> # specific container
kubectl logs <pod-name> --previous -n <namespace> # previous crash (essential for CrashLoopBackOff)
kubectl logs -f <pod-name> -n <namespace> # stream in real-time
kubectl logs --since=5m <pod-name> -n <namespace> # last 5 minutes
kubectl logs -l app=payments-api -n payments-prod --all-containers # all pods matching labelThe --previous flag is critical for crash-looping pods where the current container has no logs yet. The --all-containers flag captures init containers and sidecars.