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
Official competencies this lesson covers
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:
| Competency | Lesson in this section | Also covered in |
|---|---|---|
| Troubleshoot clusters and nodes | Worker node failure | Cluster maintenance, kubeadm |
| Troubleshoot cluster components | Control plane failure | Cluster architecture, static Pods |
| Monitor cluster and application resource usage | (this lesson, plus the next ones) | Monitor cluster components |
| Manage and evaluate container output streams | Application failure, kubectl debug | Managing application logs |
| Troubleshoot services and networking | Network troubleshooting | DNS, CoreDNS, Services, Network policies |
Four layers
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:
| Layer | What lives there | Typical symptoms |
|---|---|---|
| Application | Pods, Deployments, Services, ConfigMaps, Secrets, PVCs, probes | CrashLoopBackOff, ImagePullBackOff, Pending, 0/1 Ready, a Service that answers nothing |
| Networking | CoreDNS, kube-proxy, the CNI plugin, NetworkPolicies | Name lookups fail, Services time out, Pods on different nodes cannot talk |
| Control plane | kube-apiserver, etcd, kube-scheduler, kube-controller-manager | kubectl hangs or is refused, new Pods stay Pending, Deployments do not create Pods |
| Nodes | kubelet, container runtime (containerd), the OS, certificates, disk | Node 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
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
- Symptom. Write down, in one sentence, what fails and how you will know it is fixed. "Requests to
http://web.shoptime out from inside the cluster" is a symptom. "Networking is broken" is not. - Evidence. Collect before you change. Most faults announce themselves in a status, an event or a log line.
- Hypothesis. One cause that explains all the evidence. If it explains only part of it, keep looking.
- 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.
- Verify. Check the symptom itself, not the command you just ran.
deployment.apps/web editedproves nothing.
Where the evidence lives
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?
| Tool | Question it answers | Notes |
|---|---|---|
kubectl get <kind> -o wide | What 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 events | What 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 yaml | What exactly is configured? | Compare with what the task asks for |
journalctl -u kubelet, crictl ps -a, crictl logs | What 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 see | It usually means | Look at |
|---|---|---|
Pending | No node was chosen, or the volume cannot be bound | describe pod, events FailedScheduling; PVC status |
ContainerCreating for a long time | The node cannot start it: volume mount, Secret or ConfigMap missing, CNI problem | describe pod events (FailedMount, FailedCreatePodSandBox) |
ErrImagePull, ImagePullBackOff | Wrong image name or tag, private registry without credentials | describe pod events |
CrashLoopBackOff | The container starts and exits, again and again | logs --previous, exit code, command and args |
CreateContainerConfigError | A referenced ConfigMap, Secret or key does not exist | describe pod |
Running but 0/1 | The readiness probe fails | describe pod (Readiness), the probe's port and path |
Exit code 1 or 2 | The program reported an error | Logs |
Exit code 126 / 127 | Command not executable / not found | command and args in the spec |
Exit code 137 | Killed with SIGKILL: OOMKilled, or a liveness probe failure | describe pod (Reason: OOMKilled), memory limit, probes |
Exit code 143 | Stopped with SIGTERM, a normal shutdown | Usually 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. CheckREADY, the restart count, and the endpoints of the Service in front. - Ignoring old evidence.
kubectl logswithout--previousshows the new, still-starting container, which often has nothing useful yet. - Leaving a backup in the manifests folder.
kube-apiserver.yaml.bakin/etc/kubernetes/manifestsis 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 nodesdecides between the bottom two and the top two. - Read evidence in order: get, describe, events, logs, then the node with
journalctlandcrictl. - States and exit codes point at the layer before you read logs (
137is a kill,127a 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.