CKA Troubleshooting Practice Labs

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.

High ROI Topics:
  1. CrashLoopBackOff troubleshooting
  2. Service/Endpoint troubleshooting
  3. Pending Pods and scheduler errors
  4. ETCD backup/restore

15 Minutes - Pod Troubleshooting Drills

Drill #1 - Pending Pod

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-pod
Expected:
STATUS: Pending

Fix It

Find the scheduling error.
kubectl describe pod pending-pod
Look for:
Insufficient cpu
untolerated taint
node affinity conflict
Correct the root cause and verify:
kubectl get pod -w

Drill #2 - CrashLoopBackOff

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 pods
Expected:
CrashLoopBackOff

Fix It

Investigate:
kubectl logs crash-pod
kubectl describe pod crash-pod
Fix by changing:
command: ["sh","-c","sleep 3600"]
Recreate the pod and verify:
kubectl get pods
Expected:
Running

Drill #3 - ImagePullBackOff

Break It

Apply:
apiVersion: v1
kind: Pod
metadata:
  name: image-pod
spec:
  containers:
  - name: nginx
    image: nginx:notreal
Check:
kubectl get pods
Expected:
ImagePullBackOff

Fix It

Investigate:
kubectl describe pod image-pod
Look for:
Failed to pull image
manifest unknown
Fix:
image: nginx
Delete and recreate. Verify:
kubectl get pods
Expected:
Running

15 Minutes - Deployment Drills

Drill #1 - Bad Image Recovery

Create deployment:
kubectl create deployment webapp --image=nginx --replicas=3
Break it:
kubectl set image deployment/webapp nginx=nginx:notreal
Observe:
kubectl rollout status deployment/webapp
kubectl get pods
Fix:
kubectl set image deployment/webapp nginx=nginx
or
kubectl rollout undo deployment/webapp

Drill #2 - Rollback

Create deployment:
kubectl create deployment webapp --image=nginx
Update image:
kubectl set image deployment/webapp nginx=nginx:1.24
kubectl set image deployment/webapp nginx=nginx:1.25
Check revision history:
kubectl rollout history deployment/webapp
Rollback:
kubectl rollout undo deployment/webapp
Verify:
kubectl describe deployment webapp

Drill #3 - Scale

Create deployment:
kubectl create deployment webapp --image=nginx
Scale:
kubectl scale deployment/webapp --replicas=5
Verify:
kubectl get deployment
kubectl get pods
Scale down:
kubectl scale deployment/webapp --replicas=2

Drill #4 - Expose

Create deployment:
kubectl create deployment webapp --image=nginx --replicas=3
Expose:
kubectl expose deployment webapp \
--port=80 \
--target-port=80
Verify:
kubectl get svc
kubectl describe svc webapp
Check endpoints:
kubectl get endpoints
If endpoints are empty:
kubectl describe svc webapp
kubectl get pods --show-labels
Verify selectors match labels.

15 Minutes - ETCD Backup and Restore

Memory Drill

Without notes, try typing the commands from memory.

Backup

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.key
Verify:
ETCDCTL_API=3 etcdctl snapshot status /opt/etcd-backup.db

Restore

ETCDCTL_API=3 etcdctl snapshot restore /opt/etcd-backup.db \
--data-dir=/var/lib/etcd-restore
Edit static pod:
sudo vi /etc/kubernetes/manifests/etcd.yaml
Find:
--data-dir=/var/lib/etcd
Change to:
--data-dir=/var/lib/etcd-restore
Also update the hostPath volume. Save. Wait for kubelet to restart ETCD. Verify:
kubectl get nodes
kubectl get pods -A

Rapid-Fire Commands Worth Memorizing

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

Exam Mindset

For nearly every troubleshooting question:

  1. kubectl get
  2. kubectl describe
  3. kubectl logs
  4. kubectl get events
  5. Fix the root cause
  6. Verify the resource becomes Healthy/Running

Remember: don't memorize outputs. Memorize the investigation flow.