Introduction
If you work with containers on Kubernetes, the dreaded CrashLoopBackOff status is a common roadblock. This post walks you through the root causes, diagnostic commands, and concrete fixes so you can get your pod back to a steady Running state.
What is CrashLoopBackOff?
CrashLoopBackOff means the container started, crashed, and Kubernetes is repeatedly trying to restart it. The back‑off timer grows after each failure, so the pod never reaches Ready.
Common Root Causes
- Faulty
ENTRYPOINTorCMDin the Docker image - Missing or incorrect environment variables
- Unhealthy liveness/readiness probes
- Resource limits that cause OOM kills
- Dependency services not reachable at start‑up
Step‑by‑Step Troubleshooting
- Inspect pod status
kubectl get pod myapp-pod -n myns
kubectl describe pod myapp-pod -n myns
- Check container logs
kubectl logs myapp-pod -c myapp -n myns
- Validate the image entrypoint
FROM python:3.11-slim
WORKDIR /app
COPY . .
# Common mistake: typo in the script name
ENTRYPOINT ["python", "app.py"]
If the script name is wrong, the container exits with code 127.
- Verify environment variables
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: db-secret
key: url
Missing keys cause the application to abort immediately.
- Adjust liveness/readiness probes
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
exec:
command: ["cat", "/tmp/ready"]
initialDelaySeconds: 2
periodSeconds: 5
Overly aggressive probes kill a still‑initializing container.
- Check resource limits
resources:
limits:
memory: "256Mi"
cpu: "500m"
If the app needs more memory, it will be OOM‑killed and restart.
- Redeploy after fixing
kubectl apply -f deployment.yaml
kubectl rollout status deployment/myapp -n myns
Example: Fixing an Entrypoint Typo
A pod kept crashing with the log exec: "nodejs": executable file not found in $PATH. The Dockerfile incorrectly used nodejs instead of node.
# Bad
ENTRYPOINT ["nodejs", "server.js"]
# Fixed
ENTRYPOINT ["node", "server.js"]
After rebuilding and pushing the image, the pod transitioned to Running.
Monitoring After the Fix
kubectl get events -n myns --sort-by=.metadata.creationTimestamp- Use k9s or Lens to watch pod restarts in real time.
- Set up alerts in Prometheus/Grafana for
kube_pod_container_status_waiting_reason.
Resources
By following these steps, you can quickly pinpoint why a container enters CrashLoopBackOff and apply a lasting solution. Happy debugging!
Top comments (0)