Struggling with a pod stuck in CrashLoopBackOff? This quick guide, originally published on devopsstart.com, shows you the exact commands to diagnose the root cause in seconds.
The Problem
Your pod is stuck in CrashLoopBackOff and you need to find out why — fast.
The Solution
kubectl logs <pod-name> --previous
The --previous flag shows logs from the last crashed container instance. This is the single most useful flag for debugging crash loops.
Combine with describe for the full picture
kubectl describe pod <pod-name> | grep -A 5 "Last State"
This shows the exit code and reason for the last termination:
Last State: Terminated
Reason: OOMKilled
Exit Code: 137
Common Exit Codes
| Code | Meaning | Fix |
|---|---|---|
| 1 | Application error | Check app logs |
| 137 | OOMKilled | Increase memory limits |
| 139 | Segfault | Check binary compatibility |
| 143 | SIGTERM | Graceful shutdown issue |
Why It Works
Kubernetes keeps logs from the previous container instance even after it crashes. Without --previous, you'd only see logs from the current (possibly empty) instance that hasn't had time to produce output before crashing again.
Top comments (0)