Skip to content
Hands-on IT IT Drills

Appendix B: Practice Exam

Goal: You solve 17 CKAD-style tasks in 120 minutes and grade yourself. · Duration: 120 min · Prerequisite: Days 0–18

Rules of Play

  • Time: 120 minutes, set a timer. Each task has a weight in percent, adding up to 100 %. Here you pass with 66 % – as things stand, that is also the threshold of the real exam; the authoritative source is https://training.linuxfoundation.org.
  • Allowed: the Kubernetes docs (kubernetes.io/docs), the Helm docs (helm.sh/docs), k explain and -h. Not allowed: this book during the exam time.
  • Each task has its own namespace pruef-NN (Task 1 runs only on cp1). Pass it with -n in every command – as in the exam, where each task requires a different context or namespace.
  • Files go into ~/ckad/pruef.
  • The solutions are at the end. Only read them after the time is up.

Preparation

On cp1: namespaces and working directory.

mkdir -p ~/ckad/pruef/img && cd ~/ckad/pruef
for i in $(seq -w 2 17); do k create ns pruef-$i; done

For Task 1, a Dockerfile with a script:

cat > img/gruss.sh <<'EOF'
echo "$GRUSS aus dem Container"
EOF
cat > img/Dockerfile <<'EOF'
FROM docker.io/library/busybox:1.37
ARG GRUSS=Hallo
ENV GRUSS=${GRUSS}
COPY hallo.sh /usr/local/bin/gruss.sh
USER 1000
ENTRYPOINT ["sh", "/usr/local/bin/gruss.sh"]
EOF

For Task 6, a stable version with a Service:

k apply -f - <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: notes-stable
  namespace: pruef-06
spec:
  replicas: 4
  selector:
    matchLabels:
      app: notes
      track: stable
  template:
    metadata:
      labels:
        app: notes
        track: stable
    spec:
      containers:
      - name: notes-api
        image: 172.16.0.126:30500/notes-api:1.0
        env:
        - name: NOTES_API_KEY
          value: lab-key-123
---
apiVersion: v1
kind: Service
metadata:
  name: notes
  namespace: pruef-06
spec:
  selector:
    app: notes
  ports:
  - port: 80
    targetPort: 8080
EOF

For Task 10, a broken Deployment:

k create secret generic api-key -n pruef-10 --from-literal=NOTES_API_KEY=lab-key-123
k create deployment api -n pruef-10 --image=172.16.0.126:30500/notes-api:1.9 \
  --replicas=2 --port=8080

For Task 11, a chatty Pod and an old manifest:

k run chatty -n pruef-11 --image=busybox:1.37 -- sh -c 'i=0; while true; do
  i=$((i+1)); echo "INFO tick $i"
  [ $((i%5)) -eq 0 ] && echo "ERROR tick $i"; sleep 1; done'
cat > 11-old.yaml <<'EOF'
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: nightly
  namespace: pruef-11
spec:
  schedule: "0 2 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: nightly
            image: busybox:1.37
            command: ["date"]
          restartPolicy: OnFailure
EOF

For Task 16, an application with a faulty Service:

k create deployment notes -n pruef-16 --image=172.16.0.126:30500/notes-api:1.0 \
  --replicas=2 --port=8080
k set env deploy/notes -n pruef-16 NOTES_API_KEY=lab-key-123
k create service clusterip notes -n pruef-16 --tcp=80:80
k set selector svc notes -n pruef-16 app=notes-api

For Task 17, an API and two clients:

k create deployment api -n pruef-17 --image=172.16.0.126:30500/notes-api:1.0 \
  --port=8080
k set env deploy/api -n pruef-17 NOTES_API_KEY=lab-key-123
k expose deploy api -n pruef-17 --port=8080
k run frontend -n pruef-17 --image=busybox:1.37 -l role=frontend -- sleep 3600
k run intruder -n pruef-17 --image=busybox:1.37 -- sleep 3600

Start the clock.

Task 1: Build and export an image (5 %)

There is a Dockerfile in the folder ~/ckad/pruef/img. Use it to build the image pruef-hello:1.0 with the build argument GRUSS=Servus; fix the Dockerfile if necessary. Run the image once with podman and save it as an OCI archive under ~/ckad/pruef/pruef-hello.tar.

Task 2: Init container and sidecar (7 %)

Namespace pruef-02. Pod web with container web (nginx:1.29). An init container prep (busybox:1.37) first writes pruef-02 into the index.html that nginx serves. A native sidecar logs (busybox:1.37) prints nginx’s access log on its standard output with tail -F. The containers share the files via emptyDir volumes.

