kubectl logs <pod> --previous and kubectl describe pod <pod> to see why the container exits, then fix that: a crashing app, a wrong command, a missing config or secret, a failing liveness probe or too little memory.
What CrashLoopBackOff actually means
A pod in CrashLoopBackOff is not stuck. Kubernetes did its job: it pulled the image, started the container, and the process inside exited. Because the pod has restartPolicy: Always (the default for Deployments), the kubelet starts it again, and each time it waits longer before the next try. That wait is the "back-off".
So the question is never "why is Kubernetes doing this?" but "why does my container exit?" The answer is almost always in the container logs or in the pod events.
The most common causes
| Cause | What you see | Where to look |
|---|---|---|
| App error on start-up | Stack trace, "connection refused", "file not found" | kubectl logs <pod> --previous |
| Wrong command or args | Exit code 127 (command not found) or 126 | kubectl describe pod → Last State |
| Missing ConfigMap / Secret / env var | App says a setting is missing; or CreateContainerConfigError first | Pod spec and kubectl get cm,secret |
| Liveness probe fails | Events: "Liveness probe failed", container killed | kubectl describe pod → Events |
| Out of memory | Last State: OOMKilled, exit code 137 | kubectl describe pod |
| Process finishes and exits | Exit code 0, then restarted | The image runs a one-off script, not a server |
How to fix it, step by step
- See the status and restart count:
kubectl get pods(RESTARTS keeps going up). - Read the logs of the crashed run, not the current one:
kubectl logs <pod> --previous(add-c <container>if the pod has more than one container). - Check the exit code and reason:
kubectl describe pod <pod>and look at Last State (Error, OOMKilled, Completed) and the Events at the bottom. - Exit code 1 or a stack trace: fix the application error (bad config, database not reachable, missing file). Test the image locally with
docker runand the same environment variables. - Exit code 127 / 126: the command in
command:orargs:is wrong or not executable. Compare it with the image's ENTRYPOINT and CMD. - Exit code 137 with OOMKilled: raise
resources.limits.memoryor fix the memory leak. - Probe failures: give the app time to start with a
startupProbeor a largerinitialDelaySeconds, and check the probe path and port. - Exit code 0: the container finished its work. Use a Job for one-off tasks, or make the process run in the foreground.
- Apply the fix and watch it recover:
kubectl get pods -w.
Debug a container that crashes too fast
If the container dies before you can look inside, start a copy of the pod with a shell instead of the normal command:
kubectl debug <pod> -it --copy-to=debug-pod --container=<container> -- sh
# or override the command in a test pod
kubectl run test --rm -it --image=<your-image> --command -- sh Inside the shell, run the start command yourself and you will see the exact error.
How to prevent it
- Fail fast with clear log messages when a required setting is missing.
- Use a
startupProbefor slow apps so the liveness probe does not kill them while starting. - Set memory requests and limits from real usage (check
kubectl top pod). - Test images locally with the same env vars before deploying.
Questions
Is CrashLoopBackOff an error in Kubernetes itself?
No. Kubernetes is restarting a container that keeps exiting. The fault is inside the container: the app, its command, its config or its resources.
How long does Kubernetes wait between restarts?
The delay doubles each time: 10s, 20s, 40s and so on, up to 5 minutes. It resets after the container runs fine for 10 minutes.
Why does `kubectl logs` show nothing?
You are seeing the new container, which has just started. Use kubectl logs <pod> --previous to read the logs of the run that crashed.