Skip to content
Kubernetes tools · Chapter 19 of 20 Appendix B: Final Exam

Appendix B: Final Exam

Goal: You answer twenty questions and solve ten tasks across the whole book, incidents and assignments, each with the right tool and a proof, and grade yourself · Duration: 120 min · Prerequisite: Days 0–15

Rules of the Game

  • Time: 120 minutes, set a timer. Recommendation: 20 minutes for Part A, 100 minutes for Part B.
  • Points: Part A 20 questions at 1 point each, Part B 10 tasks at 8 points each, 100 in total.
  • There is no certificate. Your own benchmark: from 70 points, you pick the right tool in everyday work and operate it confidently.
  • You answer Part A in writing, without a cluster and without the book. One sentence per question is enough.
  • In Part B, before an incident, an examiner (a colleague or you yourself, without looking) runs its preparation, like the referee in the competition (Day 15). The task only describes the symptom or the assignment.
  • Allowed: --help, kubectl explain, the tools’ documentation. Not allowed: this course during the exam.
  • An incident only counts with the cause in one sentence (3 points), the fix of the cause (3 points) and a proof command (2 points). An assignment counts with the implementation (6 points) and the proof (2 points). Whoever deletes a policy instead of correcting it, grants a binding with cluster-admin or rebuilds the cluster gets 0 points for the task.
  • All commands run on the lab VM, in the lab as it stands after Day 15. The solutions are at the end. Read them only after the time is up.

Preparation

Once before Part B: a working directory and the state of the lab. The lines are the scoring from Day 15.

mkdir -p ~/werkzeuge/pruefung && cd ~/werkzeuge/pruefung
echo "Kasse-Neustarts: $(kubectl -n laden get pods -l app=kasse -o jsonpath='{.items[*].status.containerStatuses[0].restartCount}')"
echo "Web: $(kubectl -n laden exec werkbank -- wget -qO- -T3 http://web/ | grep -o '<title>.*</title>')"
echo "Cache: $(kubectl -n laden exec netshoot -- sh -c "printf 'PING\r\n' | nc -w2 cache 6379" | tr -d '\r')"
echo "Lager liest kube-system-Secrets: $(kubectl auth can-i get secrets -n kube-system --as=system:serviceaccount:lager:default)"
echo "Headlamp-Admin-Bindung: $(kubectl get clusterrolebinding headlamp-admin --ignore-not-found -o name | wc -l)"
echo "Headlamp-Replikas: $(kubectl -n headlamp get deploy headlamp -o jsonpath={.status.readyReplicas})"

Expected:

Kasse-Neustarts: 0 0
Web: <title>Welcome to nginx!</title>
Cache: +PONG
Lager liest kube-system-Secrets: no
Headlamp-Admin-Bindung: 0
Headlamp-Replikas: 2

For Task 3 you need Hubble. If cilium hubble port-forward from Day 8 is no longer running, start it in a separate terminal.