Task 3: CronJob (4 %)

Namespace pruef-03. CronJob report with busybox:1.37 that runs date; echo report ok every 10 minutes. It never runs in parallel, keeps 2 successful and 1 failed Job, each Job may run for at most 60 seconds and is retried at most twice. Start it once by hand right away as the Job report-manual.

Task 4: Data survives the Pod (4 %)

Namespace pruef-04. PVC data (200Mi, ReadWriteOnce, StorageClass local-path). Pod writer (busybox:1.37) writes gespeichert to /data/stamp.txt and exits. Delete writer; a Pod reader mounts the same PVC and prints the file in its log.

Task 5: Rolling update and rollback (6 %)

Namespace pruef-05. Deployment notes with four replicas of 172.16.0.126:30500/notes-api:1.0 (container notes-api, port 8080, NOTES_API_KEY=lab-key-123). During an update, no Pod may ever be missing and at most one extra may run. Roll out notes-api:1.1 with the change cause 1.1, then notes-api:1.2 with the cause 1.2. Check the result and go back specifically to the revision with 1.1.

Task 6: Canary (4 %)

Namespace pruef-06. Behind the Service notes run four Pods of notes-stable (1.0). Put a Deployment notes-canary with notes-api:1.1 next to it, so that about 20 % of the requests to notes hit the new version. The Service stays unchanged.

Task 7: Helm (5 %)

Namespace pruef-07. From the repository https://stefanprodan.github.io/podinfo, install the chart podinfo in version 6.16.0 as release pi with two replicas and ui.message=Probe. Afterwards, upgrade the release to chart version 6.17.0; replicas and message are kept, and the Pods run with the image 6.17.0.

Task 8: Kustomize (5 %)

Under ~/ckad/pruef/kust/base there is a base with a Deployment notes (notes-api:1.0, one replica) that reads NOTES_API_KEY from the key api-key of a Secret notes-key; Kustomize generates the Secret (api-key=lab-key-123). The overlay ~/ckad/pruef/kust/prod sets namespace pruef-08, prefix prod-, label env=prod, image tag 1.1 and two replicas. Apply the overlay.

Task 9: Probes (5 %)

Namespace pruef-09. Deployment notes with two replicas of notes-api:1.0 (NOTES_API_KEY=lab-key-123). Startup probe: TCP on 8080, every 2 s, up to 30 attempts. Readiness probe: HTTP GET /healthz on 8080 every 5 s. Liveness probe: the command notes-api healthcheck every 10 s.

Task 10: A Deployment won’t come up (6 %)

Namespace pruef-10. The Deployment api should run with notes-api:1.0 and two ready Pods. The key is in the Secret api-key. Find all errors and fix them without deleting the Deployment.

Task 11: Logs and API versions (4 %)

Namespace pruef-11. Write all lines containing ERROR from the log of the Pod chatty to ~/ckad/pruef/11-errors.txt. The manifest ~/ckad/pruef/11-old.yaml cannot be applied – bring it to the current API version, save it as ~/ckad/pruef/11-new.yaml and apply it.

Task 12: Configuration for notes-api (7 %)

Namespace pruef-12. Secret notes-key with api-key=lab-key-123, ConfigMap notes-cfg with PORT=9090. Deployment notes (notes-api:1.0, one replica) takes all keys of the ConfigMap as environment variables. It reads the API key from the Secret as the file /etc/notes/api-key (mounted read-only) via NOTES_API_KEY_FILE. Prove with a POST /notes on port 9090 that it works.

Task 13: SecurityContext and ServiceAccount (7 %)

Namespace pruef-13. The namespace enforces the Pod Security Standard restricted. ServiceAccount notes-sa. Pod hardened (notes-api:1.0, NOTES_API_KEY=lab-key-123) uses it, but gets no token mounted, runs as user and group 65532 with a read-only root file system and without capabilities.

Task 14: RBAC (6 %)

Namespace pruef-14. ServiceAccount monitor may read Pods and their logs there (get, list, watch), list and view Deployments (get, list) and scale Deployments – nothing else. Prove it with k auth can-i.

Task 15: Quota and default values (5 %)

Namespace pruef-15. ResourceQuota pruef-quota: at most 4 Pods, requests totaling 1 CPU and 512Mi, memory limits totaling 1Gi. Containers without their own settings automatically get requests of 100m CPU and 64Mi plus a memory limit of 128Mi. Deployment web (nginx:1.29, three replicas, without resources) runs completely.

Task 16: Service and Ingress (10 %)

