debugMajorpending
Debug: Kubernetes CrashLoopBackOff
Viewed 0 times
crashloopbackoffpod crashkubernetes debugexit codeliveness probe
Error Messages
Problem
Kubernetes pod is in CrashLoopBackOff state, restarting repeatedly.
Solution
Diagnose CrashLoopBackOff:
Common causes:
# 1. Check pod events and status
kubectl describe pod <pod-name>
# Look at:
# - Events section (bottom) for error details
# - Last State -> Reason and Exit Code
# - Containers -> State
# 2. Check container logs
kubectl logs <pod-name>
# If container restarts too fast:
kubectl logs <pod-name> --previous # Logs from last crash
# 3. Common exit codes:
# 0 = Normal exit (maybe missing CMD or app exits immediately)
# 1 = Application error
# 137 = SIGKILL (OOM killed or liveness probe failed)
# 139 = SIGSEGV (segmentation fault)
# 143 = SIGTERM (graceful shutdown)
# 4. Check if OOM killed
kubectl describe pod <pod-name> | grep -i oom
# Fix: Increase memory limits in deployment spec
# 5. Check liveness probe
# If probe fails, K8s kills and restarts the container
kubectl get pod <pod-name> -o yaml | grep -A 10 livenessProbe
# Fix: Increase initialDelaySeconds or timeoutSeconds
# 6. Debug interactively
# Override command to keep container alive
kubectl run debug --image=<image> --command -- sleep infinity
kubectl exec -it debug -- /bin/sh
# Test if app can start manually
# 7. Check config and secrets
kubectl get configmap <name> -o yaml
kubectl get secret <name> -o yaml
# Missing config/secrets cause immediate crashes
# 8. Check resource limits
kubectl top pod <pod-name> # Current usage
# Compare with limits in deployment specCommon causes:
- Missing environment variables or config
- Database/service not reachable
- Liveness probe too aggressive
- Memory limit too low (OOM)
- Application bug causing immediate crash
- Wrong Docker image tag
Why
CrashLoopBackOff means K8s is backing off restart attempts because the container keeps crashing. The key is finding WHY it crashes via logs, events, and exit codes.
Context
Kubernetes pod troubleshooting
Revisions (0)
No revisions yet.