Part A: Questions (20 Points)

  1. Why can kubectl wait --for=condition=Available deploy/web return before all new Pods are ready, and what do you use instead?
  2. What can field selectors (--field-selector) do, and where is their limit?
  3. A JSONPath filter ?(@.spec.containers[0].securityContext.privileged==true) reports no match. Why does that not mean that no container runs privileged?
  4. Why does the API server reject a kubectl patch --type=merge that is supposed to give a container an environment variable with containers[0].image: Required value?
  5. Two teams apply the same ConfigMap with kubectl apply --server-side and different --field-managers. What happens when the second team changes a value that belongs to the first?
  6. You have two terminals open and want to work with the lab in one and with a test cluster in the other. Why is kubectx a trap for this, and which tool is built for it?
  7. What must the file be called for kubectl view-secret to work, and what does Krew check when installing a plugin, and what not?
  8. How do you make k9s safe for production access, and how do you recognize it at the top left?
  9. What has to be changed in the Headlamp Helm chart before using it in a real cluster, and why?
  10. How many terminated containers does the kubelet keep per Pod container, and where are the exit code and reason when the logs are already gone?
  11. Why is stern … --include ERROR a bad first filter for an unknown incident?
  12. curl reports Connection refused once and a timeout (exit 28) another time. What does each mean, and which cause is typical for a timeout in the cluster?
  13. hubble observe … --last 1 returns two lines. Why?
  14. Popeye reports “0 SCANNED” with 100 % for a section. What does that mean?
  15. Why do you always pass -t k8s=<version> to Pluto?
  16. Why does kubeconform belong in front of kube-linter, and why with -strict?
  17. Kubescape shows “Action Required” (skipped in the JSON report) with 0 resources for two kubelet controls. Did you pass?
  18. What happens to previously set values with helm upgrade … --set replicaCount=2 without --reuse-values, and how do you prevent this permanently?
  19. In a Flux-managed namespace, you have to set a Deployment to zero replicas for one hour. Which commands, in which order?
  20. Why does a kubectl plugin in Go use cli-runtime, and which exit codes does kubectl ohnelimits have?

Part B: Tasks (80 Points)

Task 1: The Checkout Again (8 Points)

Examiner:

kubectl -n laden patch deploy kasse --type=json -p '[{"op":"remove","path":"/spec/template/spec/containers/0/volumeMounts"},{"op":"remove","path":"/spec/template/spec/volumes"}]' >/dev/null
kubectl -n laden rollout status deploy/kasse --timeout=90s >/dev/null
sleep 70
clear

The night shift reports: “The checkout restarted several times today.” Deliver with one command, for each checkout Pod (kasse), the number of restarts, the exit code and the end time of the last container. Then find the cause and fix it without losing the requests and limits from Day 9.

Task 2: Restart for the Colleague (8 Points)

Task, no preparation: the user kollege (colleague) should be allowed to restart the Deployment packer in the namespace lager (warehouse) with kubectl rollout restart, and otherwise as little as possible. Proof: the restart works with --as=kollege, patch on Deployments in laden (shop) and delete on Pods in laden do not.

Task 3: The Checkout Gets No Prices (8 Points)

Examiner:

kubectl apply -f ~/werkzeuge/tag08/api-policy.yaml >/dev/null
clear

(If you already added the checkout to the file after the Challenge of Day 8, this command changes nothing, and the task counts as solved.)

The checkout team reports: “Since just now, we no longer get any prices from the api.”

kubectl -n laden exec deploy/kasse -- wget -qO- -T3 http://api:8080/ | head -1

The call aborts after three seconds. Use Hubble to find who drops, and fix the cause so that it does not come back with the next kubectl apply. netshoot must still not be able to reach the api.

Task 4: Old Manifests (8 Points)

Examiner:

cd ~/werkzeuge/pruefung && mkdir -p alt
cat > alt/pdb.yaml <<'EOF'
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: web
  namespace: laden
spec:
  minAvailable: 2
  selector:
    matchLabels: {app: web}
EOF
cat > alt/hpa.yaml <<'EOF'
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: web
  namespace: laden
spec:
  scaleTargetRef: {apiVersion: apps/v1, kind: Deployment, name: web}
  minReplicas: 3
  maxReplicas: 6
  metrics:
  - type: Resource
    resource: {name: cpu, target: {type: Utilization, averageUtilization: 70}}
EOF
cat > alt/ingress.yaml <<'EOF'
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web
  namespace: laden
spec:
  rules:
  - host: laden.example
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service: {name: web, port: {number: 80}}
EOF
clear

Task: A colleague wants to move the folder ~/werkzeuge/pruefung/alt into a cluster with Kubernetes 1.37. Check with a pipeline-ready command what no longer works there, fix the files, and prove with the API server that all three would be accepted, without creating anything.

Task 5: The New Deployment (8 Points)

Examiner:

mkdir -p ~/werkzeuge/pruefung/manifeste && cd ~/werkzeuge/pruefung
cat > manifeste/neu.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: lieferung
  namespace: laden