Namespace pruef-16. The Service notes does not reach the Pods of the Deployment notes. Fix it (port 80 to container port 8080). Then make the application reachable through Traefik under the host notes.pruef.lab: curl -H 'Host: notes.pruef.lab' http://172.16.0.126:30080/version returns 1.0.

Task 17: NetworkPolicies (10 %)

Namespace pruef-17. No Pod in the namespace accepts connections, except: Pods with role=frontend may reach the Pods of api on TCP 8080. In addition, Pods with role=frontend may only reach api on 8080 and DNS on the way out. Test with frontend and intruder.

Stop the clock.

Solutions

All solutions on cp1 in the folder ~/ckad/pruef.

Solution 1

cd ~/ckad/pruef/img
podman build --build-arg GRUSS=Servus -t pruef-hello:1.0 .

Expected (abridged):

Error: building at STEP "COPY hallo.sh /usr/local/bin/gruss.sh": checking on sources
under "/home/ubuntu/ckad/pruef/img": copier: stat: "/hallo.sh": no such file or
directory

The script is called gruss.sh:

sed -i 's/COPY hallo.sh/COPY gruss.sh/' Dockerfile
podman build --build-arg GRUSS=Servus -t pruef-hello:1.0 . | tail -1
podman run --rm pruef-hello:1.0
podman save --format oci-archive -o ~/ckad/pruef/pruef-hello.tar pruef-hello:1.0
ls -lh ~/ckad/pruef/pruef-hello.tar
cd ~/ckad/pruef

Expected (abridged):

e081fd89289cbda1d14e29ffb248a23523f645f2e5e35b9bf25061f797be0559
Servus aus dem Container
Writing manifest to image destination
-rw-r--r-- 1 ubuntu ubuntu 2.3M Nov 18 16:14 /home/ubuntu/ckad/pruef/pruef-hello.tar

Solution 2

Scaffold with k run web --image=nginx:1.29 -n pruef-02 $do, then add the rest. Important: an emptyDir over /var/log/nginx hides the image’s symlinks to stdout – nginx then writes into a real file that the sidecar can read.

cat > 02-web.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata:
  name: web
  namespace: pruef-02
spec:
  initContainers:
  - name: prep
    image: busybox:1.37
    command: ["sh", "-c", "echo pruef-02 > /html/index.html"]
    volumeMounts:
    - name: html
      mountPath: /html
  - name: logs
    image: busybox:1.37
    restartPolicy: Always
    command: ["sh", "-c", "tail -F /logs/access.log"]
    volumeMounts:
    - name: logs
      mountPath: /logs
  containers:
  - name: web
    image: nginx:1.29
    volumeMounts:
    - name: html
      mountPath: /usr/share/nginx/html
    - name: logs
      mountPath: /var/log/nginx
  volumes:
  - name: html
    emptyDir: {}
  - name: logs
    emptyDir: {}
EOF
k apply -f 02-web.yaml
k wait -n pruef-02 --for=condition=Ready pod/web --timeout=90s
k exec -n pruef-02 web -c web -- curl -s localhost
k logs -n pruef-02 web -c logs | grep GET

Expected:

pod/web created
pod/web condition met
pruef-02
::1 - - [18/Nov/2026:16:14:37 +0000] "GET / HTTP/1.1" 200 9 "-" "curl/8.14.1" "-"

2/2 in k get pod shows: the sidecar counts, the init container prep does not.

Solution 3

k create cronjob report -n pruef-03 --image=busybox:1.37 --schedule="*/10 * * * *" \
  $do -- sh -c 'date; echo report ok' > 03-report.yaml

Add the fields – concurrencyPolicy and the history limits under spec, backoffLimit and activeDeadlineSeconds under spec.jobTemplate.spec:

cat > 03-report.yaml <<'EOF'
apiVersion: batch/v1
kind: CronJob
metadata:
  name: report
  namespace: pruef-03
spec:
  schedule: "*/10 * * * *"
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 2
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      backoffLimit: 2
      activeDeadlineSeconds: 60
      template:
        spec:
          containers:
          - name: report
            image: busybox:1.37
            command: ["sh", "-c", "date; echo report ok"]
          restartPolicy: Never
EOF
k apply -f 03-report.yaml
k create job report-manual -n pruef-03 --from=cronjob/report
k wait -n pruef-03 --for=condition=Complete job/report-manual --timeout=60s
k logs -n pruef-03 job/report-manual

Expected:

cronjob.batch/report created
job.batch/report-manual created
job.batch/report-manual condition met
Wed Nov 18 16:14:50 UTC 2026
report ok

