Appendix B: Practice Exam
Goal: Two hours, 17 tasks, weighted like the CNPE exam. Pass mark 64 % · Prerequisite: Day 0–17 on your lab
Rules of the game
- Set a timer for 120 minutes. Only the Kubernetes documentation as help, no peeking at the solutions.
- Each task states its points. Total: 100. Pass mark: 64.
- A task is solved when its check command (in the solutions) shows what is expected. There are no partial points – as in the exam, the result in the cluster is what counts.
- All tasks take place in the new tenant
team-lila, unless stated otherwise.
| Domain | Weight | Tasks |
|---|---|---|
| Platform Architecture and Infrastructure | 15 | 1–3 |
| GitOps and Continuous Delivery | 25 | 4–7 |
| Platform APIs and Self-Service | 25 | 8–11 |
| Observability and Operations | 20 | 12–14 |
| Security and Policy Enforcement | 15 | 15–17 |
Before you start – make room. After 17 days the CPU requests of the workers are almost fully allocated (measured: 99 %), although the real load is below 50 % – every container gets 100 m from the LimitRange. You no longer need Team Gelb’s practice faults (Day 11):
# on cp1
k delete ns team-gelb
for n in worker1 worker2; do k describe node $n | grep -A6 'Allocated resources' | grep cpu; doneExpected:
namespace "team-gelb" deleted
cpu 1690m (84%) 9050m (452%)
cpu 1690m (84%) 5500m (275%)
The tasks
Task 1 (5 points). Create the namespace
team-lila as a tenant (team=lila,
tier=tenant). The platform must automatically give it a
quota, a LimitRange, two NetworkPolicies and a RoleBinding.
Task 2 (5 points). Deployment suche in
team-lila: image nginx:1.31-alpine, 2
replicas, label app: suche; the replicas must run on
different nodes; the control plane node must not block
the distribution. Store the manifest at
~/cnpe/anhang-b/suche.yaml.
Task 3 (5 points). A PriorityClass
batch-niedrig with value 1000 that never
preempts other pods. A Deployment index in
team-lila (image busybox:1.37, command
sleep 3600) uses it.
Task 4 (5 points). An Argo CD project
team-lila: only the platform repo as source, only the
namespace team-lila as destination.
Task 5 (8 points). Bring suche under
GitOps: the manifest from Task 2 to apps/team-lila/suche in
the platform repo, Application team-lila-suche in project
team-lila, with automatic sync, prune and self-heal.
Task 6 (6 points). A colleague sets the image of
suche in Git to nginx:1.31-alpine-gibtsnicht.
Do this yourself (commit and push), observe the consequences and restore
the working state via Git.
Task 7 (6 points). Rollout preise in
team-lila (image argoproj/rollouts-demo:blue,
2 replicas, requests 20 m/32 Mi, limits 100 m/64 Mi) with canary: first
50 %, then a manual pause. Set the image to green and
promote the rollout after the pause.
Task 8 (7 points). CRD
wartungsfenster.plattform.lab (kind
Wartungsfenster, short name wf, namespaced,
version v1) with the required fields wochentag
(one of Mo–So) and stunde (0–23). Create a maintenance
window nachts in team-lila for Tuesday at 3
a.m.
Task 9 (6 points). Members of
team-lila-devs may create maintenance windows in their
namespace – without a new RoleBinding.
Task 10 (6 points). Use the platform API from Day 8
to order a database suchdb of size S in
team-lila. It must report READY True.
Task 11 (6 points). Every tenant namespace
automatically gets a ConfigMap plattform-kontakt with the
keys team (from the namespace label) and
hilfe: [email protected] – the existing ones too.
Task 12 (7 points). Deployment info in
team-lila (image
ghcr.io/stefanprodan/podinfo:6.11.0, port 9898) with
Service info (port name http). Prometheus
should scrape its metrics; the target must be up.
Task 13 (6 points). Recording rule
namespace:http_requests:rate5m: requests per second of all
pods in team-lila, over 5 minutes, summed per
namespace.
Task 14 (7 points). Inject the following fault and fix it so that the pod keeps running:
# on cp1 – part of the task
cat > ~/cnpe/anhang-b/bericht.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: bericht
namespace: team-lila
spec:
selector:
matchLabels: {app: bericht}
template:
metadata:
labels: {app: bericht}
spec:
containers:
- name: bericht
image: busybox:1.37
command: ["sh", "-c", "head -c 300m /dev/zero | tail; sleep 3600"]
resources:
limits: {memory: 128Mi}
EOF
k apply -f ~/cnpe/anhang-b/bericht.yamlTask 15 (5 points). In tenant namespaces, pods with privileged containers may no longer be created.
Task 16 (5 points). How many
critical vulnerabilities does
nginx:1.31-alpine have? Write only the number into
~/cnpe/anhang-b/kritisch.txt.
Task 17 (5 points). The auditor
prueferin (a user, not a group) may read
everything in team-lila except Secrets – and change
nothing.
Solutions
Task 1
# on cp1
mkdir -p ~/cnpe/anhang-b && cd ~/cnpe/anhang-b
k create ns team-lila --dry-run=client -o yaml | k label --local -f - team=lila tier=tenant -o yaml | k apply -f -
sleep 8
k -n team-lila get quota,limitrange,netpol,rolebinding -o name | wc -lExpected:
namespace/team-lila created
5
Task 2
# on cp1
cat > suche.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: suche
namespace: team-lila
labels: {app: suche}
spec:
replicas: 2
selector:
matchLabels: {app: suche}
template:
metadata:
labels: {app: suche}
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
nodeTaintsPolicy: Honor
labelSelector:
matchLabels: {app: suche}
containers:
- name: suche
image: nginx:1.31-alpine
EOF
k apply -f suche.yaml
k -n team-lila rollout status deploy/suche --timeout=120s
k -n team-lila get pods -l app=suche -o custom-columns=NODE:.spec.nodeName --no-headers | sort | uniq -cExpected:
deployment.apps/suche created
deployment "suche" successfully rolled out
1 worker1
1 worker2
Task 3
# on cp1
k create priorityclass batch-niedrig --value=1000 --preemption-policy=Never --description='Hintergrundjobs'
k -n team-lila create deployment index --image=busybox:1.37 -- sleep 3600
k -n team-lila patch deploy index -p '{"spec":{"template":{"spec":{"priorityClassName":"batch-niedrig"}}}}'
k -n team-lila rollout status deploy/index --timeout=90s
k -n team-lila get pod -l app=index -o jsonpath='{.items[0].spec.priority} {.items[0].spec.preemptionPolicy}{"\n"}'Expected (abridged):
priorityclass.scheduling.k8s.io/batch-niedrig created
deployment.apps/index created
deployment.apps/index patched
deployment "index" successfully rolled out
1000 Never
Task 4
# on cp1
cat > projekt-lila.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: team-lila
namespace: argocd
spec:
sourceRepos: [http://172.16.0.126:30300/platform/plattform.git]
destinations:
- {server: https://kubernetes.default.svc, namespace: team-lila}
EOF
k apply -f projekt-lila.yamlExpected:
appproject.argoproj.io/team-lila created
Task 5
# on cp1
cd ~/cnpe/plattform && git pull -q
mkdir -p apps/team-lila/suche && cp ~/cnpe/anhang-b/suche.yaml apps/team-lila/suche/
git add -A && git commit -qm 'suche für Team Lila' && git push -q
cat > ~/cnpe/anhang-b/suche-app.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: team-lila-suche
namespace: argocd
spec:
project: team-lila
source:
repoURL: http://172.16.0.126:30300/platform/plattform.git
targetRevision: main
path: apps/team-lila/suche
destination:
server: https://kubernetes.default.svc
namespace: team-lila
syncPolicy:
automated: {prune: true, selfHeal: true}
EOF
k apply -f ~/cnpe/anhang-b/suche-app.yaml
sleep 30
k -n argocd get application team-lila-suche -o jsonpath='{.spec.project} {.status.sync.status} {.status.health.status}{"\n"}'Expected:
application.argoproj.io/team-lila-suche created
team-lila Synced Healthy
Task 6
# on cp1
cd ~/cnpe/plattform
sed -i 's#nginx:1.31-alpine#nginx:1.31-alpine-gibtsnicht#' apps/team-lila/suche/suche.yaml
git commit -qam 'suche: neues Image' && git push -q
argocd app get team-lila-suche --refresh >/dev/null
sleep 30
k -n team-lila get pods -l app=suche --no-headers | awk '{print $3}' | sort | uniq -c
# back via Git
git revert --no-edit HEAD && git push -q
argocd app get team-lila-suche --refresh >/dev/null
sleep 40
k -n argocd get application team-lila-suche -o jsonpath='{.status.sync.status} {.status.health.status}{"\n"}'
k -n team-lila get deploy suche -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'Expected (abridged):
1 ImagePullBackOff
2 Running
…
Synced Healthy
nginx:1.31-alpine
k rollout undo or a patch on the Deployment earn 0
points: self-heal reverts them, and Git still shows the broken
image.
Task 7
# on cp1
cd ~/cnpe/anhang-b
cat > preise.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: preise
namespace: team-lila
spec:
replicas: 2
selector:
matchLabels: {app: preise}
template:
metadata:
labels: {app: preise}
spec:
containers:
- name: preise
image: argoproj/rollouts-demo:blue
resources:
requests: {cpu: 20m, memory: 32Mi}
limits: {cpu: 100m, memory: 64Mi}
strategy:
canary:
steps:
- setWeight: 50
- pause: {}
EOF
k apply -f preise.yaml
sleep 30
k argo rollouts set image preise -n team-lila preise=argoproj/rollouts-demo:green
sleep 20
k -n team-lila get rollout preise -o jsonpath='{.status.phase} step={.status.currentStepIndex}{"\n"}'
k argo rollouts promote preise -n team-lila
sleep 25
k -n team-lila get rollout preise -o jsonpath='{.status.phase} {.spec.template.spec.containers[0].image}{"\n"}'Expected:
rollout.argoproj.io/preise created
rollout "preise" image updated
Paused step=1
rollout 'preise' promoted
Healthy argoproj/rollouts-demo:green
Task 8
# on cp1
cat > crd-wartungsfenster.yaml <<'EOF'
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: wartungsfenster.plattform.lab
spec:
group: plattform.lab
scope: Namespaced
names: {kind: Wartungsfenster, plural: wartungsfenster, singular: wartungsfenster, shortNames: [wf]}
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
required: [wochentag, stunde]
properties:
wochentag: {type: string, enum: [Mo, Di, Mi, Do, Fr, Sa, So]}
stunde: {type: integer, minimum: 0, maximum: 23}
EOF
k apply -f crd-wartungsfenster.yaml
k wait --for=condition=Established crd/wartungsfenster.plattform.lab
printf 'apiVersion: plattform.lab/v1\nkind: Wartungsfenster\nmetadata:\n name: nachts\n namespace: team-lila\nspec:\n wochentag: Di\n stunde: 3\n' | k apply -f -
# Counter-check: must be rejected
printf 'apiVersion: plattform.lab/v1\nkind: Wartungsfenster\nmetadata:\n name: falsch\n namespace: team-lila\nspec:\n wochentag: Dienstag\n stunde: 25\n' | k apply -f -Expected:
customresourcedefinition.apiextensions.k8s.io/wartungsfenster.plattform.lab created
customresourcedefinition.apiextensions.k8s.io/wartungsfenster.plattform.lab condition met
wartungsfenster.plattform.lab/nachts created
The Wartungsfenster "falsch" is invalid:
* spec.wochentag: Unsupported value: "Dienstag": supported values: "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"
* spec.stunde: Invalid value: 25: spec.stunde in body should be less than or equal to 23
Task 9
# on cp1
printf 'apiVersion: rbac.authorization.k8s.io/v1\nkind: ClusterRole\nmetadata:\n name: plattform-wartungsfenster-edit\n labels:\n rbac.authorization.k8s.io/aggregate-to-edit: "true"\nrules:\n- apiGroups: [plattform.lab]\n resources: [wartungsfenster]\n verbs: [get, list, watch, create, update, patch, delete]\n' | k apply -f -
k auth can-i create wartungsfenster.plattform.lab -n team-lila --as=lea --as-group=team-lila-devsExpected:
clusterrole.rbac.authorization.k8s.io/plattform-wartungsfenster-edit created
yes
Kyverno created the RoleBinding for team-lila-devs to
edit in Task 1 – the aggregation extends
edit.
Task 10
# on cp1
printf 'apiVersion: plattform.lab/v1alpha1\nkind: Datenbank\nmetadata:\n name: suchdb\n namespace: team-lila\nspec:\n groesse: S\n' | k apply -f -
sleep 70
k -n team-lila get datenbank suchdbExpected:
datenbank.plattform.lab/suchdb created
NAME GROESSE ADRESSE SYNCED READY RESPONSIVE COMPOSITION AGE
suchdb S suchdb True True True datenbank-postgres 70s
Task 11
# on cp1
cat > kontakt.yaml <<'EOF'
apiVersion: policies.kyverno.io/v1
kind: GeneratingPolicy
metadata:
name: team-kontakt
spec:
evaluation:
generateExisting:
enabled: true
synchronize:
enabled: true
matchConstraints:
resourceRules:
- apiGroups: [""]
apiVersions: [v1]
operations: [CREATE, UPDATE]
resources: [namespaces]
objectSelector:
matchLabels: {tier: tenant}
variables:
- name: ns
expression: object.metadata.name
- name: cm
expression: >-
[{"apiVersion": dyn("v1"), "kind": dyn("ConfigMap"),
"metadata": dyn({"name": "plattform-kontakt"}),
"data": dyn({"team": object.metadata.labels["team"], "hilfe": "[email protected]"})}]
generate:
- expression: generator.Apply(variables.ns, variables.cm)
EOF
k apply -f kontakt.yaml
sleep 20
k get cm -A -l generate.kyverno.io/policy-name=team-kontakt --no-headers | wc -l
k -n team-lila get cm plattform-kontakt -o jsonpath='{.data}{"\n"}'Expected:
generatingpolicy.policies.kyverno.io/team-kontakt created
5
{"hilfe":"[email protected]","team":"lila"}
Five tenants: team-blue, team-green, team-green-staging, team-rot, team-lila.
Task 12
# on cp1
k -n team-lila create deployment info --image=ghcr.io/stefanprodan/podinfo:6.11.0 --port=9898
k -n team-lila expose deploy info --port=9898 --name=info
# the ServiceMonitor needs a port name
k -n team-lila patch svc info --type=json -p '[{"op":"add","path":"/spec/ports/0/name","value":"http"}]'
printf 'apiVersion: monitoring.coreos.com/v1\nkind: ServiceMonitor\nmetadata:\n name: info\n namespace: team-lila\nspec:\n selector:\n matchLabels: {app: info}\n endpoints:\n - port: http\n' | k apply -f -
# without this rule: context deadline exceeded (Day 10)
printf 'apiVersion: networking.k8s.io/v1\nkind: NetworkPolicy\nmetadata:\n name: allow-monitoring\n namespace: team-lila\nspec:\n podSelector: {}\n policyTypes: [Ingress]\n ingress:\n - from:\n - namespaceSelector:\n matchLabels:\n kubernetes.io/metadata.name: monitoring\n ports:\n - {port: 9898, protocol: TCP}\n' | k apply -f -
sleep 120
curl -s 'http://172.16.0.126:30090/api/v1/targets?state=active' | jq -r '.data.activeTargets[] | select(.labels.namespace=="team-lila") | "\(.labels.job) \(.health)"'Expected (abridged):
servicemonitor.monitoring.coreos.com/info created
networkpolicy.networking.k8s.io/allow-monitoring created
info up
Right after creation the target shows unknown – the
first scrape is still pending.
Task 13
# on cp1
printf 'apiVersion: monitoring.coreos.com/v1\nkind: PrometheusRule\nmetadata:\n name: info\n namespace: team-lila\nspec:\n groups:\n - name: info\n rules:\n - record: namespace:http_requests:rate5m\n expr: sum by (namespace) (rate(http_requests_total{namespace="team-lila"}[5m]))\n' | k apply -f -
sleep 120
curl -s http://172.16.0.126:30090/api/v1/query --data-urlencode 'query=namespace:http_requests:rate5m' \
| jq -r '.data.result[] | "\(.metric.namespace) \(.value[1])"'Expected (value varies):
prometheusrule.monitoring.coreos.com/info created
team-lila 0.009559333333333335
Task 14
# on cp1
sleep 75
k -n team-lila get pod -l app=bericht -o jsonpath='{.items[0].status.containerStatuses[0].lastState.terminated.reason}{"\n"}'
k -n team-lila set resources deploy/bericht --limits=memory=512Mi
k -n team-lila rollout status deploy/bericht --timeout=150sExpected:
OOMKilled
deployment.apps/bericht resource requirements updated
deployment "bericht" successfully rolled out
Task 15
# on cp1
cat > kein-privileged.yaml <<'EOF'
apiVersion: policies.kyverno.io/v1
kind: ValidatingPolicy
metadata:
name: kein-privileged
spec:
validationActions: [Deny]
matchConstraints:
resourceRules:
- apiGroups: [""]
apiVersions: [v1]
operations: [CREATE, UPDATE]
resources: [pods]
namespaceSelector:
matchLabels: {tier: tenant}
validations:
- expression: >-
object.spec.containers.all(c, !c.?securityContext.?privileged.orValue(false))
message: Privilegierte Container sind in Mandanten-Namespaces verboten
EOF
k apply -f kein-privileged.yaml
sleep 5
k -n team-lila run priv --image=busybox:1.37 \
--overrides='{"spec":{"containers":[{"name":"priv","image":"busybox:1.37","command":["sleep","60"],"securityContext":{"privileged":true}}]}}'Expected:
validatingpolicy.policies.kyverno.io/kein-privileged created
Error from server: admission webhook "vpol.validate.kyverno.svc-fail-…" denied the request: Policy kein-privileged failed: Privilegierte Container sind in Mandanten-Namespaces verboten
The namespace ci (Buildah runs privileged, Day 6) does
not carry tier=tenant – the pipeline keeps running. Pod
Security Admission set to restricted would be the built-in
alternative.
Task 16
# on cp1
trivy image --severity CRITICAL --quiet --format json nginx:1.31-alpine | jq '[.Results[].Vulnerabilities[]?] | length' > ~/cnpe/anhang-b/kritisch.txt
cat ~/cnpe/anhang-b/kritisch.txtExpected (on the day the course was written):
0
Task 17
# on cp1
k -n team-lila create rolebinding prueferin-view --clusterrole=view --user=prueferin
k auth can-i list pods -n team-lila --as=prueferin
k auth can-i get secrets -n team-lila --as=prueferin
k auth can-i delete pods -n team-lila --as=prueferinExpected:
rolebinding.rbac.authorization.k8s.io/prueferin-view created
yes
no
no
view deliberately leaves out Secrets – exactly the
requirement.
Evaluation
Add up the points of the tasks you solved. Below 64: repeat the days
of the domains where you lost points and take the exam again in a week –
with your own names instead of lila, so that you don’t type
from memory.