spec:
  replica: 2
  selector:
    matchLabels: {app: lieferung}
  template:
    metadata:
      labels: {app: lieferung}
    spec:
      containers:
      - name: lieferung
        image: nginx:latest
        ports:
        - containerPort: "80"
EOF
clear

Task: A colleague wrote manifeste/neu.yaml and says: “kube-linter does not complain, so it is fine.” Find all errors that violate the schema before the file sees a cluster, explain in one sentence why kube-linter stays silent, and fix the file. Proof: kubeconform in strict mode without errors. Do not apply it; a lieferung (delivery) is already running in the shop.

Task 6: The Checkout Has Too Many Permissions (8 Points)

Task, no preparation: on Day 11, Trivy, Kubescape and rbac-tool all flagged the same binding: kasse-edit from Day 6. Replace it with a Role that lets the ServiceAccount kasse read, restart and scale Deployments in the namespace laden, but not read Secrets and not create ephemeral containers. Proof with kubectl auth can-i and rbac-tool.

Task 7: Headlamp Back to One Replica (8 Points)

Task, no preparation: Headlamp should run with one replica again. Show before the upgrade that only the replicas change, and make sure that the values are not again only on a command line. Proof: the admin binding headlamp-admin still does not exist, and one replica is running.

Task 8: Ready for Pod Security (8 Points)

Task, no preparation: the namespace laden is to enforce the Pod Security level baseline in the future. Find out which running Pods violate it today and why, and make the namespace ready without switching the level on yet. Proof: a dry run of the label no longer reports violations for laden.

Task 9: Read Access for Support (8 Points)

Task, no preparation: a colleague from support needs read access to the cluster for one hour with the permissions of the ServiceAccount betrachter (viewer; namespace headlamp, Day 6), as a standalone file support.kubeconfig. Your ~/.kube/config stays untouched. Proof: with the file, kubectl auth whoami reports the ServiceAccount, and Secrets in laden are forbidden.

Task 10: The Shop Is Gone (8 Points)

Examiner:

kind create cluster --name frisch >/dev/null 2>&1
clear

A minute later, you report it yourself: kubectl -n laden get deploy no longer shows a single Deployment. Find the cause and restore the previous state. At the end, no additional cluster and no additional context may be left over.

Solutions

Solutions Part A

  1. Available means minimum availability, which is often already met by the old Pods. For exact states --for=jsonpath='{.status.readyReplicas}'=4, for rollouts kubectl rollout status (Day 1).
  2. They filter on the API server, with every output form, but only on a few fields defined per resource; with Jobs, even status.phase fails (Day 1).
  3. The filter only checks the first container. A privileged sidecar in second place slips through; “any container” works with jq and any() (Day 1).
  4. JSON Merge Patch knows no keys in lists and replaces the whole container list with one container without an image; strategic merge merges by name (Day 2).
  5. The second apply fails with a conflict; taking over only works explicitly with --force-conflicts (Day 2).
  6. kubectx changes the shared ~/.kube/config, so a switch applies immediately in all terminals. kubie gives each shell its own kubeconfig (Day 3).
  7. kubectl-view_secret in the PATH. Krew checks the origin and checksums of the downloads, not what the plugin does (Day 4).
  8. k9s --readonly (or readOnly in the context configuration) and a user with few permissions. The top left shows [R] instead of [RW] (Day 5).
  9. Set clusterRoleBinding.create=false. Otherwise the chart binds its ServiceAccount to cluster-admin, and whoever has its token has all permissions (Day 6).
  10. Exactly one. Exit code and reason are in the Pod status under state.terminated or lastState.terminated, as long as the Pod exists (Day 7).
  11. The actual cause may come from the shell and has neither a timestamp nor a level. First exclude what you know (--exclude INFO) instead of including what you expect (Day 7).
  12. Refused: target reached, nothing listening on the port. Timeout: packets get lost, typically a NetworkPolicy that drops in the cluster (Day 8).
  13. --last applies per node, and the target Pods run on different nodes (Day 8).
  14. The tool has not checked, not passed; with -n laden, for example, Popeye does not count policies and RoleBindings at all (Day 9).
  15. Without a target version, Pluto compares with a built-in older version and reports removed APIs as merely deprecated (REMOVED false) (Day 9).
  16. kube-linter skips files that are not a valid object and still exits with 0. Without -strict, the schema allows unknown fields, and typos like replica: disappear silently (Day 10).
  17. No. The checks need the Kubescape operator in the cluster; “Action Required” means not checked, which is why the scan coverage is below 100 % (Day 11).
  18. They get lost; with the Headlamp chart, the admin binding comes back. Permanently: all values in a file (-f) in the repo and helm diff upgrade beforehand (Days 12, 15).
  19. flux suspend kustomization <name>, kubectl -n <ns> scale deploy <app> --replicas=0, maintenance, flux resume kustomization <name>, flux get kustomizations (Day 12).
  20. So that --context, -n, --as and the kubeconfig resolution work exactly as in kubectl. 0 = everything set, 1 = hits, 2 = error (Day 14).