Solution 4

cat > 04-data.yaml <<'EOF'
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data
  namespace: pruef-04
spec:
  accessModes: ["ReadWriteOnce"]
  storageClassName: local-path
  resources:
    requests:
      storage: 200Mi
---
apiVersion: v1
kind: Pod
metadata:
  name: writer
  namespace: pruef-04
spec:
  restartPolicy: Never
  containers:
  - name: writer
    image: busybox:1.37
    command: ["sh", "-c", "echo gespeichert > /data/stamp.txt"]
    volumeMounts:
    - name: data
      mountPath: /data
  volumes:
  - name: data
    persistentVolumeClaim:
      claimName: data
EOF
k apply -f 04-data.yaml
k wait -n pruef-04 --for=jsonpath='{.status.phase}'=Succeeded pod/writer --timeout=90s
k delete pod writer -n pruef-04
cat > 04-reader.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata:
  name: reader
  namespace: pruef-04
spec:
  containers:
  - name: reader
    image: busybox:1.37
    command: ["sh", "-c", "cat /data/stamp.txt; sleep 3600"]
    volumeMounts:
    - name: data
      mountPath: /data
  volumes:
  - name: data
    persistentVolumeClaim:
      claimName: data
EOF
k apply -f 04-reader.yaml
k wait -n pruef-04 --for=condition=Ready pod/reader --timeout=60s
k logs -n pruef-04 reader

Expected (abridged):

persistentvolumeclaim/data created
pod/writer created
pod/writer condition met
pod "writer" deleted from pruef-04 namespace
pod/reader created
pod/reader condition met
gespeichert

With local-path, the volume lives on one node; reader automatically lands there.

Solution 5

k create deploy notes -n pruef-05 --image=172.16.0.126:30500/notes-api:1.0 \
  --replicas=4 --port=8080 $do > 05-notes.yaml

Add the strategy, variable and change cause:

cat > 05-notes.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: notes
  namespace: pruef-05
  annotations:
    kubernetes.io/change-cause: "1.0"
spec:
  replicas: 4
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels:
      app: notes
  template:
    metadata:
      labels:
        app: notes
    spec:
      containers:
      - name: notes-api
        image: 172.16.0.126:30500/notes-api:1.0
        ports:
        - containerPort: 8080
        env:
        - name: NOTES_API_KEY
          value: lab-key-123
EOF
k apply -f 05-notes.yaml
k rollout status deploy/notes -n pruef-05
k set image deploy/notes -n pruef-05 notes-api=172.16.0.126:30500/notes-api:1.1
k annotate deploy notes -n pruef-05 kubernetes.io/change-cause="1.1" --overwrite
k rollout status deploy/notes -n pruef-05
k set image deploy/notes -n pruef-05 notes-api=172.16.0.126:30500/notes-api:1.2
k annotate deploy notes -n pruef-05 kubernetes.io/change-cause="1.2" --overwrite
k rollout status deploy/notes -n pruef-05 --timeout=40s
k get pods -n pruef-05

Expected (abridged):

error: timed out waiting for the condition
NAME                     READY   STATUS         RESTARTS   AGE
notes-69d95b4b66-647sj   0/1     ErrImagePull   0          41s
notes-7c9d5897d5-kddz5   1/1     Running        0          51s
notes-7c9d5897d5-kfgs5   1/1     Running        0          48s
notes-7c9d5897d5-ms8gd   1/1     Running        0          43s
notes-7c9d5897d5-zjlwf   1/1     Running        0          45s

Version 1.2 does not exist. Thanks to maxUnavailable: 0, all four old Pods keep running. Back to the revision with 1.1:

k rollout history deploy/notes -n pruef-05
k rollout undo deploy/notes -n pruef-05 --to-revision=2
k rollout status deploy/notes -n pruef-05
k exec -n pruef-05 deploy/notes -- wget -qO- localhost:8080/version

Expected (abridged):

REVISION  CHANGE-CAUSE
1         1.0
2         1.1
3         1.2
deployment.apps/notes rolled back
deployment "notes" successfully rolled out
1.1

The warning about last-applied-configuration during undo is harmless.

Solution 6

The Service selects only app=notes. A second Deployment with app=notes and its own track label automatically ends up behind it; four to one gives 20 %.

cat > 06-canary.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: notes-canary
  namespace: pruef-06
spec:
  replicas: 1
  selector:
    matchLabels:
      app: notes
      track: canary
  template:
    metadata:
      labels:
        app: notes
        track: canary
    spec:
      containers:
      - name: notes-api
        image: 172.16.0.126:30500/notes-api:1.1
        env:
        - name: NOTES_API_KEY
          value: lab-key-123
