Appendix B: Final Exam
Goal: You find and fix ten operational problems from across the book in 120 minutes, each with cause and proof, and grade yourself · Duration: 120 min · Prerequisite: Days 0–16
Rules
- Time: 120 minutes, set a timer. Each task counts 10 %.
- There is no certificate. Your own bar: from 70 % on, you know how to run a cluster.
- An examiner (a colleague, or you yourself without looking) runs the preparation. The tasks only describe the symptom or the assignment.
- Allowed:
--help,kubectl explain, kubernetes.io/docs, etcd.io/docs and your files under~/day2. Not allowed: this course during the exam. - A task only counts with the cause in one sentence and a proof command. If you just remove the symptom (deleting a PDB, quota or namespace, deleting the timer unit, approving CSRs without review), you get 0 %.
- The solutions are at the end. Read them only after the time is up.
Preparation
The examiner copies the blocks one after the other into a separate terminal.
mkdir -p ~/day2/pruefung && cd ~/day2/pruefung
kubectl create namespace pruefung
cat > fehler.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: {name: kasse, namespace: pruefung}
spec:
replicas: 2
selector: {matchLabels: {app: kasse}}
template:
metadata: {labels: {app: kasse}}
spec:
containers:
- name: kasse
image: traefik/whoami:v1.11
resources: {requests: {cpu: 10m, memory: 16Mi}, limits: {memory: 64Mi}}
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata: {name: kasse, namespace: pruefung}
spec:
maxUnavailable: 0
selector: {matchLabels: {app: kasse}}
---
apiVersion: apps/v1
kind: Deployment
metadata: {name: lager, namespace: pruefung}
spec:
replicas: 2
strategy: {rollingUpdate: {maxUnavailable: 0, maxSurge: 1}}
selector: {matchLabels: {app: lager}}
template:
metadata: {labels: {app: lager}}
spec:
containers:
- name: lager
image: traefik/whoami:v1.11
resources: {requests: {cpu: 10m, memory: 16Mi}, limits: {memory: 64Mi}}
readinessProbe: {httpGet: {path: /, port: 80}, periodSeconds: 2}
EOF
kubectl apply -f fehler.yaml
kubectl -n pruefung rollout status deploy/lager --timeout=120s
kubectl -n pruefung patch deploy lager --type=json \
-p='[{"op":"replace","path":"/spec/template/spec/containers/0/readinessProbe/httpGet/port","value":8080}]'kubectl create namespace pruefung-quota
kubectl -n pruefung-quota create quota klein --hard=requests.memory=64Mi,limits.memory=128Mi
cat > bericht.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: {name: bericht, namespace: pruefung-quota}
spec:
replicas: 2
selector: {matchLabels: {app: bericht}}
template:
metadata: {labels: {app: bericht}}
spec:
containers:
- name: bericht
image: traefik/whoami:v1.11
resources: {requests: {cpu: 10m, memory: 48Mi}, limits: {memory: 64Mi}}
EOF
kubectl apply -f bericht.yaml
kubectl create namespace pruefung-neu
cat > altlast.yaml <<'EOF'
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata: {name: web, namespace: demo}
spec:
scaleTargetRef: {apiVersion: apps/v1, kind: Deployment, name: web}
minReplicas: 3
maxReplicas: 6
metrics:
- type: Resource
resource: {name: cpu, target: {type: Utilization, averageUtilization: 80}}
---
apiVersion: flowcontrol.apiserver.k8s.io/v1beta3
kind: FlowSchema
metadata: {name: backup}
spec:
priorityLevelConfiguration: {name: workload-low}
matchingPrecedence: 1000
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: {name: shop, namespace: demo}
spec:
podSelector: {matchLabels: {app: shop}}
ingress: [{}]
EOF
clear# on cp2
sudo rm -f /var/lib/kubelet/pki/kubelet-server-*
sudo systemctl restart kubelet
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab >/dev/null
clear# on cp3
sudo systemctl disable --now etcd-snapshot.timer
sudo mv /etc/kubernetes/manifests/kube-vip.yaml /etc/kubernetes/kube-vip.yaml.pausiert
clearTask 1: The checkout (10 %)
Tomorrow all three nodes go into maintenance. Check beforehand
whether a drain will get stuck anywhere, and make sure it goes through
without kasse (checkout) ever going down completely.
Task 2: The warehouse (10 %)
The new version of lager (warehouse) in the namespace
pruefung does not arrive. The old Pods are still
running.
Task 3: The report (10 %)
bericht (report) in the namespace
pruefung-quota should run with two Pods. The quota stays as
it is.
Task 4: The legacy (10 %)
~/day2/pruefung/altlast.yaml contains manifests from an
old repository. Find all APIs that no longer exist in v1.37, correct the
file and prove that the API server accepts it. Do not
actually apply it.
Task 5: No logs from cp2 (10 %)
kubectl logs does not work for Pods on cp2, but it does
on the other nodes.
Task 6: The silent snapshot (10 %)
No etcd snapshot has been created on cp3 for hours. Make sure one is created every six hours again, and create one right away.
Task 7: The virtual address (10 %)
A colleague reports that during the next maintenance of cp1 and cp2, the API address 172.16.0.100 could disappear. Find out why, and fix it.
Task 8: Before the reboot (10 %)
Before the next kernel patch: something is lurking on one node that would prevent the kubelet from starting after the reboot. Find it and remove it without rebooting a node.
Task 9: Expiry dates (10 %)
For cp1, state on which day the first control plane certificate expires and how long the CAs are valid. Name the command you use to renew all certificates before they expire.
Task 10: The new namespace (10 %)
Teams are going to deploy into pruefung-neu from now on.
Every container without its own values should automatically request 10m
CPU and 32Mi memory and be limited to 128Mi memory. Prove it with a Pod
without values.
Solutions
Solution 1
kubectl get pdb -AExpected:
NAMESPACE NAME MIN AVAILABLE MAX UNAVAILABLE ALLOWED DISRUPTIONS AGE
demo shop 1 N/A 1 21h
demo web N/A 1 1 21h
kube-system coredns N/A 1 1 21h
pruefung kasse N/A 0 0 29s
Cause: With maxUnavailable: 0, the PDB
of kasse does not allow a single disruption. Every drain of
a node with a kasse Pod hangs.
kubectl -n pruefung patch pdb kasse --type=merge -p '{"spec":{"maxUnavailable":1}}'
kubectl -n pruefung get pdb kasseExpected:
poddisruptionbudget.policy/kasse patched
NAME MIN AVAILABLE MAX UNAVAILABLE ALLOWED DISRUPTIONS AGE
kasse N/A 1 1 30s
With two replicas, one Pod always remains.
minAvailable: 1 is equivalent.
Solution 2
kubectl -n pruefung rollout status deploy/lager --timeout=15s
kubectl -n pruefung get pods -l app=lager
P=$(kubectl -n pruefung get pods -l app=lager --sort-by=.metadata.creationTimestamp -o name | tail -1)
kubectl -n pruefung describe $P | grep 'Readiness probe failed' | tail -1 | cut -c1-120Expected:
Waiting for deployment "lager" rollout to finish: 1 out of 2 new replicas have been updated...
error: timed out waiting for the condition
NAME READY STATUS RESTARTS AGE
lager-55f8bd585b-2xvth 1/1 Running 0 45s
lager-55f8bd585b-sh8qn 1/1 Running 0 45s
lager-8558cc8d9b-2wthd 0/1 Running 0 41s
Warning Unhealthy 2s (x21 over 40s) kubelet spec.containers{lager}: Readiness pro
The full message reads
Readiness probe failed: Get "http://10.244.0.21:8080/": dial tcp ….
Cause: The readiness probe queries port 8080, whoami
listens on 80. Thanks to maxUnavailable: 0, the old Pods
keep running, and the rollout is stuck.
kubectl -n pruefung patch deploy lager --type=json \
-p='[{"op":"replace","path":"/spec/template/spec/containers/0/readinessProbe/httpGet/port","value":80}]'
kubectl -n pruefung rollout status deploy/lager --timeout=120s | tail -1Expected:
deployment.apps/lager patched
deployment "lager" successfully rolled out
Solution 3
kubectl -n pruefung-quota get deploy bericht
kubectl -n pruefung-quota describe quota klein | tail -3
kubectl -n pruefung-quota get deploy bericht \
-o jsonpath='{.status.conditions[?(@.type=="ReplicaFailure")].message}{"\n"}'Expected:
NAME READY UP-TO-DATE AVAILABLE AGE
bericht 1/2 1 1 42s
-------- ---- ----
limits.memory 64Mi 128Mi
requests.memory 48Mi 64Mi
pods "bericht-6997c44c6f-p675g" is forbidden: exceeded quota: klein, requested: requests.memory=48Mi, used: requests.memory=48Mi, limited: requests.memory=64Mi
Cause: Two Pods with a 48Mi request each need 96Mi, but the quota allows 64Mi. So lower it to 32Mi per Pod:
kubectl -n pruefung-quota set resources deploy/bericht --requests=memory=32Mi
kubectl -n pruefung-quota rollout status deploy/bericht --timeout=120s | tail -1
kubectl -n pruefung-quota get deploy berichtExpected:
deployment.apps/bericht resource requirements updated
error: timed out waiting for the condition
NAME READY UP-TO-DATE AVAILABLE AGE
bericht 1/2 0 1 2m43s
The rollout still hangs. The new Pod (32Mi) would have to be created next to the old one (48Mi), 80Mi together. Even with 16Mi per Pod it gets stuck, then on the limits: the old Pod’s 64Mi plus the new one’s 64Mi fill the 128Mi, and there is no room left for the next extra Pod:
kubectl -n pruefung-quota set resources deploy/bericht --requests=memory=16Mi
kubectl -n pruefung-quota rollout status deploy/bericht --timeout=120s | tail -1
kubectl -n pruefung-quota get deploy bericht
kubectl -n pruefung-quota describe quota klein | tail -2Expected:
deployment.apps/bericht resource requirements updated
error: timed out waiting for the condition
NAME READY UP-TO-DATE AVAILABLE AGE
bericht 2/2 1 2 5m2s
limits.memory 128Mi 128Mi
requests.memory 64Mi 64Mi
A rolling update needs room for the extra Pod
(maxSurge). If the quota is calculated without any
headroom, the rollout has to stop an old Pod first:
kubectl -n pruefung-quota patch deploy bericht --type=merge \
-p '{"spec":{"strategy":{"rollingUpdate":{"maxUnavailable":1,"maxSurge":0}}}}'
kubectl -n pruefung-quota rollout status deploy/bericht --timeout=120s | tail -1
kubectl -n pruefung-quota get deploy bericht
kubectl -n pruefung-quota describe quota klein | tail -2Expected:
deployment.apps/bericht patched
deployment "bericht" successfully rolled out
NAME READY UP-TO-DATE AVAILABLE AGE
bericht 2/2 2 2 7m11s
limits.memory 128Mi 128Mi
requests.memory 32Mi 64Mi
Full points for both: requests that fit the quota and a strategy without an extra Pod. If you only lower the requests, you get half.
Solution 4
cd ~/day2/pruefung
pluto detect-files -f altlast.yaml --target-versions k8s=v1.37.0Expected:
NAME KIND VERSION REPLACEMENT REMOVED DEPRECATED REPL AVAIL
web HorizontalPodAutoscaler autoscaling/v2beta2 autoscaling/v2 true true false
backup FlowSchema flowcontrol.apiserver.k8s.io/v1beta3 flowcontrol.apiserver.k8s.io/v1 true true false
Cause: autoscaling/v2beta2 has been
gone since v1.26, flowcontrol.apiserver.k8s.io/v1beta3
since v1.32. The NetworkPolicy is fine. Both replacement APIs take the
fields unchanged:
sed -i 's#autoscaling/v2beta2#autoscaling/v2#; s#flowcontrol.apiserver.k8s.io/v1beta3#flowcontrol.apiserver.k8s.io/v1#' \
altlast.yaml
pluto detect-files -f altlast.yaml --target-versions k8s=v1.37.0; echo "Exit: $?"
kubectl apply -f altlast.yaml --dry-run=serverExpected:
There were no resources found with known deprecated apiVersions.
Exit: 0
horizontalpodautoscaler.autoscaling/web created (server dry run)
flowschema.flowcontrol.apiserver.k8s.io/backup created (server dry run)
networkpolicy.networking.k8s.io/shop created (server dry run)
Before the correction, pluto ends with exit code 4 (Day 4).
Solution 5
P=$(kubectl -n kube-system get pod -l k8s-app=kube-proxy --field-selector spec.nodeName=cp2 -o name)
kubectl -n kube-system logs $P --tail=1 | cut -c1-120
kubectl get csr | grep -E 'NAME|Pending'Expected:
Error from server: Get "https://172.16.0.228:10250/containerLogs/kube-system/kube-proxy-m9jnq/k
NAME AGE SIGNERNAME REQUESTOR REQUESTEDDURATION CONDITION
csr-2t845 7m24s kubernetes.io/kubelet-serving system:node:cp2 <none> Pending
Cause: The kubelet on cp2 has no serving certificate; its request is waiting for approval.
kubectl get csr csr-2t845 -o jsonpath='{.spec.request}' | base64 -d | openssl req -noout -text \
| grep DNS:
kubectl certificate approve csr-2t845
kubectl -n kube-system logs $P --tail=1 | cut -c1-60Expected:
DNS:cp2, IP Address:172.16.0.228
certificatesigningrequest.certificates.k8s.io/csr-2t845 approved
I1122 17:09:20.473004 1 shared_informer.go:510] "Cache
Without checking the names, you only get half.
Solution 6
# on cp3
systemctl is-enabled etcd-snapshot.timer
systemctl is-active etcd-snapshot.timer
sudo ls -t /var/backups/k8s/etcd/ | head -1Expected:
disabled
inactive
etcd-20261122-1627.db
Cause: The timer is disabled. Enabling it is enough.
Persistent=true catches up on the missed run right
away:
# on cp3
sudo systemctl enable --now etcd-snapshot.timer
sudo ls -t /var/backups/k8s/etcd/ | head -1
systemctl is-failed etcd-snapshot.serviceExpected:
Created symlink /etc/systemd/system/timers.target.wants/etcd-snapshot.timer → /etc/systemd/system/etcd-snapshot.timer.
etcd-20261122-1803.db
inactive
Solution 7
kubectl -n kube-system get pods -o wide | grep kube-vip | awk '{print $1, $3, $7}'Expected:
kube-vip-cp1 Running cp1
kube-vip-cp2 Running cp2
Cause: No kube-vip runs on cp3. If cp1 and cp2 drop out one after the other, nobody is left to take over the address. The manifest is still lying around from a paused maintenance:
# on cp3
ls /etc/kubernetes/manifests/
ls /etc/kubernetes/*.pausiert
sudo mv /etc/kubernetes/kube-vip.yaml.pausiert /etc/kubernetes/manifests/kube-vip.yamlExpected:
etcd.yaml
kube-apiserver.yaml
kube-controller-manager.yaml
kube-scheduler.yaml
/etc/kubernetes/kube-vip.yaml.pausiert
kubectl -n kube-system get pods -o wide | grep kube-vip | awk '{print $1, $3, $7}'Expected:
kube-vip-cp1 Running cp1
kube-vip-cp2 Running cp2
kube-vip-cp3 Running cp3
Solution 8
Check on every node; the hit is on cp2:
# on cp2
swapon --show
grep -n swap /etc/fstabExpected:
4:/swapfile none swap sw 0 0
Cause: A swap entry in /etc/fstab. Swap
is not active yet (swapon --show is empty), but it would be
after the reboot, and the kubelet would abort with
running with swap on is not supported (Day 16). The file
/swapfile does not even exist here, so the reboot would
also produce an error message while mounting.
# on cp2
sudo sed -i '\#^/swapfile #d' /etc/fstab
grep -c swap /etc/fstabExpected:
0
Solution 9
sudo kubeadm certs check-expiration | sed -n 4,6p
sudo kubeadm certs check-expiration | sed -n 17,20pExpected:
CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY EXTERNALLY MANAGED
admin.conf Nov 22, 2027 09:05 UTC 364d ca no
apiserver Nov 22, 2027 09:05 UTC 364d ca no
CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED
ca Nov 18, 2036 19:03 UTC 9y no
etcd-ca Nov 18, 2036 19:03 UTC 9y no
front-proxy-ca Nov 18, 2036 19:03 UTC 9y no
All certificates on cp1 expire on November 22, 2027:
they were renewed together on Days 9 and 10. The CAs are valid until
November 2036. Renew with sudo kubeadm certs renew all on
every control plane node, then restart the static Pods (Day 10). An
upgrade with kubeadm upgrade apply or node
renews them as well.
Solution 10
kubectl -n pruefung-neu run probe --image=busybox:1.37 --restart=Never -- sleep 3600
kubectl -n pruefung-neu get pod probe -o jsonpath='{.status.qosClass}{"\n"}'
kubectl -n pruefung-neu delete pod probe --nowExpected:
pod/probe created
BestEffort
pod "probe" deleted from pruefung-neu namespace
Cause: The namespace has no LimitRange, so Pods without values request nothing.
cat > limitrange.yaml <<'EOF'
apiVersion: v1
kind: LimitRange
metadata:
name: standard
namespace: pruefung-neu
spec:
limits:
- type: Container
defaultRequest:
cpu: 10m
memory: 32Mi
default:
memory: 128Mi
EOF
kubectl apply -f limitrange.yaml
kubectl -n pruefung-neu run probe --image=busybox:1.37 --restart=Never -- sleep 3600
kubectl -n pruefung-neu get pod probe -o jsonpath='{.spec.containers[0].resources}{"\n"}{.status.qosClass}{"\n"}'Expected:
limitrange/standard created
pod/probe created
{"limits":{"memory":"128Mi"},"requests":{"cpu":"10m","memory":"32Mi"}}
Burstable
Scoring
| Result | Assessment |
|---|---|
| 90–100 % | You can take responsibility for a self-managed cluster |
| 70–89 % | Operations-ready; close the gaps with the matching days |
| below 70 % | Repeat Days 3, 10, 11, 13 and 15, then try again |
Cleanup
kubectl delete namespace pruefung pruefung-quota pruefung-neuExpected:
namespace "pruefung" deleted
namespace "pruefung-quota" deleted
namespace "pruefung-neu" deleted
The corrections on cp2 and cp3 stay; they are the desired state.