Solution 1

The single command comes from the Challenge of Day 7:

kubectl -n laden get pods -l app=kasse -o custom-columns='POD:.metadata.name,NEUSTARTS:.status.containerStatuses[0].restartCount,EXIT:.status.containerStatuses[0].lastState.terminated.exitCode,ENDE:.status.containerStatuses[0].lastState.terminated.finishedAt'

Expected (names and times will differ):

POD                     NEUSTARTS   EXIT   ENDE
kasse-f59678576-7tb4q   2           3      2026-11-24T14:54:36Z
kasse-f59678576-sgsww   2           3      2026-11-24T14:54:31Z

Exit code 3 is the exit 3 from the checkout’s script. The cause is in the log, but not in a line with ERROR:

stern -n laden kasse --since 2m --no-follow --exclude INFO 2>/dev/null | grep -v WARN | head -4

Expected (names and times will differ, as on Day 15, Round 1):

kasse-f59678576-9zhrl kasse sh: can't create /daten/abschluss.log: nonexistent directory
kasse-f59678576-9zhrl kasse 2026-11-24T14:34:02+00:00 ERROR tagesabschluss fehlgeschlagen

Cause: the volume daten is missing from the Deployment, and the end-of-day closing does not find /daten. Add it back, with the patch from Day 7:

kubectl -n laden patch deploy kasse --type=strategic -p '{"spec":{"template":{"spec":{"volumes":[{"name":"daten","emptyDir":{}}],"containers":[{"name":"kasse","volumeMounts":[{"name":"daten","mountPath":"/daten"}]}]}}}}'
kubectl -n laden rollout status deploy/kasse --timeout=90s

Proof after 40 seconds:

kubectl -n laden get pods -l app=kasse
stern -n laden kasse --since 35s --no-follow --include "tagesabschluss|ERROR" 2>/dev/null
kubectl -n laden get deploy kasse -o jsonpath='{.spec.template.spec.containers[0].resources.requests.cpu}{"\n"}'

Expected (names and times will differ):

NAME                    READY   STATUS    RESTARTS   AGE
kasse-866c4ff85-6xrx5   1/1     Running   0          49s
kasse-866c4ff85-w9hvx   1/1     Running   0          45s
kasse-866c4ff85-6xrx5 kasse 2026-11-24T14:55:26+00:00 INFO tagesabschluss nach /daten/abschluss.log
kasse-866c4ff85-w9hvx kasse 2026-11-24T14:55:30+00:00 INFO tagesabschluss nach /daten/abschluss.log
15m

No restarts, no ERROR, and the requests from Day 9 are still there.

kubectl apply -f ~/werkzeuge/tag07/kasse.yaml is not a solution: the file has neither the volume nor the requests from Day 9 (Day 10, Drill 1), and the checkout keeps crashing.

Solution 2