EOF
k apply -f 06-canary.yaml
k rollout status deploy/notes-canary -n pruef-06
k get pods -n pruef-06 -L track
k exec -n pruef-06 deploy/notes-stable -- sh -c \
  'for i in $(seq 30); do wget -qO- notes/version; done' | sort | uniq -c

Expected (abridged, the distribution varies):

NAME                            READY   STATUS    RESTARTS   AGE   TRACK
notes-canary-5949cdcc79-rj9v7   1/1     Running   0          3s    canary
notes-stable-56b476f6f-m47tr    1/1     Running   0          9s    stable
...
     23 1.0
      7 1.1

Solution 7

helm repo add podinfo https://stefanprodan.github.io/podinfo
helm repo update podinfo
helm install pi podinfo/podinfo -n pruef-07 --version 6.16.0 \
  --set replicaCount=2 --set ui.message=Probe
helm upgrade pi podinfo/podinfo -n pruef-07 --version 6.17.0 --reuse-values
k get deploy pi-podinfo -n pruef-07 -o jsonpath='{..image}{"\n"}'

Expected (abridged):

STATUS: deployed
REVISION: 1
Release "pi" has been upgraded. Happy Helming!
ghcr.io/stefanprodan/podinfo:6.16.0

Trap: --reuse-values takes over all values of the old release – including the image tag from the default values of 6.16.0. The right choice is --reset-then-reuse-values: the default values of the new chart, with your own values on top.

helm upgrade pi podinfo/podinfo -n pruef-07 --version 6.17.0 --reset-then-reuse-values
k rollout status deploy/pi-podinfo -n pruef-07
k get deploy pi-podinfo -n pruef-07 -o jsonpath='{..image} {.spec.replicas}{"\n"}'
helm get values pi -n pruef-07

Expected:

Release "pi" has been upgraded. Happy Helming!
deployment "pi-podinfo" successfully rolled out
ghcr.io/stefanprodan/podinfo:6.17.0 2
USER-SUPPLIED VALUES:
replicaCount: 2
ui:
  message: Probe

Solution 8

mkdir -p ~/ckad/pruef/kust/base ~/ckad/pruef/kust/prod && cd ~/ckad/pruef/kust
k create deploy notes --image=172.16.0.126:30500/notes-api:1.0 $do > base/deploy.yaml

Add env and remove superfluous fields:

cat > base/deploy.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: notes
spec:
  replicas: 1
  selector:
    matchLabels:
      app: notes
  template:
    metadata:
      labels:
        app: notes
    spec:
      containers:
      - name: notes-api
        image: 172.16.0.126:30500/notes-api:1.0
        env:
        - name: NOTES_API_KEY
          valueFrom:
            secretKeyRef:
              name: notes-key
              key: api-key
EOF
cat > base/kustomization.yaml <<'EOF'
resources:
- deploy.yaml
secretGenerator:
- name: notes-key
  literals:
  - api-key=lab-key-123
EOF
cat > prod/kustomization.yaml <<'EOF'
resources:
- ../base
namespace: pruef-08
namePrefix: prod-
labels:
- pairs:
    env: prod
images:
- name: 172.16.0.126:30500/notes-api
  newTag: "1.1"
replicas:
- name: notes
  count: 2
EOF
k kustomize prod | grep -E 'name: prod|image:'
k apply -k prod
k rollout status deploy/prod-notes -n pruef-08
k exec -n pruef-08 deploy/prod-notes -- wget -qO- localhost:8080/version
cd ~/ckad/pruef

Expected (abridged):

  name: prod-notes-key-d654t4m6b9
  name: prod-notes
              name: prod-notes-key-d654t4m6b9
        image: 172.16.0.126:30500/notes-api:1.1
secret/prod-notes-key-d654t4m6b9 created
deployment.apps/prod-notes created
deployment "prod-notes" successfully rolled out
1.1

Kustomize renames the Secret (prefix and hash) and adjusts the reference in the Deployment accordingly.

Solution 9

k create deploy notes -n pruef-09 --image=172.16.0.126:30500/notes-api:1.0 \
  --replicas=2 --port=8080 $do > 09-notes.yaml

Copy the probes from the docs page “Configure Liveness, Readiness and Startup Probes” and adjust them:

cat > 09-notes.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: notes
  namespace: pruef-09
