Skip to content
FR
  1. LuzineDebug
  2. Docker & DevOps
  3. Back-off restarting failed container app in pod…
Docker & DevOps Intermediate ≈ 20 min to fix

Fix "CrashLoopBackOff" / "Back-off restarting failed container" (Kubernetes)

Error message
Back-off restarting failed container app in pod api-7d9f8b6c5d-x2kqp_default(3c1d6f0e-9a2b-4e57-8f1a-6b2d0c9e4a11)
  • api-7d9f8b6c5d-x2kqp 0/1 CrashLoopBackOff 6 (2m ago) 9m
  • back-off 5m0s restarting failed container=app pod=api-7d9f8b6c5d-x2kqp_default(3c1d6f0e-9a2b-4e57-8f1a-6b2d0c9e4a11)
  • Warning BackOff 3m (x28 over 9m) kubelet Back-off restarting failed container app in pod api-7d9f8b6c5d-x2kqp_default(3c1d6f0e-9a2b-4e57-8f1a-6b2d0c9e4a11)
  • Init:CrashLoopBackOff
In short

CrashLoopBackOff means the container starts then stops in a loop, and Kubernetes waits longer and longer before restarting it. The cause shows in the logs of the previous instance (kubectl logs <pod> --previous) and in the exit code shown by kubectl describe pod: missing variable, invalid command, overly strict probe or not enough memory.

Be the first to confirm this fix

What this error means

CrashLoopBackOff is not an error in itself, it is a state. The container starts, then ends (crash or normal end of the process). With restartPolicy: Always, the one used by Deployments, the kubelet restarts it, doubling the delay after each failure: 10 s, 20 s, 40 s, up to 5 minutes at most. The delay resets once the container runs for 10 minutes without trouble. The "Back-off restarting failed container" message is the event emitted during that wait. The real cause is always elsewhere: in the logs of the previous attempt, the exit code, or the pod events.

Common causes

  1. The application crashes on startup: missing environment variable or secret, missing config file, unreachable database, failing migration (code 1).
  2. Invalid entry command: wrong command/args, binary not found (code 127), not executable (code 126), wrong architecture (exec format error), or a process that ends immediately (code 0).
  3. Overly strict liveness probe: wrong port or path, or an application slow to start; the kubelet kills it before it is ready.
  4. Not enough memory: the resources.limits.memory limit is exceeded, the container is killed with Reason: OOMKilled and code 137.
  5. Permissions or file system: runAsNonRoot, readOnlyRootFilesystem or a mounted volume prevent the application from writing where it needs to.

Step-by-step fix

  1. Read the state, exit code and events

    In kubectl describe pod, look at Last State: Terminated, then Reason and Exit Code, and the Events section at the bottom. Events sorted by date also show probe failures.

    bash
    kubectl get pods -n default
    kubectl describe pod api-7d9f8b6c5d-x2kqp -n default
    kubectl get events -n default --sort-by=.lastTimestamp
  2. Read the logs of the previous attempt

    kubectl logs without options shows the container that just restarted, often empty. --previous shows the one that crashed. Add -c if the pod has several containers, or the init container name for Init:CrashLoopBackOff.

    bash
    kubectl logs api-7d9f8b6c5d-x2kqp --previous
    kubectl logs api-7d9f8b6c5d-x2kqp -c app --previous --tail=100
  3. Interpret the exit code

    1: application error, the answer is in the logs. 126: file not executable. 127: command not found in the image. 137: SIGKILL, OOMKilled or killed after a failed liveness probe. 143: SIGTERM. 0: the process ended normally, but a Deployment expects a process that stays in the foreground.

  4. Check the injected configuration

    List the Deployment variables and check that the referenced Secrets and ConfigMaps exist with the right keys. kubectl describe secret shows keys and their size, without revealing the values.

    bash
    kubectl set env deployment/api --list
    kubectl describe secret app-secrets
    kubectl describe configmap app-config
  5. Give startup some time with a startupProbe

    If the events show Liveness probe failed, check the port and path, then add a startupProbe: liveness only starts once the application is up. Here, the application has up to 150 seconds (30 × 5 s) to start.

    yaml
    startupProbe:
      httpGet:
        path: /healthz
        port: 8080
      periodSeconds: 5
      failureThreshold: 30
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
      periodSeconds: 10
      failureThreshold: 3
  6. Debug inside a copy of the pod

    kubectl debug creates a copy of the pod where the app container command is replaced by a shell: you can inspect files and start the application by hand. Delete the copy afterwards. You can also test the image locally with docker run --rm -it --entrypoint sh myapp:1.4.2.

    bash
    kubectl debug api-7d9f8b6c5d-x2kqp -it --copy-to=api-debug --container=app -- sh
    kubectl delete pod api-debug
  7. Roll back if a deployment broke it

    If the problem appeared with the latest version, go back to the previous one while you fix it, then watch the rollout.

    bash
    kubectl rollout undo deployment/api
    kubectl rollout status deployment/api

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • Have the application validate its configuration on startup, with an explicit message ("DATABASE_URL is missing") rather than an obscure stack trace.
  • Test the image locally with the same variables and command as in the manifest before deploying.
  • Separate the probes: startupProbe for startup, readinessProbe for traffic (it does not restart the container), livenessProbe only to detect a real hang.

Frequently asked questions

How do I see the logs of a pod in CrashLoopBackOff?

With kubectl logs <pod> --previous, which shows the output of the container that just crashed. Without --previous, you see the new attempt, often still empty.

Does deleting the pod fix the problem?

No: the Deployment recreates a pod with the same spec, which will crash the same way. Fix the cause (config, image, probes, resources), then redeploy.

What is the difference between CrashLoopBackOff and ImagePullBackOff?

ImagePullBackOff: Kubernetes cannot download the image (name, tag, private registry). CrashLoopBackOff: the image is there, the container starts, then stops.

Useful tools for this error

More Docker & DevOps errors

All Docker & DevOps errors →