CrashLoopBackOff is the most searched pod status there is, and the name explains almost nothing. It is not an error. It is Kubernetes telling you that a container keeps stopping and that it is now waiting before it tries again. The actual error is somewhere else, and where exactly depends on how the container died.

To show where, we broke five pods on purpose, each in a different way, on a single-node Kubernetes 1.33 cluster running Docker as the container runtime. Every block of output below is copied from that run, trimmed only for width. Two of the five are worth reading even if you have debugged crash loops before: in one the logs look like a clean shutdown, and in the other a pod that is crash looping shows Running and 1/1 between its first restarts.

What the status actually means

A pod's containers run under a restartPolicy, and the default is Always. When a container exits, for any reason and with any exit code, the kubelet starts it again. If it keeps exiting, the kubelet waits longer each time: 10 seconds, then 20, then 40, doubling up to a cap of five minutes. If a container then runs for ten minutes without problems, the delay resets. CrashLoopBackOff is the name of that waiting period.

Here is how that looked for one of our pods, api-missing-env: the restart count, when each attempt started, and the gap since the previous one.

restart attempt started (UTC) gap since previous 2 11:11:04 - 3 11:11:31 27 s 4 11:12:12 41 s 5 11:13:45 93 s 6 11:16:28 163 s 7 11:21:31 303 s 

Two practical consequences follow. First, when you look at a crash looping pod you are usually looking at a container that is not running at all: it is Waiting, and the evidence is in the record of the previous attempt. Second, after a few minutes each restart is five minutes apart, so "watch it and see what happens" stops being a debugging method quite fast.

Here is the list right after the five pods went in:

$ kubectl get pods -n crashloop-lab NAME READY STATUS RESTARTS AGE api-missing-env 0/1 CrashLoopBackOff 2 (19s ago) 36s bad-entrypoint 0/1 CrashLoopBackOff 2 (21s ago) 36s job-as-deployment 0/1 CrashLoopBackOff 2 (18s ago) 36s web-bad-probe 1/1 Running 2 (5s ago) 36s worker-oom 0/1 OOMKilled 2 (28s ago) 36s 

Five different problems, and the STATUS column gives you three words for them, one of which is Running. The column you can trust is RESTARTS.

The three places to look, in this order

1. kubectl describe pod, the Last State block. This is the single most useful thing to read, and it is easy to scroll past. Under each container, State is what is happening now (usually Waiting with reason CrashLoopBackOff, which tells you nothing new), and Last State is how the previous attempt ended: a reason, an exit code, and start and finish times.

$ kubectl describe pod <pod> -n <namespace> State: Waiting Reason: CrashLoopBackOff Last State: Terminated Reason: Error Exit Code: 1 

2. The logs of the previous attempt. kubectl logs <pod> --previous prints the output of the container instance before the current one. It goes back one instance only, not through the whole history. For a pod with several containers add -c <container>.

3. Events. kubectl get events -n <namespace> --field-selector involvedObject.name=<pod> or the Events section at the bottom of describe. Events are where the kubelet writes down what it did to your container and why, which matters when the container itself had no chance to say anything.

The Last State reason and exit code tell you which of the other two to trust:

Last State reason Exit code What happened Where the cause is
Error 1 (or any app code) the process exited by itself logs --previous
OOMKilled 137 the kernel killed it at the memory limit describe: the limits, not the logs
Completed 0 the process finished, or was told to stop events (probes), then the pod spec
ContainerCannotRun 127 the process never started the Message line in describe

The exact reason names and codes for the last row depend on the container runtime. The rule does not: if the logs are empty, the container never got as far as writing any.

Case 1: the application exits on its own

The common one. The process starts, finds something wrong with its configuration and exits with an error.

$ kubectl describe pod api-missing-env -n crashloop-lab Last State: Terminated Reason: Error Exit Code: 1 $ kubectl logs api-missing-env -n crashloop-lab --previous starting api on :8080 FATAL: DATABASE_URL is not set 