spec:
  replicas: 2
  selector:
    matchLabels:
      app: notes
  template:
    metadata:
      labels:
        app: notes
    spec:
      containers:
      - name: notes-api
        image: 172.16.0.126:30500/notes-api:1.0
        ports:
        - containerPort: 8080
        env:
        - name: NOTES_API_KEY
          value: lab-key-123
        startupProbe:
          tcpSocket:
            port: 8080
          periodSeconds: 2
          failureThreshold: 30
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8080
          periodSeconds: 5
        livenessProbe:
          exec:
            command: ["notes-api", "healthcheck"]
          periodSeconds: 10
EOF
k apply -f 09-notes.yaml
k rollout status deploy/notes -n pruef-09
k describe deploy notes -n pruef-09 | grep -E 'Liveness|Readiness|Startup'

Expected (abridged):

deployment "notes" successfully rolled out
    Liveness:   exec [notes-api healthcheck] delay=0s timeout=1s period=10s ...
    Readiness:  http-get http://:8080/healthz delay=0s timeout=1s period=5s ...
    Startup:    tcp-socket :8080 delay=0s timeout=1s period=2s ...

Solution 10

k get pods -n pruef-10
k get events -n pruef-10 --field-selector type=Warning | grep -m1 'Failed to pull'

Expected (abridged):

api-77d4fc4568-rtncm   0/1     ImagePullBackOff   0          20s
api-77d4fc4568-sg4fb   0/1     ImagePullBackOff   0          20s
... Failed to pull image "172.16.0.126:30500/notes-api:1.9": ... NotFound ...

First error: tag 1.9 does not exist.

k set image deploy/api -n pruef-10 notes-api=172.16.0.126:30500/notes-api:1.0
k get pods -n pruef-10

Expected (after about 20 s, abridged):

api-77d4fc4568-rtncm   0/1     ImagePullBackOff   0             2m7s
api-77d4fc4568-sg4fb   0/1     ImagePullBackOff   0             2m7s
api-b448b9847-gmb4d    0/1     CrashLoopBackOff   1 (12s ago)   15s

The old Pods remain until new ones are ready. k logs deploy/api would catch an old Pod – so look at the new Pod directly (name from your output):

k logs -n pruef-10 api-b448b9847-gmb4d --tail=1

Expected:

time=... level=ERROR msg="start abgebrochen" err="NOTES_API_KEY oder NOTES_API_KEY_FILE
fehlt"

Second error: the key is missing. The Secret already has the matching name NOTES_API_KEY:

k set env deploy/api -n pruef-10 --from=secret/api-key
k rollout status deploy/api -n pruef-10
k get deploy api -n pruef-10

Expected (abridged):

deployment.apps/api env updated
deployment "api" successfully rolled out
NAME   READY   UP-TO-DATE   AVAILABLE   AGE
api    2/2     2            2           42s

Solution 11

k logs -n pruef-11 chatty | grep ERROR > ~/ckad/pruef/11-errors.txt
head -2 ~/ckad/pruef/11-errors.txt
k apply -f 11-old.yaml

Expected (abridged):

ERROR tick 5
ERROR tick 10
error: resource mapping not found for name: "nightly" namespace: "pruef-11" from
"11-old.yaml": no matches for kind "CronJob" in version "batch/v1beta1"
ensure CRDs are installed first

batch/v1beta1 has been removed. k api-resources | grep cronj or k explain cronjob | head -3 shows which version applies. Convert with the kubectl-convert plugin from Day 15 – or enter apiVersion: batch/v1 by hand:

k convert -f 11-old.yaml --output-version batch/v1 > 11-new.yaml
head -2 11-new.yaml
k apply -f 11-new.yaml
k get cj -n pruef-11

Expected:

apiVersion: batch/v1
kind: CronJob
cronjob.batch/nightly created
NAME      SCHEDULE    TIMEZONE   SUSPEND   ACTIVE   LAST SCHEDULE   AGE
nightly   0 2 * * *   <none>     False     0        <none>          0s

Solution 12

k create secret generic notes-key -n pruef-12 --from-literal=api-key=lab-key-123
k create configmap notes-cfg -n pruef-12 --from-literal=PORT=9090
cat > 12-notes.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: notes
  namespace: pruef-12
spec:
  replicas: 1
  selector:
    matchLabels:
      app: notes
  template:
    metadata:
      labels:
        app: notes
    spec:
      containers:
      - name: notes-api
        image: 172.16.0.126:30500/notes-api:1.0
        ports:
        - containerPort: 9090
        envFrom:
        - configMapRef:
            name: notes-cfg
        env:
        - name: NOTES_API_KEY_FILE
          value: /etc/notes/api-key
        volumeMounts:
        - name: key
          mountPath: /etc/notes
          readOnly: true
      volumes:
      - name: key
        secret:
          secretName: notes-key
