Skip to Content

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 , founding engineer running Kubernetes in production. Updated .

my pod is brokenPendingkubectl describeread the EventsCrashLoopBackOffkubectl logs--previousImagePullBackOffcheck the imagename and registryRunning, 0/1probes andService endpoints
The chapter in one pictureThe status tells you where to look first.

By the end you can

0 of 5

The method

  1. 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.
  2. 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.
  3. Walk down the layers. get for status, describe for events, logs for the app, then exec or debug from inside, then the node.
  4. 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

    CommandUse it for
    kubectl get pods -o wideStatus, restarts, IP and node at a glance
    kubectl describe pod NAMEEvents: scheduling, pulls, probes, kills
    kubectl get events -A --sort-by=.lastTimestampEverything that happened recently, cluster-wide
    kubectl logs NAME --previous -c CONTAINERWhy the last container died
    kubectl logs -l app=web --prefix --tail=50Logs from every replica at once
    kubectl debug -it NAME --image=busybox:1.37 --target=appA shell next to a container that has none
    kubectl top podsWho is using the CPU and memory
    kubectl rollout history deploy/NAMEWhat 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:

    Terminal
    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

    Terminal
    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

    Live lab · no install

    Five broken apps

    Each one is broken differently. Fix them all using only kubectl.

    kind-learn
    1. Tasks0/7
    2. Deploy five broken apps
      kubectl create namespace broken
      kubectl apply -f broken.yaml
      kubectl -n broken get pods
    3. Fix app1

      Start with describe. The last events name the problem.

      kubectl -n broken describe pod -l app=app1 | tail -n 4

      A typo in the tag: ErrImagePull, then ImagePullBackOff.

    4. Fix app2

      It starts and exits. What did it print before it died?

      kubectl -n broken logs deploy/app2 --previous

      The app told you: DATABASE_URL was missing. kubectl set env fixed it.

    5. Fix app3
      kubectl -n broken describe pod -l app=app3 | tail -n 2

      CreateContainerConfigError: it referenced a ConfigMap that did not exist.

    6. Fix app4
      kubectl -n broken describe pod -l app=app4 | tail -n 2

      It asked for 64Gi of memory. No node had that, so the scheduler left it Pending.

    7. 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 endpointslices

      The selector said app-5, the pods say app5. Zero endpoints, zero traffic.

    8. Clean up
      kubectl delete namespace broken
    9. Lab complete. Keep experimenting, or press Reset to start again.
    ↑↓ history · Tab complete · Ctrl+C stop
    Cluster map live
    • 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.

    broken.yaml
    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 }]
    Terminal
    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             40s
    app5
    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
    Terminal
    # 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

    1. 1. Production errors started 10 minutes ago. What is the first question?
    2. 2. A container image has no shell or debugging tools. How do you get a shell next to it?
    3. 3. Status CreateContainerConfigError. Most likely cause?
    4. 4. A node shows NotReady. What does draining it do?

    Further reading