Anhang B: Probeprüfung
Ziel: Zwei Stunden, 17 Aufgaben, gewichtet wie die CNPE-Prüfung. Bestanden ab 64 % · Voraussetzung: Tag 0–17 auf deinem Gelände
Spielregeln
- Wecker auf 120 Minuten. Nur die Kubernetes-Doku als Hilfe, kein Blick in die Lösungen.
- Jede Aufgabe nennt ihre Punkte. Summe: 100. Bestanden ab 64.
- Gelöst ist eine Aufgabe, wenn ihr Prüfbefehl (in den Lösungen) das Erwartete zeigt. Teilpunkte gibt es nicht – wie in der Prüfung zählt das Ergebnis im Cluster.
- Alle Aufgaben spielen im neuen Mandanten
team-lila, sofern nicht anders genannt.
| Bereich | Gewicht | Aufgaben |
|---|---|---|
| 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 |
Vor dem Start – Platz schaffen. Nach 17 Tagen sind die CPU-Requests der Worker fast vollständig vergeben (gemessen: 99 %), obwohl die echte Last unter 50 % liegt – jeder Container bekommt von der LimitRange 100 m. Die Übungsstörungen von Team Gelb (Tag 11) brauchst du nicht mehr:
# auf cp1
k delete ns team-gelb
for n in worker1 worker2; do k describe node $n | grep -A6 'Allocated resources' | grep cpu; doneErwartet:
namespace "team-gelb" deleted
cpu 1690m (84%) 9050m (452%)
cpu 1690m (84%) 5500m (275%)
Die Aufgaben
Aufgabe 1 (5 Punkte). Lege den Namespace
team-lila als Mandanten an (team=lila,
tier=tenant). Die Plattform muss ihm automatisch Quota,
LimitRange, zwei NetworkPolicies und eine RoleBinding geben.
Aufgabe 2 (5 Punkte). Deployment suche
in team-lila: Image nginx:1.31-alpine, 2
Kopien, Label app: suche, Kopien müssen auf
verschiedenen Knoten laufen; der Control-Plane-Knoten
darf die Verteilung nicht blockieren. Lege das Manifest unter
~/cnpe/anhang-b/suche.yaml ab.
Aufgabe 3 (5 Punkte). Eine PriorityClass
batch-niedrig mit Wert 1000, die nie
andere Pods verdrängt. Ein Deployment index in
team-lila (Image busybox:1.37, Befehl
sleep 3600) nutzt sie.
Aufgabe 4 (5 Punkte). Ein Argo-CD-Projekt
team-lila: nur das Plattform-Repo als Quelle, nur der
Namespace team-lila als Ziel.
Aufgabe 5 (8 Punkte). Bringe suche
unter GitOps: Manifest aus Aufgabe 2 nach
apps/team-lila/suche im Plattform-Repo, Application
team-lila-suche im Projekt team-lila, mit
automatischem Sync, Prune und Self-Heal.
Aufgabe 6 (6 Punkte). Ein Kollege setzt das Image
von suche in Git auf
nginx:1.31-alpine-gibtsnicht. Führe das selbst aus (Commit
und Push), beobachte die Folgen und stelle den funktionierenden Zustand
über Git wieder her.
Aufgabe 7 (6 Punkte). Rollout preise in
team-lila (Image argoproj/rollouts-demo:blue,
2 Kopien, Requests 20 m/32 Mi, Limits 100 m/64 Mi) mit Canary: erst 50
%, dann manuelle Pause. Setze das Image auf green und gib
den Rollout nach der Pause frei.
Aufgabe 8 (7 Punkte). CRD
wartungsfenster.plattform.lab (Kind
Wartungsfenster, Kurzname wf, namespaced,
Version v1) mit Pflichtfeldern wochentag
(einer von Mo–So) und stunde (0–23). Lege in
team-lila ein Wartungsfenster nachts für
Dienstag 3 Uhr an.
Aufgabe 9 (6 Punkte). Mitglieder von
team-lila-devs dürfen Wartungsfenster in ihrem Namespace
anlegen – ohne neue RoleBinding.
Aufgabe 10 (6 Punkte). Bestelle über die
Plattform-API von Tag 8 eine Datenbank suchdb der Größe S
in team-lila. Sie muss READY True melden.
Aufgabe 11 (6 Punkte). Jeder Mandanten-Namespace
bekommt automatisch eine ConfigMap plattform-kontakt mit
den Schlüsseln team (aus dem Namespace-Label) und
hilfe: [email protected] – auch die bestehenden.
Aufgabe 12 (7 Punkte). Deployment info
in team-lila (Image
ghcr.io/stefanprodan/podinfo:6.11.0, Port 9898) mit Service
info (Port-Name http). Prometheus soll seine
Metriken einsammeln; das Ziel muss up sein.
Aufgabe 13 (6 Punkte). Aufzeichnungsregel
namespace:http_requests:rate5m: Anfragen pro Sekunde aller
Pods in team-lila, über 5 Minuten, summiert je
Namespace.
Aufgabe 14 (7 Punkte). Spiele die folgende Störung ein und behebe sie so, dass der Pod dauerhaft läuft:
# auf cp1 – Teil der Aufgabe
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.yamlAufgabe 15 (5 Punkte). In Mandanten-Namespaces dürfen keine Pods mit privilegierten Containern mehr angelegt werden.
Aufgabe 16 (5 Punkte). Wie viele
kritische Schwachstellen hat
nginx:1.31-alpine? Schreibe nur die Zahl in
~/cnpe/anhang-b/kritisch.txt.
Aufgabe 17 (5 Punkte). Die Prüferin
prueferin (Benutzer, keine Gruppe) darf in
team-lila alles lesen außer Secrets – und
nichts ändern.
Lösungen
Aufgabe 1
# auf 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 -lErwartet:
namespace/team-lila created
5
Aufgabe 2
# auf 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 -cErwartet:
deployment.apps/suche created
deployment "suche" successfully rolled out
1 worker1
1 worker2
Aufgabe 3
# auf 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"}'Erwartet (gekürzt):
priorityclass.scheduling.k8s.io/batch-niedrig created
deployment.apps/index created
deployment.apps/index patched
deployment "index" successfully rolled out
1000 Never
Aufgabe 4
# auf 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.yamlErwartet:
appproject.argoproj.io/team-lila created
Aufgabe 5
# auf 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"}'Erwartet:
application.argoproj.io/team-lila-suche created
team-lila Synced Healthy
Aufgabe 6
# auf 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
# zurück über 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"}'Erwartet (gekürzt):
1 ImagePullBackOff
2 Running
…
Synced Healthy
nginx:1.31-alpine
k rollout undo oder ein Patch am Deployment geben 0
Punkte: Self-Heal dreht sie zurück, und Git zeigt weiter das kaputte
Image.
Aufgabe 7
# auf 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"}'Erwartet:
rollout.argoproj.io/preise created
rollout "preise" image updated
Paused step=1
rollout 'preise' promoted
Healthy argoproj/rollouts-demo:green
Aufgabe 8
# auf 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 -
# Gegenprobe: muss abgelehnt werden
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 -Erwartet:
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
Aufgabe 9
# auf 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-devsErwartet:
clusterrole.rbac.authorization.k8s.io/plattform-wartungsfenster-edit created
yes
Die RoleBinding für team-lila-devs auf edit
hat Kyverno in Aufgabe 1 angelegt – die Aggregation erweitert
edit.
Aufgabe 10
# auf 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 suchdbErwartet:
datenbank.plattform.lab/suchdb created
NAME GROESSE ADRESSE SYNCED READY RESPONSIVE COMPOSITION AGE
suchdb S suchdb True True True datenbank-postgres 70s
Aufgabe 11
# auf 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"}'Erwartet:
generatingpolicy.policies.kyverno.io/team-kontakt created
5
{"hilfe":"[email protected]","team":"lila"}
Fünf Mandanten: team-blue, team-green, team-green-staging, team-rot, team-lila.
Aufgabe 12
# auf 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
# der ServiceMonitor braucht einen Port-Namen
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 -
# ohne diese Freigabe: context deadline exceeded (Tag 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)"'Erwartet (gekürzt):
servicemonitor.monitoring.coreos.com/info created
networkpolicy.networking.k8s.io/allow-monitoring created
info up
Direkt nach dem Anlegen zeigt das Ziel unknown – der
erste Abruf steht noch aus.
Aufgabe 13
# auf 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])"'Erwartet (Wert schwankt):
prometheusrule.monitoring.coreos.com/info created
team-lila 0.009559333333333335
Aufgabe 14
# auf 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=150sErwartet:
OOMKilled
deployment.apps/bericht resource requirements updated
deployment "bericht" successfully rolled out
Aufgabe 15
# auf 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}}]}}'Erwartet:
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
Der Namespace ci (Buildah läuft privilegiert, Tag 6)
trägt kein tier=tenant – die Pipeline läuft weiter. Pod
Security Admission auf restricted wäre die eingebaute
Alternative.
Aufgabe 16
# auf 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.txtErwartet (am Tag der Kurserstellung):
0
Aufgabe 17
# auf 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=prueferinErwartet:
rolebinding.rbac.authorization.k8s.io/prueferin-view created
yes
no
no
view lässt Secrets bewusst aus – genau die
Anforderung.
Auswertung
Zähle die Punkte der gelösten Aufgaben. Unter 64: Wiederhole die Tage
der verlorenen Bereiche und schreibe die Prüfung in einer Woche noch
einmal – mit eigenen Namen statt lila, damit du nicht
auswendig tippst.