The solution of the Challenge of Day 2. rollout restart reads the Deployment and sets an annotation in the Pod template; it needs get and patch on deployments, no permission on Pods:

kubectl -n lager create role neustart-deploy --verb=get,patch --resource=deployments
kubectl -n lager create rolebinding kollege-neustart-deploy --role=neustart-deploy --user=kollege
kubectl -n lager rollout restart deploy/packer --as=kollege
for v in "patch deployments -n lager" "patch deployments -n laden" "delete pods -n laden"; do echo "$v: $(kubectl auth can-i $v --as=kollege)"; done
kubectl -n lager rollout status deploy/packer --timeout=60s | tail -1

Expected:

role.rbac.authorization.k8s.io/neustart-deploy created
rolebinding.rbac.authorization.k8s.io/kollege-neustart-deploy created
deployment.apps/packer restarted
patch deployments -n lager: yes
patch deployments -n laden: no
delete pods -n laden: no
deployment "packer" successfully rolled out

Full points only with the sentence that patch may also change the image; RBAC has no finer level. Whoever grants delete on Pods has missed the goal: rollout restart does not delete any Pods. Clean up:

kubectl -n lager delete role neustart-deploy
kubectl -n lager delete rolebinding kollege-neustart-deploy

Solution 3

hubble observe -n laden --verdict DROPPED --last 3
kubectl -n laden get netpol api-nur-von-web -o jsonpath='{.spec.ingress[0].from}{"\n"}'

Expected (names, times and IDs will differ):

Nov 24 14:56:06.112: laden/kasse-866c4ff85-6xrx5:51650 (ID:1132) <> laden/api-7d5f77c79b-725kc:8080 (ID:9654) Policy denied DROPPED (TCP Flags: SYN)
Nov 24 14:56:07.133: laden/kasse-866c4ff85-6xrx5:51650 (ID:1132) <> laden/api-7d5f77c79b-725kc:8080 (ID:9654) policy-verdict:none INGRESS DENIED (TCP Flags: SYN)
Nov 24 14:56:07.133: laden/kasse-866c4ff85-6xrx5:51650 (ID:1132) <> laden/api-7d5f77c79b-725kc:8080 (ID:9654) Policy denied DROPPED (TCP Flags: SYN)
[{"podSelector":{"matchLabels":{"app":"web"}}}]

Under from, only the entry for app: web remains.

Cause: the permission for the checkout reached the cluster on Day 8 via kubectl patch, never the file. The kubectl apply of the old api-policy.yaml removed it again; the Challenge of Day 8 warns about this. So the checkout belongs in the file:

cd ~/werkzeuge/tag08
cat > api-policy.yaml <<'EOF'
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: api-nur-von-web
  namespace: laden
spec:
  podSelector:
    matchLabels: {app: api}
  policyTypes: [Ingress]
  ingress:
  - from:
    - podSelector:
        matchLabels: {app: web}
    - podSelector:
        matchLabels: {app: kasse}
    ports:
    - port: 8080
EOF
kubectl apply -f api-policy.yaml

Proof, as in the Challenge of Day 8:

kubectl -n laden get netpol api-nur-von-web -o jsonpath='{.spec.ingress[0].from}{"\n"}'
kubectl -n laden exec deploy/kasse -- wget -qO- -T3 http://api:8080/ | head -1
kubectl -n laden exec netshoot -- curl -s -m3 -o /dev/null -w "%{http_code}\n" http://api:8080/
hubble observe --from-label app=kasse --type policy-verdict --last 1 -o compact

Expected (names will differ):

[{"podSelector":{"matchLabels":{"app":"web"}}},{"podSelector":{"matchLabels":{"app":"kasse"}}}]
Hostname: api-7d5f77c79b-725kc
000
command terminated with exit code 28
Nov 24 14:56:17.562: laden/kasse-866c4ff85-6xrx5:59276 (ID:1132) -> laden/api-7d5f77c79b-725kc:8080 (ID:9654) policy-verdict:L3-L4 INGRESS ALLOWED (TCP Flags: SYN)

