Goal: Build muscle memory for the most common troubleshooting patterns you'll encounter on the CKA exam. Work through each drill from memory before looking at the solution.
Break It
kubectl run pending-pod \ --image=nginx \ --requests='cpu=100'If your lab doesn't have enough resources, increase CPU requests in the YAML. Check:
kubectl get pods kubectl describe pod pending-podExpected:
STATUS: Pending
Fix It
Find the scheduling error.kubectl describe pod pending-podLook for:
Insufficient cpu untolerated taint node affinity conflictCorrect the root cause and verify:
kubectl get pod -w
Break It
Apply:
apiVersion: v1
kind: Pod
metadata:
name: crash-pod
spec:
containers:
- name: app
image: busybox
command: ["sh","-c","exit 1"]
Check:
kubectl get podsExpected:
CrashLoopBackOff
Fix It
Investigate:kubectl logs crash-pod kubectl describe pod crash-podFix by changing:
command: ["sh","-c","sleep 3600"]Recreate the pod and verify:
kubectl get podsExpected:
Running
Break It
Apply:
apiVersion: v1
kind: Pod
metadata:
name: image-pod
spec:
containers:
- name: nginx
image: nginx:notreal
Check:
kubectl get podsExpected:
ImagePullBackOff
Fix It
Investigate:kubectl describe pod image-podLook for:
Failed to pull image manifest unknownFix:
image: nginxDelete and recreate. Verify:
kubectl get podsExpected:
Running
kubectl create deployment webapp --image=nginx --replicas=3Break it:
kubectl set image deployment/webapp nginx=nginx:notrealObserve:
kubectl rollout status deployment/webapp kubectl get podsFix:
kubectl set image deployment/webapp nginx=nginxor
kubectl rollout undo deployment/webapp
kubectl create deployment webapp --image=nginxUpdate image:
kubectl set image deployment/webapp nginx=nginx:1.24 kubectl set image deployment/webapp nginx=nginx:1.25Check revision history:
kubectl rollout history deployment/webappRollback:
kubectl rollout undo deployment/webappVerify:
kubectl describe deployment webapp
kubectl create deployment webapp --image=nginxScale:
kubectl scale deployment/webapp --replicas=5Verify:
kubectl get deployment kubectl get podsScale down:
kubectl scale deployment/webapp --replicas=2
kubectl create deployment webapp --image=nginx --replicas=3Expose:
kubectl expose deployment webapp \ --port=80 \ --target-port=80Verify:
kubectl get svc kubectl describe svc webappCheck endpoints:
kubectl get endpointsIf endpoints are empty:
kubectl describe svc webapp kubectl get pods --show-labelsVerify selectors match labels.
ETCDCTL_API=3 etcdctl snapshot save /opt/etcd-backup.db \ --endpoints=https://127.0.0.1:2379 \ --cacert=/etc/kubernetes/pki/etcd/ca.crt \ --cert=/etc/kubernetes/pki/etcd/server.crt \ --key=/etc/kubernetes/pki/etcd/server.keyVerify:
ETCDCTL_API=3 etcdctl snapshot status /opt/etcd-backup.db
ETCDCTL_API=3 etcdctl snapshot restore /opt/etcd-backup.db \ --data-dir=/var/lib/etcd-restoreEdit static pod:
sudo vi /etc/kubernetes/manifests/etcd.yamlFind:
--data-dir=/var/lib/etcdChange to:
--data-dir=/var/lib/etcd-restoreAlso update the hostPath volume. Save. Wait for kubelet to restart ETCD. Verify:
kubectl get nodes kubectl get pods -A
kubectl describe pod PODNAME kubectl logs PODNAME kubectl logs PODNAME --previous kubectl get events --sort-by='.lastTimestamp' kubectl rollout undo deployment/NAME kubectl rollout history deployment/NAME kubectl get endpoints kubectl describe svc NAME kubectl get pods --show-labels kubectl get pod -o wide kubectl explain pod.spec.containers kubectl explain pod.spec.containers --recursive
For nearly every troubleshooting question:
Remember: don't memorize outputs. Memorize the investigation flow.