A web application deployment to Kubernetes is failing. Pods are in CrashLoopBackOff state, and the application is not accessible. You need to diagnose and fix the issue.
CrashLoopBackOffkubectl get pods shows:
NAME READY STATUS RESTARTS AGE
web-app-7d8f9b4c5-abc12 0/1 CrashLoopBackOff 5 10m
web-app-7d8f9b4c5-def34 0/1 CrashLoopBackOff 5 10m
# Get detailed pod information
kubectl describe pod web-app-7d8f9b4c5-abc12 -n production
# Check events
kubectl get events -n production --sort-by='.lastTimestamp'
What to Look For:
Common Findings:
ImagePullBackOff: Cannot pull container imageOOMKilled: Out of memoryError: Application crash# Get logs from current container
kubectl logs web-app-7d8f9b4c5-abc12 -n production
# Get logs from previous container (if crashed)
kubectl logs web-app-7d8f9b4c5-abc12 -n production --previous
# Follow logs in real-time
kubectl logs -f web-app-7d8f9b4c5-abc12 -n production
What to Look For:
# Get deployment YAML
kubectl get deployment web-app -n production -o yaml
# Check deployment status
kubectl rollout status deployment/web-app -n production
# Check deployment history
kubectl rollout history deployment/web-app -n production
What to Look For:
# Check ConfigMaps
kubectl get configmap -n production
kubectl describe configmap app-config -n production
# Check Secrets
kubectl get secrets -n production
kubectl describe secret db-credentials -n production
# Verify environment variables in pod
kubectl exec web-app-7d8f9b4c5-abc12 -n production -- env
What to Look For:
# Check resource usage
kubectl top pod web-app-7d8f9b4c5-abc12 -n production
# Check node resources
kubectl top nodes
# Check resource quotas
kubectl describe quota -n production
What to Look For:
# Run container locally with same configuration
docker run -e DATABASE_URL=$DATABASE_URL \
-e PORT=3000 \
myregistry/web-app:latest
# Check if application starts
curl http://localhost:3000/health
1. Missing Environment Variables
DATABASE_URL but not set2. Database Connection Failure
3. Application Code Error
4. Resource Limits Too Low
5. Wrong Image Tag
6. Health Check Failures
Problem Identified:
Logs show: Error: DATABASE_URL is not defined
Solution:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
namespace: production
data:
DATABASE_URL: "postgresql://db:5432/mydb"
NODE_ENV: "production"
PORT: "3000"
kubectl rollout status deployment/web-app -n production
4. **Verify Fix:**
```bash
# Check pod status
kubectl get pods -n production
# Check logs
kubectl logs -l app=web-app -n production --tail=50
# Test endpoint
curl https://web-app.example.com/health
# Validate YAML before applying
kubectl apply --dry-run=client -f deployment.yaml
# Use kubeval or similar tools
kubeval deployment.yaml
livenessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 3000
initialDelaySeconds: 5
periodSeconds: 5
kubectl logs)kubectl describe for detailed information