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
kubectl get podsNAME 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
kubectl logs api-7d9f8c9d-x2n4q --previousThe --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
kubectl describe pod api-7d9f8c9d-x2n4qLook at the Last State section:
Last State: Terminated
Reason: Error
Exit Code: 1
Common exit codes:
| Exit Code | Meaning |
|---|---|
| 0 | Container exited cleanly (often a misconfigured entrypoint for a long-running service) |
| 1 | Application error — check logs |
| 137 | OOMKilled — the container exceeded its memory limit |
| 143 | SIGTERM — 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.
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.
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 30
periodSeconds: 10Step 5: Verify the fix
kubectl rollout restart deployment api
kubectl get pods -wWatch for RESTARTS to stop increasing and STATUS to settle on Running.
Quick reference checklist
kubectl logs <pod> --previouskubectl describe pod <pod>and check the exit code- Match exit code to cause (OOM, app error, probe timeout)
- Apply the fix and roll out again