Cause: a missing environment variable, here on purpose. In real life it is a Secret that was not created in this namespace, a ConfigMap key renamed in one place, a database the app cannot reach at startup, or a migration that has not run yet.

Check: --previous is the reliable command. Plain kubectl logs happens to show the same thing while the container is waiting, but the moment the next attempt starts it switches to the new instance, which has usually printed nothing yet. Then compare what the app asked for with what the pod got: kubectl get pod <pod> -o yaml and look at env and envFrom.

Fix: supply the value. And keep the behaviour: an app that exits loudly on missing configuration is doing you a favour compared with one that starts and fails on the first request.

Case 2: OOMKilled, where the logs just stop

$ kubectl describe pod worker-oom -n crashloop-lab Last State: Terminated Reason: OOMKilled Exit Code: 137 $ kubectl logs worker-oom -n crashloop-lab --previous loading cache 

That is the whole log. No error, no stack trace, nothing about memory. The process asked for more memory than the container limit allows, and the kernel killed it with SIGKILL, which cannot be caught or logged. Exit code 137 is 128 plus 9, the signal number of SIGKILL. Note also that the STATUS column in kubectl get pods showed OOMKilled instead of CrashLoopBackOff at that moment: it alternates between the two as the restarts go on.

Cause: the container's memory limit (64 MiB here) is lower than what the process needs (it tried to allocate 200 MiB). In real workloads: a JVM or Node.js heap sized for the machine rather than the container, a cache that grows with traffic, a batch that loads a whole file into memory.

Check: the Last State reason, and the limits in the same describe output. If metrics-server is installed, kubectl top pod shows how close the running containers get to their limits.

Fix: raise the limit or lower the usage. Do not read the absence of an error in the logs as evidence that memory is fine. With an OOM kill, silence is the evidence.

Case 3: the liveness probe, where the logs look like a clean shutdown

This one is the trap. For its first few restarts the pod shows Running and 1/1, and only the restart counter keeps growing. Later it settles into CrashLoopBackOff like the others.

$ kubectl describe pod web-bad-probe -n crashloop-lab State: Running Last State: Terminated Reason: Completed Exit Code: 0 Restart Count: 2 $ kubectl logs web-bad-probe -n crashloop-lab --previous [notice] 1#1: signal 17 (SIGCHLD) received from 30 [notice] 1#1: worker process 30 exited with code 0 [notice] 1#1: exit 

Exit code 0, reason Completed, and a log that ends in a tidy exit. Everything here says the server stopped normally. The cause is only in the events:

$ kubectl get events -n crashloop-lab --field-selector involvedObject.name=web-bad-probe Warning Unhealthy Liveness probe failed: HTTP probe failed with statuscode: 404 Normal Killing Container web failed liveness probe, will be restarted 

Cause: the liveness probe calls /healthz, and the server has no such path. After three failed checks the kubelet sends the container SIGTERM. nginx handles SIGTERM gracefully, finishes and exits with 0, so the record says Completed. Any well-behaved server does the same, which is why this case misleads people who read only exit codes.

Check: the events, every time the logs look clean but the restart counter grows. Then kubectl get pod <pod> -o yaml and compare the probe path and port with what the app really serves.

Fix: point the probe at a real endpoint. If the app is slow to start, add a startupProbe rather than a long initialDelaySeconds. And keep liveness checks local: a liveness probe that checks the database will restart every replica at once when the database has a bad minute.

Case 4: exit code 0, and it still crash loops

$ kubectl describe pod job-as-deployment -n crashloop-lab State: Waiting Reason: CrashLoopBackOff Last State: Terminated Reason: Completed Exit Code: 0 $ kubectl logs job-as-deployment -n crashloop-lab --previous migrations applied: 0 pending 

The logs show success, and the process really did succeed. That is the problem.

Cause: a one-shot task (a migration, a seed, a backup) runs in a pod with restartPolicy: Always, which is the default for a bare pod and the only value a Deployment allows. Always means restart after any exit, including a successful one. The task finishes, Kubernetes starts it again, it finishes again, and after a few rounds it is in backoff.

