Skip to content

CrashLoopBackOff: why the pod keeps dying

Kubernetestested on RKE2 v1.37.2

CrashLoopBackOff is not an error but a wait: the container has exited, the kubelet restarts it – and waits longer after every crash. The cause is in the exit code and in the log of the last run.

Symptom

kubectl -n tag05 get pods -l app=web
NAME                   READY   STATUS             RESTARTS      AGE
web-7c8cd947d6-zstdf   0/1     CrashLoopBackOff   4 (55s ago)   2m26s

The wait grows 10 s, 20 s, 40 s, 80 s up to 5 minutes and only resets once the container has run without failing for ten minutes. That is why a fix sometimes doesn't take effect right away.

Diagnosis

Look at the log of the crashed run and at the exit code.

kubectl -n tag05 logs deploy/tippfehler
kubectl -n tag05 get pod -l app=tippfehler -o jsonpath=\
'{.items[0].status.containerStatuses[0].lastState.terminated.exitCode}{"\n"}'
starte
sh: slep: not found
127

Causes

Exit 127Command not found

A typo in the command or a program that doesn't exist in the image. The log says "not found".

Exit 1The application gives up

Missing configuration, variable or file. The log tells you why.

nginx: [emerg] open() "/etc/nginx/conf.d/app.conf" failed (2: No such file or directory)

Exit 137OOMKilled – memory limit exceeded

The kernel kills the container. describe shows the reason.

kubectl -n tag05 describe pod -l app=speicher \
  | sed -n '/Last State/,/Exit Code/p;/Limits/,/memory/p'
    Last State:     Terminated
      Reason:       OOMKilled
      Exit Code:    137
    Limits:
      memory:  64Mi

Fix

Fix the cause, then roll out again: correct the command, mount the missing file as a ConfigMap or raise the limit to what the app needs. A rollout creates a fresh pod – without the long wait.
kubectl -n tag05 rollout status deploy/tippfehler
kubectl -n tag05 logs deploy/tippfehler
starte

Don't: Just deleting the pod. The new pod crashes the same way – the cause is still there.

▶
Break it yourself and find it – free
Debugging Kubernetes, day 5: six crashes from a typo to readOnlyRootFilesystem, with a drill to reproduce each one.
Go to day 5 →

FAQ

Why does kubectl logs show nothing?

The current container has just restarted. kubectl logs --previous shows the crashed run.

What is the difference to "Error"?

"Error" is the moment of the crash, "CrashLoopBackOff" the wait until the next attempt.

Related error patterns

More