EOF
k apply -f 12-notes.yaml
k rollout status deploy/notes -n pruef-12
k logs -n pruef-12 deploy/notes
k exec -n pruef-12 deploy/notes -- wget -qO- --header 'X-API-Key: lab-key-123' \
  --post-data '{"text":"pruef"}' http://localhost:9090/notes

Expected (abridged):

deployment "notes" successfully rolled out
time=... level=INFO msg="api key loaded" source=file
time=... level=INFO msg="store ready" store=memory
time=... level=INFO msg=listening addr=:9090 version=1.0 pid=1
{"id":"6db79a29-e0d6-4d87-981b-a56c0813221d","text":"pruef"}

Solution 13

k label ns pruef-13 pod-security.kubernetes.io/enforce=restricted
k create sa notes-sa -n pruef-13
cat > 13-hardened.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata:
  name: hardened
  namespace: pruef-13
spec:
  serviceAccountName: notes-sa
  automountServiceAccountToken: false
  securityContext:
    runAsNonRoot: true
    runAsUser: 65532
    runAsGroup: 65532
    seccompProfile:
      type: RuntimeDefault
  containers:
  - name: notes-api
    image: 172.16.0.126:30500/notes-api:1.0
    env:
    - name: NOTES_API_KEY
      value: lab-key-123
    securityContext:
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true
      capabilities:
        drop: ["ALL"]
EOF
k apply -f 13-hardened.yaml
k wait -n pruef-13 --for=condition=Ready pod/hardened --timeout=60s
k exec -n pruef-13 hardened -- id
k exec -n pruef-13 hardened -- touch /x
k exec -n pruef-13 hardened -- ls /var/run/secrets/kubernetes.io

Expected:

namespace/pruef-13 labeled
serviceaccount/notes-sa created
pod/hardened created
pod/hardened condition met
uid=65532 gid=65532 groups=65532
touch: /x: Read-only file system
command terminated with exit code 1
ls: /var/run/secrets/kubernetes.io: No such file or directory
command terminated with exit code 1

If a field is missing, the PodSecurity rejection names all violations at once, for example allowPrivilegeEscalation != false or runAsNonRoot != true. Without runAsGroup, by the way, the process would run with group 0.

Solution 14

Different verbs for different resources – that only works with a Role in YAML. Scaling is the subresource deployments/scale.

k create sa monitor -n pruef-14
cat > 14-role.yaml <<'EOF'
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: monitor
  namespace: pruef-14
rules:
- apiGroups: [""]
  resources: ["pods", "pods/log"]
  verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
  resources: ["deployments"]
  verbs: ["get", "list"]
- apiGroups: ["apps"]
  resources: ["deployments/scale"]
  verbs: ["update", "patch"]
EOF
k apply -f 14-role.yaml
k create rolebinding monitor -n pruef-14 --role=monitor \
  --serviceaccount=pruef-14:monitor
SA=system:serviceaccount:pruef-14:monitor
k auth can-i get pods --subresource=log -n pruef-14 --as=$SA
k auth can-i list deployments.apps -n pruef-14 --as=$SA
k auth can-i patch deployments.apps --subresource=scale -n pruef-14 --as=$SA
k auth can-i patch deployments.apps -n pruef-14 --as=$SA
k auth can-i delete pods -n pruef-14 --as=$SA

Expected:

serviceaccount/monitor created
role.rbac.authorization.k8s.io/monitor created
rolebinding.rbac.authorization.k8s.io/monitor created
yes
yes
yes
no
no

Solution 15

First the quota, then the LimitRange, then the Deployment. With a quota on requests.cpu and limits.memory, the API rejects every Pod without these settings – the LimitRange fills them in.

k create quota pruef-quota -n pruef-15 \
  --hard=pods=4,requests.cpu=1,requests.memory=512Mi,limits.memory=1Gi
cat > 15-limits.yaml <<'EOF'
apiVersion: v1
kind: LimitRange
metadata:
  name: defaults
  namespace: pruef-15
spec:
  limits:
  - type: Container
    defaultRequest:
      cpu: 100m
      memory: 64Mi
    default:
      memory: 128Mi
EOF
k apply -f 15-limits.yaml
k create deploy web -n pruef-15 --image=nginx:1.29 --replicas=3
k rollout status deploy/web -n pruef-15
k get pod -n pruef-15 -l app=web \
  -o jsonpath='{.items[0].spec.containers[0].resources}{"\n"}'
