Kubernetes

How to Debug CrashLoopBackOff in Kubernetes

A systematic approach to diagnosing and fixing CrashLoopBackOff errors in Kubernetes pods.

Marcus LeeFebruary 18, 20262 min read
Share:

CrashLoopBackOff is one of the most common Kubernetes errors, and one of the most poorly explained by kubectl get pods alone. Here's how to actually diagnose it.

Step 1: Confirm what's happening

bash
kubectl get pods
NAME READY STATUS RESTARTS AGE api-7d9f8c9d-x2n4q 0/1 CrashLoopBackOff 6 4m

The status means: the container starts, exits (crashes or completes), and Kubernetes keeps restarting it with an increasing backoff delay.

Step 2: Read the logs from the crashed container

bash
kubectl logs api-7d9f8c9d-x2n4q --previous

The --previous flag is essential — it shows logs from the last terminated container, not the current (likely empty) restart attempt.

Step 3: Check the exit code and reason

bash
kubectl describe pod api-7d9f8c9d-x2n4q

Look at the Last State section:

Last State: Terminated Reason: Error Exit Code: 1

Common exit codes:

Exit CodeMeaning
0Container exited cleanly (often a misconfigured entrypoint for a long-running service)
1Application error — check logs
137OOMKilled — the container exceeded its memory limit
143SIGTERM — often a graceful shutdown that took too long

Step 4: Match the exit code to a fix

OOMKilled (137): Raise the memory limit or fix a memory leak.

yaml
resources:
  limits:
    memory: "512Mi"
  requests:
    memory: "256Mi"

Application error (1): Usually a missing environment variable, bad config, or failed dependency connection — the logs from Step 2 will show the stack trace.

Readiness/liveness probe failing: If the app takes longer to boot than the probe allows, increase initialDelaySeconds.

yaml
livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
  initialDelaySeconds: 30
  periodSeconds: 10

Step 5: Verify the fix

bash
kubectl rollout restart deployment api
kubectl get pods -w

Watch for RESTARTS to stop increasing and STATUS to settle on Running.

Quick reference checklist

  1. kubectl logs <pod> --previous
  2. kubectl describe pod <pod> and check the exit code
  3. Match exit code to cause (OOM, app error, probe timeout)
  4. Apply the fix and roll out again
Advertisement
Marcus Lee
Marcus Lee

Cloud & DevOps Engineer

Marcus covers Kubernetes, cloud infrastructure, and CI/CD. He's spent a decade running production systems at scale.

Related Articles