DevOpsil
KubernetesCritical

Fix: Kubernetes Pod CrashLoopBackOff

Pod status shows CrashLoopBackOff

!Symptoms

  • Pod status shows CrashLoopBackOff
  • Pod restarts increasing rapidly
  • Application is unreachable or intermittently available
  • kubectl get pods shows high restart count

?Root Causes

  • Application crashing on startup due to missing config or secrets
  • Liveness probe failing repeatedly
  • Insufficient memory or CPU causing OOM kills before probe succeeds
  • Missing dependencies or environment variables
  • Application binary or entrypoint not found in container image

#Diagnosis Steps

  1. 1Run `kubectl describe pod <pod-name>` to check events and exit codes
  2. 2Run `kubectl logs <pod-name> --previous` to see logs from the last crashed container
  3. 3Check exit code: 137 = OOMKilled, 1 = application error, 127 = command not found
  4. 4Verify configmaps and secrets are mounted correctly with `kubectl get cm` and `kubectl get secret`
  5. 5Check resource limits with `kubectl describe pod` and compare to actual usage

>Fix

  1. 1Fix the application error shown in `kubectl logs --previous`
  2. 2If OOMKilled (exit 137), increase memory limits in the pod spec
  3. 3If command not found (exit 127), verify the container image and entrypoint
  4. 4Ensure all required environment variables and secrets exist
  5. 5Adjust liveness probe initialDelaySeconds if the app needs more startup time
  6. 6Use a startup probe for slow-starting applications

*Prevention

  • Implement proper health check endpoints in your application
  • Set appropriate resource requests and limits based on load testing
  • Use startup probes for applications with variable startup times
  • Add readiness gates before routing traffic to new pods
  • Test container images locally before deploying to the cluster

Related Error Messages

CrashLoopBackOffBack-off restarting failed containerpod has unbound immediate PersistentVolumeClaimscontainer exited with code 1container exited with code 137