k get quota -n pruef-15

Expected (abridged):

deployment "web" successfully rolled out
{"limits":{"memory":"128Mi"},"requests":{"cpu":"100m","memory":"64Mi"}}
NAME          REQUEST                                                         LIMIT
pruef-quota   pods: 3/4, requests.cpu: 300m/1, requests.memory: 192Mi/512Mi   limits...

The LIMIT column shows limits.memory: 384Mi/1Gi.

If the Deployment comes first, it stays at 0/3; only the events show the reason: failed quota: pruef-quota: must specify limits.memory.

Solution 16

k get endpointslices -n pruef-16 -l kubernetes.io/service-name=notes
k get svc notes -n pruef-16 -o wide
k get pods -n pruef-16 --show-labels

Expected (abridged):

NAME          ADDRESSTYPE   PORTS     ENDPOINTS   AGE
notes-6pr9m   IPv4          <unset>   <unset>     5s
NAME    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE   SELECTOR
notes   ClusterIP   10.104.105.133   <none>        80/TCP    6s    app=notes-api
NAME                     READY   STATUS    RESTARTS   AGE   LABELS
notes-7b6866d9dd-46vbg   1/1     Running   0          3s    app=notes,pod-template-...

Two errors: selector app=notes-api instead of app=notes, targetPort 80 instead of 8080.

k set selector svc notes -n pruef-16 app=notes
k patch svc notes -n pruef-16 --type=json \
  -p '[{"op":"replace","path":"/spec/ports/0/targetPort","value":8080}]'
k get endpointslices -n pruef-16 -l kubernetes.io/service-name=notes
k create ingress notes -n pruef-16 --class=traefik \
  --rule="notes.pruef.lab/*=notes:80"

Expected:

service/notes selector updated
service/notes patched
NAME          ADDRESSTYPE   PORTS   ENDPOINTS                        AGE
notes-6pr9m   IPv4          8080    192.168.235.190,192.168.189.88   7s
ingress.networking.k8s.io/notes created

Traefik needs a few seconds for the new route; until then it answers with 404 page not found.

curl -s -H 'Host: notes.pruef.lab' http://172.16.0.126:30080/version

Expected: 1.0

Solution 17

cat > 17-netpol.yaml <<'EOF'
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny
  namespace: pruef-17
spec:
  podSelector: {}
  policyTypes:
  - Ingress
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: api-allow-frontend
  namespace: pruef-17
spec:
  podSelector:
    matchLabels:
      app: api
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchLabels:
          role: frontend
    ports:
    - protocol: TCP
      port: 8080
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: frontend-egress
  namespace: pruef-17
spec:
  podSelector:
    matchLabels:
      role: frontend
  policyTypes:
  - Egress
  egress:
  - to:
    - podSelector:
        matchLabels:
          app: api
    ports:
    - protocol: TCP
      port: 8080
  - ports:
    - protocol: UDP
      port: 53
    - protocol: TCP
      port: 53
EOF
k apply -f 17-netpol.yaml
k exec -n pruef-17 frontend -- wget -qO- -T 3 api:8080/version
k exec -n pruef-17 intruder -- wget -qO- -T 3 api:8080/version
k exec -n pruef-17 frontend -- wget -qO- -T 3 http://172.16.0.126:30080/

Expected:

networkpolicy.networking.k8s.io/default-deny created
networkpolicy.networking.k8s.io/api-allow-frontend created
networkpolicy.networking.k8s.io/frontend-egress created
1.0
wget: download timed out
command terminated with exit code 1
wget: download timed out
command terminated with exit code 1

Without the DNS rule, frontend already fails at resolving the name api. The DNS rule without to allows port 53 to any destination – precise enough for the exam.

Scoring

Add up the weights of the tasks that are completely and verifiably solved – there is no partial credit here.

Result Assessment
85–100 % exam-ready
66–84 % passed, but barely: review your weak spots
under 66 % review the days covering the missed tasks and start over
Tasks Curriculum domain Days
1–4 Application Design and Build (20 %) 2–5
5–8 Application Deployment (20 %) 11–13
9–11 Application Observability and Maintenance (15 %) 14, 15
12–15 Application Environment, Configuration and Security (25 %) 6–9
16, 17 Services and Networking (20 %) 16, 17

Clean up:

for i in $(seq -w 2 17); do k delete ns pruef-$i --wait=false; done
podman rmi pruef-hello:1.0

Checkpoint

k get ns | grep -c '^pruef-'

Expected (after about a minute): 0

Good luck in the exam.