Two entries under from are an or. Whoever writes app: kasse into the same podSelector as app: web builds an and and locks both out. Whoever only patches the cluster again gets no points for the fix: the next apply brings the error back.

Solution 4

Pipeline-ready means: with a target version and exit code (Day 9, Drill 6):

cd ~/werkzeuge/pruefung
pluto detect-files -d alt -t k8s=v1.37.0
echo "exit $?"

Expected:

NAME   KIND                      VERSION               REPLACEMENT      REMOVED   DEPRECATED   REPL AVAIL
web    HorizontalPodAutoscaler   autoscaling/v2beta2   autoscaling/v2   true      true         false
web    PodDisruptionBudget       policy/v1beta1        policy/v1        true      true         true

exit 4

Cause: both API versions are removed in Kubernetes 1.37; the Ingress is clean. Without -t, Pluto would have reported the HPA as merely deprecated. The fields have not changed, so sed is enough:

sed -i 's#policy/v1beta1#policy/v1#' alt/pdb.yaml
sed -i 's#autoscaling/v2beta2#autoscaling/v2#' alt/hpa.yaml
pluto detect-files -d alt -t k8s=v1.37.0; echo "exit $?"
kubectl apply --dry-run=server -f alt/

Expected:

There were no resources found with known deprecated apiVersions.
exit 0
horizontalpodautoscaler.autoscaling/web created (server dry run)
ingress.networking.k8s.io/web created (server dry run)
poddisruptionbudget.policy/web created (server dry run)

Whoever applies without --dry-run=server creates an HPA and a PDB in the shop: 2 points deducted, and delete them again.

Solution 5

Schema first, in strict mode (Day 10, Drill 2):

cd ~/werkzeuge/pruefung
kubeconform -strict -summary manifeste/neu.yaml
kube-linter lint manifeste/neu.yaml; echo "exit $?"

Expected (the first line shortened):

manifeste/neu.yaml - Deployment lieferung is invalid: … - at '/spec/template/spec/containers/0/ports/0/containerPort': got string, want integer - at '/spec': additional properties 'replica' not allowed
Summary: 1 resource found in 1 file - Valid: 0, Invalid: 1, Errors: 0, Skipped: 0
Warning: no valid objects found.
exit 0

Cause: two errors. containerPort: "80" is a string instead of a number, and replica: is a typo for replicas: that only -strict finds; without it, the Deployment would silently run with one replica. kube-linter stays silent because it does not even read the invalid file, and still reports success.

sed -i 's/containerPort: "80"/containerPort: 80/; s/replica: 2/replicas: 2/' manifeste/neu.yaml
kubeconform -strict -summary manifeste/neu.yaml

Expected:

Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0

Whoever also names nginx:latest (kube-linter latest-tag, Polaris tagNotSpecified) gets no extra point, but the answer is right: that is a rule, not a schema error.

Solution 6

First look at what the binding allows (Day 11, Drill 6):

rbac-tool policy-rules -e "kasse" | grep -E "secrets|pods/exec" | head -4

Expected: the lines from Day 11 with ClusterRoles>>edit, among them create on secrets and pods/exec. The Challenge of Day 6 names the replacement: a custom Role with get, list, patch on deployments and deployments/scale.

kubectl -n laden delete rolebinding kasse-edit
kubectl -n laden create role kasse-deploy --verb=get,list,patch --resource=deployments,deployments/scale
kubectl -n laden create rolebinding kasse-deploy --role=kasse-deploy --serviceaccount=laden:kasse
SA=system:serviceaccount:laden:kasse
kubectl auth can-i patch deployments -n laden --as=$SA
kubectl auth can-i patch deployments -n lager --as=$SA
kubectl auth can-i get secrets -n laden --as=$SA
kubectl auth can-i patch pods/ephemeralcontainers -n laden --as=$SA
kubectl auth can-i patch deployments/scale -n laden --as=$SA
rbac-tool who-can get secrets | grep -c kasse
kubectl -n laden scale deploy kasse --replicas=2 --as=$SA
kubectl -n laden rollout restart deploy/kasse --as=$SA

