Debug Kubernetes Resources: troubleshooting commands
21 commands in 4 groups: Crash Forensics, Live Resource Usage, Container Limits, Eviction and Pressure. Click or tap any command to copy it. Official documentation: kubernetes.io.
Open in the interactive cheat sheet search, stars and every other section
Crash Forensics
Read the last terminated state of a container to learn why it died, plus inspect previous logs.
kubectl get pod <name> -o jsonpath='{.status.containerStatuses[*].lastState.terminated.exitCode}'
Exit code from last termination
kubectl get pod <name> -o jsonpath='{.status.containerStatuses[*].lastState.terminated.reason}'
Termination reason (OOMKilled, Error, Completed)
kubectl get pod <name> -o jsonpath='{.status.containerStatuses[*].restartCount}'
Restart count per container
kubectl get pods --field-selector=status.phase=Failed
Find all Failed pods
kubectl get pods -A --sort-by='.status.containerStatuses[0].restartCount'
Pods sorted by restart count to spot flappers
kubectl logs <pod> --previous
Logs from a crashed/previous container
kubectl logs <pod> -p -c <container>
Previous logs for a specific container in a multi-container pod
Live Resource Usage
Real-time CPU and memory usage per pod, container and process. Requires metrics-server for kubectl top.
kubectl describe quota -n <namespace>
Current ResourceQuota usage vs hard limits in a namespace
kubectl exec -it <pod> -- top
Live CPU and memory usage by process inside the container
kubectl top pod <name> --containers
Per-container CPU/memory breakdown within a pod
kubectl top pod -A --sort-by=cpu
CPU-heavy pods across all namespaces
kubectl top pod -A --sort-by=memory
Memory-heavy pods across all namespaces
Container Limits
Verify the actual cgroup limits set on a container vs what the spec declared.
kubectl exec -it <pod> -- cat /proc/meminfo
Node-wide memory stats (meminfo ignores the container cgroup limit)
kubectl exec -it <pod> -- cat /sys/fs/cgroup/cpu.max
CPU quota and period on cgroup v2
kubectl exec -it <pod> -- cat /sys/fs/cgroup/memory.current
Current memory usage on cgroup v2
kubectl exec -it <pod> -- cat /sys/fs/cgroup/memory.max
Memory limit on cgroup v2
kubectl get pod <name> -o jsonpath='{.spec.containers[*].resources}'
Declared requests and limits from the pod spec
Eviction and Pressure
Find evicted pods and node pressure conditions that caused them.
kubectl get events --field-selector=reason=FailedCreatePodSandBox
Pod sandbox creation failures
kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.conditions[?(@.type=="MemoryPressure")].status}{"\n"}{end}'
MemoryPressure condition per node
kubectl get events --field-selector=reason=Evicted -A
All eviction events cluster-wide
kubectl get pods -A --field-selector=status.phase=Failed -o wide | grep Evicted
List evicted pods across the cluster