Kubernetes crash loops: read the last state
CrashLoopBackOff tells you a container keeps dying, not why. The reason is in the pod's last state, and the cause is almost always in the rollout history. This lesson is the three-command triage and the mitigations that make things worse.
Three commands
$ kubectl -n search describe pod <pod> | sed -n '/Last State/,/Restart Count/p' Last State: Terminated Reason: OOMKilled Exit Code: 137 $ kubectl -n search logs <pod> --previous | tail -20 $ kubectl -n search rollout history deploy/indexer
describe gives the termination reason and exit code of the previous container. logs --previous shows what it printed before it died; for an OOM kill there is often nothing, which is itself a clue. rollout history tells you what changed, and the change cause annotation is why you should always set one.
Exit codes
- 137 = SIGKILL. With Reason OOMKilled it is the memory limit; without, something else killed it (liveness probe after a timeout, node pressure eviction).
- 143 = SIGTERM. The container was asked to stop and did; look at probes and preStop hooks.
- 1 or other small codes = the application exited on its own; the logs will say why.
- CreateContainerConfigError or ImagePullBackOff are not crash loops; they are config or registry problems.
Roll back first
If a rollout lines up with the page, kubectl rollout undo is the mitigation. It is reversible, fast, and does not require you to understand the bug. Understanding comes afterwards in the post-mortem. The exception is when the rollout was itself a fix for something worse, which is why you read the change cause before you undo.
Mitigations that backfire
- Raising the memory limit: hides the regression and may not schedule if the node is committed.
- Deleting pods: they come back with the same spec and you lose any that were still serving.
- Scaling out: more replicas of a broken pod is more OOM kills and more load on dependencies.
- Disabling the liveness probe: the pod stays Running while serving nothing.