Expected:

rolebinding.rbac.authorization.k8s.io "kasse-edit" deleted from laden namespace
role.rbac.authorization.k8s.io/kasse-deploy created
rolebinding.rbac.authorization.k8s.io/kasse-deploy created
yes
no
no
no
yes
0
deployment.apps/kasse scaled
deployment.apps/kasse restarted

rbac-tool who-can get secrets no longer names kasse (grep -c counts 0), and scaling and restarting work with the checkout’s permissions.

rollout restart needs get and patch (Day 2), kubectl scale the subresource deployments/scale. Whoever only deletes kasse-edit and creates no new Role loses 3 points: the team can then do nothing at all.

Solution 7

Since Day 15, Round 5, the values are in headlamp-values.yaml. Change them there, then the diff:

cd ~/werkzeuge/tag15
sed -i "s/replicaCount: 2/replicaCount: 1/" headlamp-values.yaml
cat headlamp-values.yaml
helm diff upgrade headlamp headlamp/headlamp -n headlamp --version 0.46.0 -f headlamp-values.yaml | grep -E "^headlamp,"

Expected:

replicaCount: 1
clusterRoleBinding:
  create: false
headlamp, headlamp, Deployment (apps) has changed:

Exactly one changed object, the Deployment, and no line ClusterRoleBinding … has been added. Then the upgrade with the same file and the proof:

helm upgrade headlamp headlamp/headlamp -n headlamp --version 0.46.0 -f headlamp-values.yaml | grep REVISION
kubectl get clusterrolebinding headlamp-admin
kubectl -n headlamp get deploy headlamp -o jsonpath='{.status.readyReplicas}{"\n"}'

Expected (the revision is one higher than after Day 15):

REVISION: 7
Error from server (NotFound): clusterrolebindings.rbac.authorization.k8s.io "headlamp-admin" not found
1

0 points for helm upgrade … --set replicaCount=1 without a file and without --reuse-values: that is exactly the mistake from Day 15.

Solution 8

First ask who violates it, with a dry run on the server (Day 15, Challenge):

kubectl label --dry-run=server --overwrite ns laden pod-security.kubernetes.io/enforce=baseline

Expected (names will differ, the order of the lines can change):

namespace/laden labeled (server dry run)
Warning: existing pods in namespace "laden" violate the new PodSecurity enforce level "baseline:latest"
Warning: api-7d5f77c79b-725kc (and 1 other pod): non-default capabilities

Who is behind it? The ephemeral containers from Day 7 and Day 8 (Day 7, Drill 4):

A=$(kubectl -n laden get pods -l app=api -o jsonpath='{.items[0].metadata.name}')
kubectl -n laden get pod $A -o jsonpath='{range .spec.ephemeralContainers[*]}{.name} {.image} {.targetContainerName}{"\n"}{end}'

Expected (the name will differ):

debugger-m8snk busybox:1.37.0 whoami

Correspondingly, the affected web Pod contains the sniffer with --profile=netadmin.

Cause: debug containers cannot be removed and carry additional capabilities; they make a Pod less secure after the fact. Only a new Pod is clean again:

kubectl -n laden rollout restart deploy/api deploy/web
kubectl -n laden rollout status deploy/web deploy/api --timeout=180s | tail -2
kubectl label --dry-run=server --overwrite ns laden pod-security.kubernetes.io/enforce=baseline

Expected:

deployment.apps/api restarted
deployment.apps/web restarted
deployment "web" successfully rolled out
deployment "api" successfully rolled out
namespace/laden labeled (server dry run)

Happened during testing: Right after the rollout, the dry run still reported Warning: web-67649cfddb-6d48k: non-default capabilities. That was the old Pod with the sniffer, which was just being terminated. Half a minute later, it was gone, and so was the warning. Check beforehand with kubectl -n laden get pods -l app=web that only new Pods are running.

