Kubernetes CrashLoopBackOff
A container is repeatedly crashing and restarting in Kubernetes.
Explanation
CrashLoopBackOff occurs when a Kubernetes pod's container is crashing repeatedly and Kubernetes is backing off the restart attempts. The container starts, crashes, Kubernetes waits an increasing amount of time (exponential backoff), then tries again. Common causes include application errors (missing config, database connection failure), misconfigured command/args, missing environment variables, insufficient resources, application bug causing immediate crash, and liveness probe failures. The pod never reaches a running state.
Common Causes
- Application crashes on startup
- Missing environment variables or config
- Database/dependency unreachable
- Incorrect container command/args
- Liveness probe failing
Solution
Check the container logs: kubectl logs pod-name. Check previous crashed container logs: kubectl logs pod-name --previous. Describe the pod for events: kubectl describe pod pod-name. Verify the container command/args are correct. Check that all required environment variables and config maps are present. Ensure database and other dependencies are accessible. Verify the container image works locally. Check resource limits - the container may be OOMKilling. Review liveness/readiness probe configuration. Check for application-level errors in the logs.
Code Example
# Check pod status
kubectl get pods
# NAME READY STATUS RESTARTS AGE
# myapp 0/1 CrashLoopBackOff 5 2m
# Check current logs
kubectl logs myapp-pod-xyz
# Check logs from crashed container
kubectl logs myapp-pod-xyz --previous
# Describe pod for events
kubectl describe pod myapp-pod-xyz
# Look at Events section for errors
# Common fixes:
# 1. Missing config
kubectl get configmap myapp-config
# 2. Database connection - check service
kubectl get svc postgres
kubectl exec -it myapp-pod-xyz -- env | grep DATABASE
# 3. Check command/args
apiVersion: v1
kind: Pod
spec:
containers:
- name: myapp
image: myapp:latest
command: ["node"]
args: ["server.js"] # verify this file exists!
# 4. Check resource limits
kubectl top pod myapp-pod-xyz
# 5. Test image locally
docker run --rm myapp:latest
Error Information
Language
bash
Framework
kubernetes
Difficulty
Intermediate
Views
12
Related Errors
DevOps
Docker Permission Denied
The current user doesn't have permission to run Docker commands.
General
Git Merge Conflict
Git cannot automatically merge changes from two branches because they modified the same lines.
DevOps
Container Name Already in Use
A Docker container with the specified name already exists.
DevOps
Ansible Unreachable Host
Ansible cannot connect to the target host via SSH or WinRM.