Home/Engineer/Troubleshooting/Diagnosing Kubernetes Pod Cr…
TroubleshootingIntermediatelinuxkubernetescrashloopbackoffdebugging

Diagnosing Kubernetes Pod CrashLoopBackOff — Complete Fixes by Cause

Understand what CrashLoopBackOff actually means and how backoff works, then walk through a systematic diagnosis and fix for each cause—exit codes, logs, probes, OOMKilled, missing config, and more.

Contents
  1. What is CrashLoopBackOff?
  2. Step 1: Get the overall picture
  3. Step 2: Interpret the exit code
  4. Step 3: Check the logs — the most important clue
  5. Fixes by cause
  6. Live debugging techniques
  7. Recap

What is CrashLoopBackOff?

CrashLoopBackOff is not an error in itself—it is a state. The container keeps starting, crashing, and restarting, so kubelet stretches the restart interval (back-off) to stop a restart storm. In plain terms: the container keeps dying, so kubelet is pausing briefly before trying again.

  • Restart interval doubles: 10s → 20s → 40s … up to a maximum of 5 minutes
  • The cause lives inside the container, so the real job is finding why it died
  • Occurs when restartPolicy is Always (the default) or OnFailure

CrashLoopBackOff is a bundle of symptoms, not the root cause. Tweaking the manifest without looking at the exit code and logs is usually wasted effort. Always narrow it down in this order: exit code → logs → events.


Step 1: Get the overall picture

Bash
kubectl get pods
# NAME        READY   STATUS             RESTARTS   AGE
# myapp-xxx   0/1     CrashLoopBackOff   5          3m

kubectl describe pod myapp-xxx

In the describe output, look at these two places first.

CODE
Last State:     Terminated
  Reason:       Error
 Exit Code: 1 ←
Events:
  Warning  BackOff  ...  Back-off restarting failed container

Step 2: Interpret the exit code

The exit code quickly narrows the cause.

Exit CodeMeaningCommon causes
0Clean exitMain process finished its work and exited (not a daemon)
1Generic application errorCode exception, missing config, dependency not reachable
2Shell usage / command errorTypo in command/args
126Cannot executeNo permission, not a binary
127Command not foundWrong command path, package not installed
137SIGKILL (128+9)OOMKilled or forced kill
139SIGSEGV (128+11)Segmentation fault (native crash)
143SIGTERM (128+15)Termination signal received normally

Step 3: Check the logs — the most important clue

You need the logs of the previously crashed container, not the current one.

Bash
kubectl logs myapp-xxx # (or )
kubectl logs myapp-xxx --previous # when ←
kubectl logs myapp-xxx -c sidecar # when

If restarts are fast, the container is gone before you can grab logs. Use --previous to see the last instance's logs—that's where the real cause shows up.


Fixes by cause

A. Application failed to start (Exit 1)

Usually missing config/env vars, or a failed DB connection.

Bash
kubectl logs myapp-xxx --previous
# : "ECONNREFUSED postgres:5432" → DB Service
  • Confirm env vars / ConfigMap / Secret are actually injected
  • If it's a dependency startup-order problem, wait with initContainers
YAML
initContainers:
- name: wait-db
  image: busybox:1.36
  command: ['sh','-c','until nc -z postgres 5432; do echo waiting; sleep 2; done']

B. OOMKilled (Exit 137)

The kernel killed the container because it exceeded its memory limit.

Bash
kubectl describe pod myapp-xxx | grep -A3 'Last State'
#   Reason: OOMKilled

Fix: raise the limit, or inspect the app's memory usage.

YAML
resources:
  requests: { memory: 256Mi }
 limits: { memory: 512Mi } # +

JVM, Node, and similar runtimes ignore the container limit and size the heap from host memory, which leads to OOM. Cap them to the container limit with -XX:MaxRAMPercentage or --max-old-space-size.

C. Bad command/args (Exit 127/126)

Bash
kubectl logs myapp-xxx --previous
# "exec: \"node\": executable file not found" →

When you override the image ENTRYPOINT, double-check the path and spelling, and drop into a shell for debugging.

Bash
kubectl run debug --rm -it --image=myapp:1.0 --command -- /bin/sh

D. Liveness probe failing

The app is fine, but livenessProbe is too aggressive, so kubelet keeps killing it. Exit code is 137/143 and the logs show no error.

YAML
livenessProbe:
  httpGet: { path: /healthz, port: 8080 }
 initialDelaySeconds: 30 # boot
  periodSeconds: 10
  failureThreshold: 3
# boot startupProbe
startupProbe:
  httpGet: { path: /healthz, port: 8080 }
  failureThreshold: 30
  periodSeconds: 5
ClueMost likely cause
App error in logs + Exit 1Config / dependency issue (A)
Reason: OOMKilled, Exit 137Out of memory (B)
"not found" + Exit 127command / image issue (C)
Clean logs + periodic 137/143Misconfigured probe (D)

E. Missing config resources (CreateContainerConfigError)

Strictly speaking this is the step before CrashLoop, but you often hit it together.

Bash
kubectl describe pod myapp-xxx
# Warning  Failed  ... configmap "app-config" not found

Confirm the referenced ConfigMap / Secret / key exists in the same namespace.


Live debugging techniques

Bash
# when — (/)
kubectl get events --sort-by=.lastTimestamp

# when (command sleep )
kubectl run probe --rm -it --image=myapp:1.0 \
  --command -- sleep 3600
kubectl exec -it probe -- sh

# Pod ( without)
kubectl debug -it myapp-xxx --image=busybox:1.36 --target=myapp

To inspect a live Deployment, temporarily kubectl edit the command to sleep. That stops the crash loop so you can investigate inside. Don't forget to revert afterward.


Recap

StepCommandWhat you get
Statuskubectl get/describe podSTATUS, exit code, events
Exit codeLast State in describeCause category
Logskubectl logs --previousThe actual crash reason
Eventskubectl get eventsScheduling / image / config problems
Diagnosekubectl run/exec/debugDirect look inside the container
Exit codeFirst fix to try
1Check logs → config / dependencies
137Raise memory limit (OOMKilled)
127/126Check command / image
137/143 + clean logsRelax probes / add startupProbe

CrashLoopBackOff only means "retrying." The cause is always inside the container. Narrow it down exit code → --previous logs → events and you can systematically fix almost every case.

#kubernetes#crashloopbackoff#debugging#troubleshooting
Editorial note

AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us

Topic-related official docs (auto-linked · not per-claim sources)Kubernetes documentation ↗

Questions & answers

Ask a question about this guide. We'll review and reply.