Skip to content
LF Cert Trainer

Lesson 138 · Section 12: Troubleshooting

Lesson 138: Troubleshooting introduction: a method that finds the fault

Troubleshooting is 30% of the CKA. This lesson gives you one repeatable method for any broken cluster: define the symptom, pick the layer, read the evidence in a fixed order (get, describe, events, logs), change one thing, and verify. · 18 min read · 3 min video

1/9Troubleshooting introduction
0:00 / 3:03

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

Why troubleshooting needs a method

Troubleshooting is the largest domain of the CKA exam: 30% of the score. The tasks are written the way a colleague would report a problem: "the cart application in namespace shop does not respond", "node01 is not ready", "kubectl hangs on the control plane". Nobody tells you which component broke. You have to find it, fix it and leave the cluster in a state the grader can check.

People who struggle with these tasks usually know the fix. What costs them is the search: jumping between Pods, editing things on a hunch, restarting components and hoping. A method turns the search into a short, predictable sequence of commands, so that even an unfamiliar fault is found in a few minutes.

The curriculum (v1.37) splits the domain into five competencies. The lessons in this section follow them:

CompetencyLesson in this sectionAlso covered in
Troubleshoot clusters and nodesWorker node failureCluster maintenance, kubeadm
Troubleshoot cluster componentsControl plane failureCluster architecture, static Pods
Monitor cluster and application resource usage(this lesson, plus the next ones)Monitor cluster components
Manage and evaluate container output streamsApplication failure, kubectl debugManaging application logs
Troubleshoot services and networkingNetwork troubleshootingDNS, CoreDNS, Services, Network policies

Four layers

Four layers, from your object down to the machinereaches?built byruns onruns onApplicationPods, Services, configNetworkingDNS, Services, CNIControl planeAPI, scheduler, etcdNodeskubelet, runtime, OS
Four layers, from your object down to the machine. Every fault lives in one layer. Start at the top, where the symptom shows, and move down only when the layer above is clean.

Parts:

  • Application (Pods, Services, config)
  • Networking (DNS, Services, CNI)
  • Control plane (API, scheduler, etcd)
  • Nodes (kubelet, runtime, OS)

Connections:

  • Application to Networking: reaches?
  • Networking to Control plane: built by
  • Control plane to Nodes: runs on
  • Application to Nodes: runs on

Every fault you will meet lives in one of four layers. The symptom usually shows at the top, but the cause can be lower down:

LayerWhat lives thereTypical symptoms
ApplicationPods, Deployments, Services, ConfigMaps, Secrets, PVCs, probesCrashLoopBackOff, ImagePullBackOff, Pending, 0/1 Ready, a Service that answers nothing
NetworkingCoreDNS, kube-proxy, the CNI plugin, NetworkPoliciesName lookups fail, Services time out, Pods on different nodes cannot talk
Control planekube-apiserver, etcd, kube-scheduler, kube-controller-managerkubectl hangs or is refused, new Pods stay Pending, Deployments do not create Pods
Nodeskubelet, container runtime (containerd), the OS, certificates, diskNode NotReady, Pods stuck Terminating or ContainerCreating on one node

A quick way to decide: can you run kubectl get nodes? If not, the control plane (or your kubeconfig) is the problem and nothing else matters yet. If you can, is any node NotReady? Then the node layer. If the nodes are fine, start at the object the task names and work down.

The loop

The loop: one change at a timelookexplainactchecknot fixedSymptomwhat exactly fails?Evidenceget, describe, logsHypothesisone causeOne changesmallest fixVerifysymptom gone?
The loop: one change at a time. Define what is wrong, gather evidence, form one hypothesis, change one thing, and check. If the check fails, undo or keep the change knowingly, and go round again.

Parts:

  • Symptom (what exactly fails?)
  • Evidence (get, describe, logs)
  • Hypothesis (one cause)
  • One change (smallest fix)
  • Verify (symptom gone?)

Connections:

  • Symptom to Evidence: look
  • Evidence to Hypothesis: explain
  • Hypothesis to One change: act
  • One change to Verify: check
  • Verify to Evidence: not fixed
  1. Symptom. Write down, in one sentence, what fails and how you will know it is fixed. "Requests to http://web.shop time out from inside the cluster" is a symptom. "Networking is broken" is not.
  2. Evidence. Collect before you change. Most faults announce themselves in a status, an event or a log line.
  3. Hypothesis. One cause that explains all the evidence. If it explains only part of it, keep looking.
  4. One change. The smallest change that tests the hypothesis. Two changes at once and you will not know which one helped, or which one broke something else.
  5. Verify. Check the symptom itself, not the command you just ran. deployment.apps/web edited proves nothing.

