Kubernetes Field Guide · Chapter 15 of 16
Troubleshooting: from CrashLoopBackOff to root cause
Every failure you have met in this guide follows a few patterns. This chapter turns them into a method you can run under pressure: scope the problem, walk down the layers, read what Kubernetes is already telling you, and fix forward or roll back.
- 40 min
- Advanced
- Hands-on
- Free
By Joshua Sequeira, founding engineer running Kubernetes in production. Updated .
By the end you can
0 of 5
Live lab in this chapter
A real-feeling terminal and a live cluster map, right in your browser. Every command block below has a ▶ Run in lab button.
The method
- Stabilise first. If a recent deploy lines up with the problem, roll it back (
kubectl rollout undo,helm rollback) and investigate after. Users care about recovery, not root cause. - Scope it. One pod, one Deployment, one node, one namespace or everything? The scope points at the layer: one pod is the app, one node is the node, everything is the control plane, DNS or the network.
- Walk down the layers.
getfor status,describefor events,logsfor the app, thenexecordebugfrom inside, then the node. - Change one thing at a time, and write down what you tried. That note becomes the incident timeline.
Symptom decision tree
Start from what kubectl get pods shows you:
Interactive
From symptom to cause
The toolkit
| Command | Use it for |
|---|---|
kubectl get pods -o wide | Status, restarts, IP and node at a glance |
kubectl describe pod NAME | Events: scheduling, pulls, probes, kills |
kubectl get events -A --sort-by=.lastTimestamp | Everything that happened recently, cluster-wide |
kubectl logs NAME --previous -c CONTAINER | Why the last container died |
kubectl logs -l app=web --prefix --tail=50 | Logs from every replica at once |
kubectl debug -it NAME --image=busybox:1.37 --target=app | A shell next to a container that has none |
kubectl top pods | Who is using the CPU and memory |
kubectl rollout history deploy/NAME | What changed and when |
Networking failures
Debug networking from inside the cluster, where the problem is. The nicolaka/netshoot image has curl, dig, nslookup and tcpdump:
kubectl run net --rm -it --image=nicolaka/netshoot -- bash
dig web.default.svc.cluster.local +short
curl -sv http://web.default
curl -sv http://10.244.0.31:80
dig- Does the name resolve? If not, check CoreDNS pods in kube-system.
curl the Service- Fails while a pod IP works? Check the selector, endpoints and targetPort.
curl a pod IP- Fails too? The app, its port, or a NetworkPolicy.
Work outwards in that order: the pod itself, then the Service, then Ingress, then DNS and the load balancer outside.
Node failures
kubectl get nodes
kubectl describe node NODE | grep -A8 Conditions
kubectl cordon NODE
kubectl drain NODE --ignore-daemonsets --delete-emptydir-data
Conditions- MemoryPressure, DiskPressure, PIDPressure and Ready. A full disk is a common cause of evictions and NotReady.
cordon- No new pods land here.
drain- Evicts pods gracefully, honouring PodDisruptionBudgets, so you can fix or replace the node.
To look at the node itself without SSH, kubectl debug node/NODE -it --image=busybox:1.37 starts a pod on it with the host filesystem mounted at /host.
Incident drill
Put the method to work on a realistic page. Every command below returns what you would actually see. The goal is not to run all of them: it is to follow the chain from symptom to cause in as few steps as you can.
Interactive · Incident drill
03:10. Paged: shop.example.com/checkout returns 503.
0 commands run
Pick commands to run. Use as few as you can, then name the root cause.
Root cause?
Hands-on: five broken apps
The lab is docked at the bottom of your screen.
Live lab · no install
Five broken apps
Each one is broken differently. Fix them all using only kubectl.
- Tasks0/7
Deploy five broken apps
kubectl create namespace broken kubectl apply -f broken.yaml kubectl -n broken get podsFix app1
Start with describe. The last events name the problem.
kubectl -n broken describe pod -l app=app1 | tail -n 4A typo in the tag: ErrImagePull, then ImagePullBackOff.
Fix app2
It starts and exits. What did it print before it died?
kubectl -n broken logs deploy/app2 --previousThe app told you: DATABASE_URL was missing. kubectl set env fixed it.
Fix app3
kubectl -n broken describe pod -l app=app3 | tail -n 2CreateContainerConfigError: it referenced a ConfigMap that did not exist.
Fix app4
kubectl -n broken describe pod -l app=app4 | tail -n 2It asked for 64Gi of memory. No node had that, so the scheduler left it Pending.
Fix app5
It looks healthy. Try to reach it through its Service.
kubectl -n broken run t --rm -it --image=busybox:1.37 --restart=Never -- wget -qO- -T 3 http://app5 kubectl -n broken get endpointslicesThe selector said app-5, the pods say app5. Zero endpoints, zero traffic.
Clean up
kubectl delete namespace broken- Lab complete. Keep experimenting, or press Reset to start again.
- ready
- starting / not ready
- failing
- terminating
Prefer your own machine? The same steps on a local cluster
Each of these Deployments is broken in a different way. Save as broken.yaml, apply it, and fix all five using only kubectl and the method above.
apiVersion: apps/v1
kind: Deployment
metadata: { name: app1, namespace: broken }
spec:
selector: { matchLabels: { app: app1 } }
template:
metadata: { labels: { app: app1 } }
spec:
containers:
- { name: web, image: "nginx:1.27-alpine-typo" }
---
apiVersion: apps/v1
kind: Deployment
metadata: { name: app2, namespace: broken }
spec:
selector: { matchLabels: { app: app2 } }
template:
metadata: { labels: { app: app2 } }
spec:
containers:
- name: api
image: busybox:1.37
command: ["sh", "-c", "[ -n \"$DATABASE_URL\" ] || { echo 'fatal: DATABASE_URL is not set'; exit 1; }; sleep 3600"]
---
apiVersion: apps/v1
kind: Deployment
metadata: { name: app3, namespace: broken }
spec:
selector: { matchLabels: { app: app3 } }
template:
metadata: { labels: { app: app3 } }
spec:
containers:
- name: web
image: nginx:1.27
envFrom: [{ configMapRef: { name: app3-config } }]
---
apiVersion: apps/v1
kind: Deployment
metadata: { name: app4, namespace: broken }
spec:
selector: { matchLabels: { app: app4 } }
template:
metadata: { labels: { app: app4 } }
spec:
containers:
- name: web
image: nginx:1.27
resources: { requests: { memory: 64Gi } }
---
apiVersion: apps/v1
kind: Deployment
metadata: { name: app5, namespace: broken }
spec:
selector: { matchLabels: { app: app5 } }
template:
metadata: { labels: { app: app5 } }
spec:
containers:
- { name: web, image: "nginx:1.27" }
---
apiVersion: v1
kind: Service
metadata: { name: app5, namespace: broken }
spec:
selector: { app: app-5 }
ports: [{ port: 80, targetPort: 80 }]kubectl create namespace broken
kubectl apply -f broken.yaml
kubectl -n broken get pods
NAME READY STATUS RESTARTS AGE
app1-6d8c9b7f5c-x2k4p 0/1 ImagePullBackOff 0 40s
app2-7f9b8c6d4e-m8q2r 0/1 CrashLoopBackOff 2 (20s ago) 40s
app3-5c7d9f8b6a-p4t6l 0/1 CreateContainerConfigError 0 40s
app4-8b6c5d4e3f-h7j9k 0/1 Pending 0 40s
app5-9d8e7f6a5b-w3v5n 1/1 Running 0 40sapp5- Looks healthy. Its Service is the problem: try reaching it.
Mini mission
Fix all five
Diagnose each one before you look. Note the command that told you the cause.
Reveal one safe solution
# app1: describe shows the pull error for the typo'd tag
kubectl -n broken set image deploy/app1 web=nginx:1.27-alpine
# app2: logs --previous prints "fatal: DATABASE_URL is not set"
kubectl -n broken set env deploy/app2 DATABASE_URL=postgres://db:5432/app
# app3: describe says configmap "app3-config" not found
kubectl -n broken create configmap app3-config --from-literal=MODE=prod
# app4: describe shows FailedScheduling, Insufficient memory
kubectl -n broken set resources deploy/app4 --requests=memory=64Mi
# app5: endpoints are empty because the selector says app-5
kubectl -n broken patch svc app5 -p '{"spec":{"selector":{"app":"app5"}}}'
kubectl -n broken get pods
kubectl -n broken get endpointslices
All five Running and app5 with endpoints. app3 may need a moment: the kubelet retries once the ConfigMap exists. Clean up with kubectl delete namespace broken.
Check yourself
Quiz
0 of 4 answered