Whoever sets the label without --dry-run=server has not fulfilled the task (“do not switch it on”). For the transition, pod-security.kubernetes.io/warn reports violations without rejecting anything.

Solution 9

The technique from the Challenge of Day 3 and Drill 2 of Day 6, with a token for one hour:

cd ~/werkzeuge/pruefung
SERVER=$(kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}')
kubectl config view --minify --raw -o jsonpath='{.clusters[0].cluster.certificate-authority-data}' | base64 -d > ca.crt
TOKEN=$(kubectl -n headlamp create token betrachter --duration=1h)
export KUBECONFIG=support.kubeconfig
kubectl config set-cluster werkzeuge --server=$SERVER --certificate-authority=ca.crt --embed-certs=true
kubectl config set-credentials betrachter --token=$TOKEN
kubectl config set-context betrachter@werkzeuge --cluster=werkzeuge --user=betrachter
kubectl config use-context betrachter@werkzeuge
kubectl auth whoami -o jsonpath='{.status.userInfo.username}{"\n"}'
kubectl auth can-i get secrets -n laden
unset KUBECONFIG
rm ca.crt
kubectx -c

Expected:

Cluster "werkzeuge" set.
User "betrachter" set.
Context "betrachter@werkzeuge" created.
Switched to context "betrachter@werkzeuge".
system:serviceaccount:headlamp:betrachter
no
kind-werkzeuge

The last line shows: your own kubeconfig is unchanged. --embed-certs makes the file standalone. Full points only with --duration=1h and the note that the file is a key to the cluster until it expires and is deleted afterwards (rm -f support.kubeconfig).

Solution 10

kubectl config current-context
kind get clusters

Expected:

kind-frisch
frisch
werkzeuge

Cause: kind create cluster switched the context to the new, empty cluster kind-frisch (fresh) without asking (Day 0, Day 13). The shop is not gone; you are looking into the wrong cluster. Throw it away and switch back:

kind delete cluster --name frisch
kubectl config use-context kind-werkzeuge
kind get clusters
kubectl -n laden get deploy

Expected (excerpt):

Deleting cluster "frisch" ...
Deleted nodes: ["frisch-control-plane"]
Switched to context "kind-werkzeuge".
werkzeuge

Afterwards, kubectl -n laden get deploy lists the shop’s Deployments again. The order matters: after kind delete cluster, current-context is empty (error: current-context is not set), which is why use-context follows right after. Whoever only types kubectx kind-werkzeuge and leaves frisch in place gets half the points: the additional cluster and its context are still there.

Clean-up

cd ~/werkzeuge/pruefung
rm -f support.kubeconfig
kubectl config current-context
kind get clusters

Expected:

kind-werkzeuge
werkzeuge

The folders alt and manifeste do no harm and may stay. The lab remains in place; tear it down as on Day 15 under “Clean-up”.

Evaluation

Result Assessment
90–100 points You pick the tool by the problem and can explain to others why.
70–89 points Confident in everyday work. The lost points show which days you should repeat.
50–69 points The tools work individually, the selection does not yet. Repeat the competition (Day 15) and the Tool Finder (Appendix C).
below 50 points Go through the book again, this time with the cheat sheet (Appendix A) next to the terminal.
Task Topic Day
Part A Questions across the book 1–14
1 Logs of dead containers, Pod status, stern 7, 15
2 Minimal permissions, auth can-i --as 2
3 NetworkPolicy, Hubble, file instead of patch 8
4 Removed APIs, Pluto, server dry run 9
5 Schema before rules, kubeconform -strict 10
6 Reducing RBAC, rbac-tool 6, 11
7 helm-diff, values file 12, 15
8 Ephemeral containers, Pod Security 7, 8, 15
9 kubeconfig with a short-lived token 3, 6
10 Context trap with throwaway clusters 0, 13

Passed the exam? With a free account it counts towards your belt. Sign up for free

Contents

More