Where the evidence lives

Where the evidence liveswhy?when?inside the appAPI down?kubectl getstatus, restartskubectl describeconditions, eventskubectl eventsnamespace timelinekubectl logs--previousOn the nodejournalctl, crictl
Where the evidence lives. Each tool answers a different question. Status says what, describe and events say why the cluster thinks so, logs say why the program thinks so, and the node tells you when the API cannot.

Parts:

  • kubectl get (status, restarts)
  • kubectl describe (conditions, events)
  • kubectl events (namespace timeline)
  • kubectl logs (--previous)
  • On the node (journalctl, crictl)

Connections:

  • kubectl get to kubectl describe: why?
  • kubectl describe to kubectl events: when?
  • kubectl events to kubectl logs: inside the app
  • kubectl logs to On the node: API down?
ToolQuestion it answersNotes
kubectl get <kind> -o wideWhat state is it in, where does it run, how often has it restarted?-A for all namespaces; -w to watch
kubectl describe <kind> <name>Why does the cluster think so?Conditions, container states, exit codes, and the last events for that object
kubectl eventsWhat happened recently, in order?--types=Warning, --for pod/web, -A, -w
kubectl logs <pod>What did the program say?-c for one container, --previous for the last crashed run, --all-containers
kubectl get <kind> <name> -o yamlWhat exactly is configured?Compare with what the task asks for
journalctl -u kubelet, crictl ps -a, crictl logsWhat is happening on the node?The only way in when the API server is down
Under the hood · kubectl events versus kubectl get events