Check: exit code 0 together with a rising restart count, and no liveness probe events (otherwise it is case 3). Then look at what owns the pod: kubectl get pod <pod> -o jsonpath='{.metadata.ownerReferences[0].kind}'.

Fix: run it as a Job, with restartPolicy: OnFailure or Never. For a migration that must finish before the app starts, an init container in the app's own pod is the other common answer.

Case 5: the container never starts, and there are no logs at all

$ kubectl logs bad-entrypoint -n crashloop-lab --previous $ 

Empty, with or without --previous. Nothing to read because nothing ever ran.

$ kubectl describe pod bad-entrypoint -n crashloop-lab Last State: Terminated Reason: ContainerCannotRun Message: ... exec: "/app/server": stat /app/server: no such file or directory Exit Code: 127 

Cause: the command in the pod spec (or the image's entrypoint) points at a file that does not exist in the image. Typical sources: a multi-stage build that copied the binary to a different path, a command: override written for an older image, a shell script without a shell in a distroless image. A binary built for the wrong CPU architecture fails in the same place, with exec format error instead of no such file or directory.

Check: the Message line in describe, which is where the runtime's own error ends up, and the Failed event, which carries the same text. To see what is really in the image, run it locally with the entrypoint overridden, for example docker run --rm --entrypoint ls <image> -l /app.

Fix: correct the path or the build. As said above, the reason name (ContainerCannotRun here) and the exit code differ between runtimes; the message text is the part to read.

The order that saves time

  1. kubectl get pods: trust RESTARTS, not STATUS.
  2. kubectl describe pod: read Last State, reason and exit code.
  3. Exit code 137 or OOMKilled: go to limits, the logs will not help.
  4. Exit code 0 with restarts: events first (liveness probe), then the owner and restartPolicy.
  5. Empty logs: the Message line and the Failed event.
  6. Anything else: kubectl logs --previous.

One more thing, because it gets asked a lot: deleting the pod or running kubectl rollout restart does not fix a crash loop. The new pod gets a fresh backoff timer and crashes exactly as before. It is still useful once you have fixed the cause, so that you do not wait five minutes for the next scheduled attempt.

FAQ

Is CrashLoopBackOff an error?
No. It is the waiting period between restarts of a container that keeps exiting. The error is in the previous attempt: its exit code and reason in kubectl describe pod, its output in kubectl logs --previous, and the kubelet's actions in the pod's events.

How long does Kubernetes wait between restarts?
10 seconds after the first crash, then 20, 40 and so on, doubling up to a cap of 5 minutes. After ten minutes of running without problems the delay resets. In our run the measured gaps followed the same pattern, see the timeline above.

How do I see the logs of a crashed container?
kubectl logs <pod> --previous, plus -c <container> if the pod has more than one. It shows the instance before the current one, not older ones. If you need older history, it has to come from a log collector outside the node.

Why is the exit code 137?
The process was killed with SIGKILL (128 + 9). In a crash loop that almost always means the memory limit, and describe will show OOMKilled as the reason.

Why does a container with exit code 0 crash loop?
Either the process is a one-shot task in a pod that restarts on any exit (use a Job), or it was stopped by a failing liveness probe and shut down gracefully. The pod's events tell the two apart.

Does restarting the pod help?
Only after you fix the cause. A new pod starts with a fresh backoff timer and then fails the same way.

The same check without typing it

All of the above works in a terminal, and for scripts and CI it should stay there. When you are looking at a whole cluster to find the one pod that is restarting, a UI saves the typing. We build one, ROZOOM, a desktop Kubernetes IDE, so take this paragraph with that in mind. In its Pods list the Restarts column is colour-coded, and Logs in a pod's row menu opens a panel with a Previous switch that does what --previous does, greyed out when the container has no earlier instance, plus a container picker for multi-container pods. If you are still choosing a UI, the Kubernetes GUI comparison measures the alternatives the same way, and Docker in production covers the layer below.

Originally published at news.rozoom.app.