Operating, scaling and debugging · 5 MIN READ

Debug failing pods: get, describe, logs, exec and events in order

Find out why a pod is not working by reading its STATUS, the Events in describe, the current and previous logs, the container from inside and the namespace events, and fix the most common failures.

A broken pod always says why, but the answer is spread over its status, its events, the logs of the current and the previous container, and the state inside it. Opening the logs first misses pods that never started, and exec cannot reach a container that keeps restarting. A fixed triage order finds the cause in minutes and works the same during an incident at 3 a.m.

kubernetes · A MAP OF THE IDEA

  1. get: read STATUS and READY
  2. describe: Events at the bottom
  3. logs --previous for crashes
  4. exec and events to confirm

Useful when

  • The same five commands diagnose almost every pod failure.
  • Waiting reasons and exit codes narrow the cause before you read any code.

Watch out

  • Events expire after an hour, so collect them early.
  • The current log of a restarting container hides the crash; use --previous.

Implementation & operation cost: A minute of reading per pod, plus log and event retention that outlives the pods themselves.

01

What the STATUS column is telling you

kubectl get pods computes STATUS from the pod phase and the state of its containers, so it names the most specific problem it can find. Pending means the pod is not scheduled yet or its images are not pulled; ContainerCreating means volumes and images are being prepared. ErrImagePull, ImagePullBackOff and CreateContainerConfigError are waiting reasons: the container never started. CrashLoopBackOff, Error and OOMKilled describe a container that started and then ended. Running only says that a process exists; READY 0/1 means a readiness probe is failing and Services send the pod no traffic. RESTARTS counts how often the kubelet restarted a container and when it last did, as in "2 (12s ago)". Add -o wide for the node and pod IP: several broken pods on one node point at the node, not at the application.

02

The triage order

Work from the outside in. get tells you which pods are affected and how. describe shows each container's State and Last State with Reason and Exit Code, its probes and mounts, and at the bottom the Events: scheduling, image pulls, probe failures and back-offs, oldest first. logs prints what the current container wrote; when the container is restarting, --previous prints the run that crashed, which is usually the one you need. exec runs a command in a running container to check environment variables, files and DNS from the pod's point of view. events --for lists the events of one object with their age, and events --types=Warning shows every warning in the namespace at once. The API server keeps events for one hour by default, so read them early.

bash
kubectl get pods -o wide
kubectl describe pod -l app=web
kubectl logs deploy/web --tail=50
kubectl logs deploy/web --previous
kubectl exec deploy/web -- printenv
kubectl events --for pod/needs-config
kubectl events --types=Warning
Read the code

logs and exec accept deploy/web and pick one of the Deployment's pods, which saves copying generated names; describe accepts -l to describe every matching pod. On a real cluster, kubectl debug -it POD --image=busybox --target=web adds an ephemeral debugging container to a pod whose image has no shell, such as a distroless Go image; kubectl debug is not available in the lab terminal.

03

Pods that never start

Pending with a FailedScheduling event means no node passed the scheduler's filters, and the message counts why: "0/3 nodes are available: 3 Insufficient cpu" (lower the requests or add capacity), an untolerated taint, a nodeSelector or affinity that no node matches, or "pod has unbound immediate PersistentVolumeClaims" (check kubectl get pvc and its StorageClass). ErrImagePull is a failed pull; ImagePullBackOff is the kubelet waiting before the next try, up to five minutes apart. The Failed event says which problem you have: "not found" is a typo in the name or tag, "unauthorized" or "pull access denied" is a private registry without imagePullSecrets, and "no match for platform" is the wrong CPU architecture. CreateContainerConfigError means a referenced ConfigMap, Secret or key does not exist, or runAsNonRoot meets an image that runs as root. The kubelet keeps retrying, so creating the missing object fixes the pod without deleting it.

04

Pods that start and then fail

CrashLoopBackOff means the container keeps exiting and the kubelet waits 10 s, 20 s, 40 s and so on, up to five minutes, before each restart; the delay resets after ten minutes of clean running. While it waits, the current log may show nothing useful, so read --previous. Last State gives the exit code: 1 is an ordinary failure such as log.Fatal or os.Exit(1), 2 is an unrecovered Go panic, 137 is 128 + 9, a SIGKILL, and 143 is 128 + 15, a SIGTERM the process obeyed. 137 with Reason OOMKilled means the container went over its memory limit: raise the limit, fix the leak, and set GOMEMLIMIT below the limit so the Go garbage collector works harder before the kernel kills the process. 137 without OOMKilled usually means a failed liveness probe or an expired grace period. Running with READY 0/1 is a failing readiness probe: the Unhealthy event names the probe and the status code it got.

05

Try it in the lab terminal

Break things on purpose, then diagnose each with the triage order: a Deployment whose image tag does not exist, one whose image panics at start, and a pod that reads an environment variable from a ConfigMap that nobody created. cluster tick 30s gives the kubelet time to retry and back off a few times. Then fix the two problems that configuration can fix, and confirm that the variable arrived inside the container.

bash
kind create cluster
kubectl create deployment typo --image=nginx:1.99
kubectl create deployment crash --image=gopherforge/web:v3-crash
cat > needs-config.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata:
  name: needs-config
spec:
  containers:
  - name: app
    image: gopherforge/web:v2
    env:
    - name: LOG_LEVEL
      valueFrom:
        configMapKeyRef:
          name: app-config
          key: log-level
EOF
kubectl apply -f needs-config.yaml
cluster tick 30s
kubectl get pods
kubectl describe pod -l app=typo
kubectl logs deploy/crash --previous
kubectl get pod -l app=crash -o jsonpath='{.items[0].status.containerStatuses[0].lastState.terminated.exitCode}'
kubectl events --for pod/needs-config
kubectl set image deploy/typo nginx=nginx:1.27
kubectl create configmap app-config --from-literal=log-level=debug
kubectl rollout status deploy/typo
kubectl get pods
kubectl exec needs-config -- printenv LOG_LEVEL
Read the code

After the tick, get pods shows crash-<hash>-<id> in CrashLoopBackOff with "2 (12s ago)", needs-config in CreateContainerConfigError and typo-<hash>-<id> in ImagePullBackOff. The typo pod's Events include Failed to pull image "nginx:1.99" ... not found. logs --previous prints the panic, a nil pointer dereference in main.loadConfig, and the exit code is 2, Go's code for a panic. events --for shows Error: configmap "app-config" not found (x6). After set image and the new ConfigMap, typo and needs-config run and printenv prints debug; crash stays broken until its code is fixed.

TAKE THIS WITH YOU

Read STATUS, then the Events at the bottom of describe, then logs --previous, then exec and events. Waiting reasons point at scheduling, images or configuration; exit codes and OOMKilled point at the process itself.

Check your understanding

A pod is in CrashLoopBackOff, and kubectl logs shows only a startup line from the container that is waiting to restart. Which command shows the output of the run that crashed?

Go to the source

Progress stays in this browser. No account needed.