Events are ordinary API objects (events.k8s.io/v1) that components write when something notable happens: the scheduler failing to place a Pod, the kubelet failing to pull an image, a probe failing. They are kept for one hour by default (the API server's --event-ttl), so old faults may have left no events behind.

kubectl get events lists them, but unsorted. kubectl events (stable since kubectl 1.28) sorts by time and adds useful filters:

kubectl events -n shop                         # the namespace, oldest first, newest last
kubectl events -n shop --for pod/cart-7d9c6b5f4-k2x8p
kubectl events -A --types=Warning              # only problems, all namespaces
kubectl events -n shop -w                      # follow live while you fix
kubectl get events -A --sort-by=.lastTimestamp # the older way, still works

The REASON column is the fastest clue: FailedScheduling, Failed (pull), BackOff, Unhealthy (probe), FailedMount, FailedCreate (ReplicaSet could not create a Pod, often a quota or admission problem).

Using it

Example · The opening move for any troubleshooting task

Before you look at the object the task names, spend fifteen seconds on the whole cluster. It catches the cases where the real fault is somewhere else:

kubectl config use-context <the context the task names>
kubectl get nodes
kubectl get pods -A | grep -vE 'Running|Completed'
kubectl events -A --types=Warning | tail -n 20
NAME           STATUS     ROLES           AGE   VERSION
controlplane   Ready      control-plane   12d   v1.37.0
node01         NotReady   <none>          12d   v1.37.0

NAMESPACE     NAME                       READY   STATUS             RESTARTS
kube-system   kube-proxy-7xqzv           0/1     ContainerCreating  0
shop          cart-7d9c6b5f4-k2x8p       0/1     CrashLoopBackOff   6

Two things are wrong here, and they may be unrelated. node01 is NotReady (a node problem: next lessons), and cart is crash looping. Check where cart runs before you assume anything:

kubectl -n shop get pod cart-7d9c6b5f4-k2x8p -o wide

If it runs on controlplane, the node problem is not its cause. Fix the task you were given first.

Example · From symptom to fix in five commands

Task: the cart Deployment in namespace shop never becomes available. Fix it.

kubectl -n shop get deploy,rs,pods -l app=cart
kubectl -n shop describe pod -l app=cart | sed -n '/State:/,/Ready:/p'
kubectl -n shop logs deploy/cart --previous
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1

FATAL: environment variable DB_HOST is not set

Hypothesis: the container needs DB_HOST. Look at what the Deployment gives it, then make one change on the Deployment (not on the Pod, which would be replaced):

kubectl -n shop get deploy cart -o jsonpath='{.spec.template.spec.containers[0].env}'; echo
kubectl -n shop get configmap
kubectl -n shop set env deploy/cart DB_HOST=postgres.shop.svc.cluster.local
kubectl -n shop rollout status deploy/cart
kubectl -n shop get pods -l app=cart        # 1/1 Running, restarts 0

The verification is the last line: every Pod 1/1 and not restarting.

Exit codes and states worth memorising

Container states and exit codes tell you which layer to look at before you read a single log line:

You seeIt usually meansLook at
PendingNo node was chosen, or the volume cannot be bounddescribe pod, events FailedScheduling; PVC status
ContainerCreating for a long timeThe node cannot start it: volume mount, Secret or ConfigMap missing, CNI problemdescribe pod events (FailedMount, FailedCreatePodSandBox)
ErrImagePull, ImagePullBackOffWrong image name or tag, private registry without credentialsdescribe pod events
CrashLoopBackOffThe container starts and exits, again and againlogs --previous, exit code, command and args
CreateContainerConfigErrorA referenced ConfigMap, Secret or key does not existdescribe pod
Running but 0/1The readiness probe failsdescribe pod (Readiness), the probe's port and path
Exit code 1 or 2The program reported an errorLogs
Exit code 126 / 127Command not executable / not foundcommand and args in the spec
Exit code 137Killed with SIGKILL: OOMKilled, or a liveness probe failuredescribe pod (Reason: OOMKilled), memory limit, probes
Exit code 143Stopped with SIGTERM, a normal shutdownUsually not the fault

Tricks

Common mistakes

  • Working in the wrong context. Each exam task names a cluster. A perfect fix in the wrong cluster scores nothing.
  • Fixing the Pod instead of its owner. Pods that belong to a Deployment, StatefulSet or DaemonSet are replaced. Edit the owner.
  • Changing several things at once. You may fix the fault and add a new one. One change, then verify.
  • Stopping at Running. Check READY, the restart count, and the endpoints of the Service in front.
  • Ignoring old evidence. kubectl logs without --previous shows the new, still-starting container, which often has nothing useful yet.
  • Leaving a backup in the manifests folder. kube-apiserver.yaml.bak in /etc/kubernetes/manifests is started as a second API server.
  • Spending twenty minutes on one task. Flag it, finish the others, and come back with fresh eyes.

Recap

  • Locate the layer first: application, networking, control plane or node. kubectl get nodes decides between the bottom two and the top two.
  • Read evidence in order: get, describe, events, logs, then the node with journalctl and crictl.
  • States and exit codes point at the layer before you read logs (137 is a kill, 127 a missing command).
  • Change one thing at a time, on the owner object, and back up files first.
  • Verify the symptom the task describes: Ready, endpoints, a real request.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Practise: try it on a real cluster

6 hands-on labs for this lesson. You get goals, not steps: any solution that reaches them passes.

  • Four workloads in one namespace are stuck, each in a different way. Read each one's state, find the cause with get, describe, events and logs, and fix it without throwing away what it needs.

    Fix · Level 2 · standard · target 20 min

  • Service names stopped resolving across the cluster, and in one namespace they still fail after that is fixed. Test layer by layer, repair cluster DNS, then open exactly the traffic a locked-down namespace needs for names.

    Fix · Level 2 · standard · target 20 min

  • A two-tier checkout fails end to end. Follow the request from the Service to the web pods, through their proxy to the API Service, its endpoints and its readiness probe, and fix each broken link on the way.

    Fix · Level 2 · standard · target 20 min

  • A cluster with three faults at once, one in a worker node, one in the control plane and one in cluster networking, picked at random for each session. Find them with the troubleshooting method, repair them, and ship a release through the repaired cluster.

    Fix · Level 3 · challenge · target 40 min

  • kubectl is refused and the API server keeps restarting. Read the container logs on the node with crictl, follow the API server's complaint to the component behind it, and repair two static Pod manifests without losing any data.

    Fix · Level 3 · challenge · target 25 min

  • Both workers of a kubeadm cluster went NotReady overnight, for different reasons. Walk each node from the bottom up with systemctl, journalctl and crictl, fix what you find, and make sure it survives a reboot.

    Fix · Level 3 · challenge · target 25 min

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.