Sub topic 12
What CrashLoopBackOff Means
This chapter assumes you can use kubectl get and kubectl describe, read pod YAML, and know that a container is one process started from an image. It also assumes you know how container states appear in kubectl describe.
It is a Waiting reason, not a cause
CrashLoopBackOff is the reason shown on a container in the Waiting state. It does not name what went wrong. It says that the container started, stopped, and the kubelet is now pausing before it starts the container again.
The pod phase usually stays Running, because at least one container has started. The STATUS column in kubectl get pod shows the container's reason text instead of the phase.
The back-off delay
The restart policy decides whether the kubelet restarts a container that exited. The default for pods is Always. With Always, a container is restarted even after it exits with code 0. With OnFailure, only non-zero exits trigger a restart.
Between restarts, the kubelet waits. The wait starts at 10 seconds and doubles after each failure: 10s, 20s, 40s, and so on, up to a cap of 5 minutes. The delay resets after the container runs for 10 minutes without a problem. That is why a crashing pod looks busy at first and then restarts only every few minutes.
Common causes
The same status hides very different problems:
| Cause | Typical sign |
|---|---|
| Application error at startup | Stack trace or error message in logs |
| Missing config, env var, or Secret value | Log line naming the missing setting |
| Wrong `command` or `args` | Exit code 127 or 126 |
| Memory limit exceeded | Reason `OOMKilled`, exit code 137 |
| Liveness probe failing | Events show `Liveness probe failed` |
| Process exits on purpose | Exit code 0 under `restartPolicy: Always` |
The last row surprises people. A short script that finishes successfully still loops under a Deployment, because Deployments require Always. Use a Job for work that should end.
Confirming the loop
Check the restart count and the last termination:
kubectl get pod web
kubectl describe pod webIn the describe output, look at the container's Last State. It lists Terminated, with a reason, exit code, and start and finish times. A short gap between start and finish means the process fails quickly. A gap of about the probe timeout suggests a probe is killing it.
Next, find out why the container stopped. Read the logs from the previous instance, because the current instance may have just started and have nothing to show. The exit code then narrows the cause.
Exercise
A pod has restartPolicy: Always and its container runs a script that prints "done" and exits with code 0. What status do you expect after a few minutes, and why?
Show answer
The pod will show CrashLoopBackOff with a rising restart count. The container exits successfully, but Always makes the kubelet restart it anyway, and the back-off delay grows between restarts. A Job, which uses OnFailure or Never, fits work that should finish.