Docker & Kubernetes

Kubernetes Pod Stuck in CrashLoopBackOff: Step-by-Step Troubleshooting

A repeatable way to find why a Kubernetes container keeps crashing, using events, previous logs and exit codes, plus fixes for the most common causes.

Quick answer: CrashLoopBackOff means the container starts, exits, and Kubernetes keeps restarting it with growing delays. Find out why it exits: run 'kubectl describe pod' and read Last State, Exit Code and Events, then 'kubectl logs POD --previous' for the crashed container's output. Exit code 137 with reason OOMKilled means raise the memory limit; exit code 1 is an application error; a failing liveness probe kills slow-starting apps, so add a startupProbe.

You deploy an application and the pod never becomes ready:

$ kubectl get pods
NAME                      READY   STATUS             RESTARTS      AGE
orders-6d9f7c8b5d-x2k8p   0/1     CrashLoopBackOff   6 (2m ago)    9m

CrashLoopBackOff isn't the problem itself; it's Kubernetes telling you the container keeps exiting. The job is to find why it exits.

What the error means

The container starts, its main process ends (crash, error or kill), and the kubelet restarts it. Each restart waits longer: 10s, 20s, 40s and so on, up to 5 minutes. While it waits, the status shows CrashLoopBackOff.

How to diagnose it

1. Read the pod description

kubectl describe pod orders-6d9f7c8b5d-x2k8p

Look at the container's Last State (Reason and Exit Code) and the Events at the bottom (probe failures, OOM kills, image or volume errors).

2. Read the logs of the crashed instance

kubectl logs orders-6d9f7c8b5d-x2k8p --previous
kubectl logs orders-6d9f7c8b5d-x2k8p -c app --previous   # multi-container pod

Without --previous you often see an empty log from the instance that's just starting.

3. Interpret the exit code

Exit codeUsual meaning
0Process finished normally. The container's command isn't a long-running server.
1Application error: config, missing file, failed connection
126 / 127Command not executable / command not found
137Killed (SIGKILL): OOMKilled, or killed after a failed liveness probe
139Segmentation fault
143Terminated (SIGTERM), e.g. during shutdown

How to fix the common causes

OOMKilled (exit 137): give it enough memory

If Last State shows Reason: OOMKilled, the container exceeded its memory limit. Check real usage with kubectl top pod, then raise the limit or fix the leak. For JVM apps, also make sure the heap fits inside the limit.

resources:
  requests: { memory: "512Mi", cpu: "250m" }
  limits:   { memory: "1Gi" }

Missing configuration, Secret or dependency

Exit code 1 with logs like "environment variable not set" or "connection refused" usually means a missing ConfigMap or Secret key, a wrong database URL, or a dependency that isn't ready yet. Check that referenced objects exist:

kubectl get configmap,secret -n my-namespace

Make the app retry connections at startup instead of exiting on the first failure.

Liveness probe kills a slow-starting app

If Events show Liveness probe failed followed by a restart, the app is being killed before it finishes starting. Add a startupProbe so liveness checks only begin once the app is up:

startupProbe:
  httpGet: { path: /healthz, port: 8080 }
  failureThreshold: 30
  periodSeconds: 5
livenessProbe:
  httpGet: { path: /healthz, port: 8080 }
  periodSeconds: 10

Wrong command, args or entrypoint (exit 0, 126, 127)

A command or args in the manifest replaces the image's entrypoint. Exit code 0 means the process ran and finished, for example a script instead of a server. 127 means the binary doesn't exist in the image.

Permission problems (common on OpenShift)

Images that write to root-owned paths fail when run as a non-root user. Make the image writable for an arbitrary user ID, or set a correct securityContext.

Debug interactively

Keep the container alive so you can look inside, or attach an ephemeral debug container:

kubectl debug -it orders-6d9f7c8b5d-x2k8p --image=busybox:1.36 --target=app

How to prevent it

  • Set realistic resource requests and limits from measured usage.
  • Use startup, readiness and liveness probes correctly. Each one has a different job.
  • Validate manifests and config in CI before deploying, and roll out with GitOps (Argo CD) so you can see and revert changes.
  • Alert on restart counts with Prometheus and Grafana (kube_pod_container_status_restarts_total).

Kubernetes troubleshooting, OpenShift and GitOps are core labs in our Docker, Kubernetes & OpenShift training.

Frequently asked questions

What does CrashLoopBackOff mean in Kubernetes?

The container keeps exiting after it starts, so the kubelet restarts it with an increasing back-off delay (up to five minutes). It is a symptom; the cause is whatever makes the process exit.

How do I see logs from a container that already crashed?

Use kubectl logs <pod> --previous (add -c <container> for multi-container pods). It shows the output of the last terminated instance.

What does exit code 137 mean?

The process was killed with SIGKILL. If the reason is OOMKilled, the container exceeded its memory limit; otherwise it may have been killed after failing a liveness probe.

Does CrashLoopBackOff happen in OpenShift too?

Yes. A common OpenShift-specific cause is an image that expects to run as root, because OpenShift runs containers with a random non-root user ID by default.

Learn Docker, Kubernetes & OpenShift hands-on with expert trainers

Fixing problems like this one is part of our Docker, Kubernetes & OpenShift training: live online classes for individuals and on-site corporate training for teams, with real projects and labs.

Training available in Hyderabad, Bangalore, Pune, Mumbai, Delhi, Chennai and online across India.