Skip to content
CNPE · Chapter 18 of 22 Day 16: Exam training – eight tasks against the clock

Day 16: Exam training – eight tasks against the clock

Goal: Practise the exam situation: read tasks quickly, solve them with few commands, check them yourself and move on. Eight tasks from all five domains, each with a time limit · Duration: approx. 60 min · Prerequisite: Day 15

Briefing

  • Two hours, 15 to 20 tasks: about seven minutes per task. Most points are not lost through lack of knowledge but through time – a task you get stuck on for 20 minutes costs you three others.
  • Rules for the exam:
Rule Why
Read the task twice: mark namespace, names, numbers Wrong namespace = 0 points
Check the context (k config current-context) if the task names one Tasks often run on different clusters
Generate instead of typing: k create … --dry-run=client -o yaml Fewer typos, faster
k explain field.subfield instead of searching the docs Offline, instant
One check command after every task Find mistakes immediately, not at the end
Stuck? Make a note, move on, come back at the end Time for the easy points
  • The only permitted help is the Kubernetes documentation and the Kubernetes blog. For Argo CD, Kyverno, Prometheus & co. this means: you must know the syntax – or k explain helps, because their CRDs have schemas.

The tasks take place in a new tenant team-rot. Set a timer for each task.

Task 1: New tenant (4 min)

Create the namespace team-rot as a tenant (labels team=rot, tier=tenant). Team Rot gets 3 CPU requests instead of 2. Check that the quota is correct.

Solution

# on cp1
mkdir -p ~/cnpe/tag16 && cd ~/cnpe/tag16
k create ns team-rot --dry-run=client -o yaml | k label --local -f - team=rot tier=tenant -o yaml | k apply -f -
# Budget via the annotation from the Day 9 Challenge
k annotate ns team-rot plattform.lab/cpu=3
sleep 10
k -n team-rot get quota team-quota -o jsonpath='{.spec.hard.requests\.cpu}{"\n"}'

Expected:

namespace/team-rot created
namespace/team-rot annotated
3

If you skipped the Day 9 Challenge, you get 2 here – then k -n team-rot patch quota does not help (Kyverno resets it); the policy itself has to be changed.

Task 2: Scaling (5 min)

Deployment katalog in team-rot, image nginx:1.31-alpine, CPU request 50 m, memory 32 Mi. It should scale between 2 and 5 replicas at 60 % CPU.

Solution

# on cp1
k -n team-rot create deployment katalog --image=nginx:1.31-alpine --replicas=2
k -n team-rot set resources deploy/katalog --requests=cpu=50m,memory=32Mi
k -n team-rot autoscale deploy katalog --cpu=60% --min=2 --max=5
k -n team-rot get hpa katalog -o jsonpath='{.spec.minReplicas}-{.spec.maxReplicas} {.spec.metrics[0].resource.target.averageUtilization}{"\n"}'

Expected:

deployment.apps/katalog created
deployment.apps/katalog resource requirements updated
horizontalpodautoscaler.autoscaling/katalog autoscaled
2-5 60

Task 3: Protecting maintenance (2 min)

During maintenance, at least one replica of katalog must always be running.

Solution

# on cp1
k -n team-rot create pdb katalog --selector=app=katalog --min-available=1
k -n team-rot get pdb katalog -o jsonpath='{.spec.minAvailable}{"\n"}'

Expected:

poddisruptionbudget.policy/katalog created
1

Task 4: Fault (5 min)

A colleague rolled out kaputt. Find out why it is not running and fix it. The database server is called katalog-db, port 5432, database katalog.

# on cp1 – preparation (part of the task, not of the solution)
k -n team-rot create deployment kaputt --image=busybox:1.37 -- \
  sh -c 'echo $DB_URL | grep -q postgres || { echo DB_URL fehlt >&2; exit 1; }; sleep 3600'
sleep 30

Solution

# on cp1
k -n team-rot logs deploy/kaputt
k -n team-rot set env deploy/kaputt DB_URL=postgres://katalog-db:5432/katalog
k -n team-rot rollout status deploy/kaputt --timeout=90s

Expected:

DB_URL fehlt
deployment.apps/kaputt env updated
deployment "kaputt" successfully rolled out

Task 5: Alert (6 min)

An alert KatalogNichtVerfuegbar with severity: critical and team: rot should fire when fewer than 2 replicas of katalog have been available for longer than 2 minutes.

Solution

# on cp1
cat > regel-verfuegbar.yaml <<'EOF'
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: katalog
  namespace: team-rot
spec:
  groups:
  - name: katalog
    rules:
    - alert: KatalogNichtVerfuegbar
      expr: kube_deployment_status_replicas_available{namespace="team-rot",deployment="katalog"} < 2
      for: 2m
      labels:
        severity: critical
        team: rot
EOF
k apply -f regel-verfuegbar.yaml
sleep 45
curl -s http://172.16.0.126:30090/api/v1/rules | jq -r '.data.groups[] | select(.name=="katalog") | .rules[] | "\(.name) \(.health)"'

Expected:

prometheusrule.monitoring.coreos.com/katalog created
KatalogNichtVerfuegbar ok

health: ok means: the query is valid and is being evaluated. The metric comes from kube-state-metrics – kube_deployment_ + Tab in the Prometheus UI shows all of them.

Task 6: Policy in audit mode (6 min)

Deployments in namespaces with team=rot must carry the label app. Violations should only be reported. Show the result for Team Rot’s Deployments.

Solution

# on cp1
cat > app-label.yaml <<'EOF'
apiVersion: policies.kyverno.io/v1
kind: ValidatingPolicy
metadata:
  name: app-label
spec:
  validationActions: [Audit]
  evaluation:
    background:
      enabled: true
  matchConstraints:
    resourceRules:
    - apiGroups: [apps]
      apiVersions: [v1]
      operations: [CREATE, UPDATE]
      resources: [deployments]
    namespaceSelector:
      matchLabels: {team: rot}
  validations:
  - expression: object.metadata.?labels[?"app"].orValue("") != ""
    message: Deployments brauchen das Label app
EOF
k apply -f app-label.yaml
sleep 50
k -n team-rot get policyreport -o json \
  | jq -r '.items[] | select(.scope.kind=="Deployment") | .scope.name as $d | .results[] | select(.policy=="app-label") | "\($d) \(.result)"'

Expected:

validatingpolicy.policies.kyverno.io/app-label created
katalog pass
kaputt pass

k create deployment sets app=<name> by itself – both pass.

Task 7: GitOps takes over (8 min)

From now on, katalog should come from Git: directory apps/team-rot/katalog in the platform repo, an Application team-rot-katalog with automatic sync. The HPA stays in charge of the replica count.

Solution

# on cp1
cd ~/cnpe/plattform && git pull -q
mkdir -p apps/team-rot/katalog
cat > apps/team-rot/katalog/deployment.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: katalog
  name: katalog
  namespace: team-rot
spec:                                  # no replicas – Day 2
  selector:
    matchLabels:
      app: katalog
  template:
    metadata:
      labels:
        app: katalog
    spec:
      containers:
        - image: nginx:1.31-alpine
          name: nginx
          resources:
            requests:
              cpu: 50m
              memory: 32Mi
EOF
git add -A && git commit -qm 'katalog für Team Rot' && git push -q
cat > ~/cnpe/tag16/katalog-app.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: team-rot-katalog
  namespace: argocd
spec:
  project: default
  source:
    repoURL: http://172.16.0.126:30300/platform/plattform.git
    targetRevision: main
    path: apps/team-rot/katalog
  destination:
    server: https://kubernetes.default.svc
    namespace: team-rot
  syncPolicy:
    automated: {prune: true, selfHeal: true}
EOF
k apply -f ~/cnpe/tag16/katalog-app.yaml
sleep 30
k -n argocd get application team-rot-katalog -o jsonpath='{.status.sync.status} {.status.health.status}{"\n"}'
k -n team-rot get deploy katalog

Expected:

application.argoproj.io/team-rot-katalog created
Synced Healthy
NAME      READY   UP-TO-DATE   AVAILABLE   AGE
katalog   2/2     2            2           3m8s

The container name (nginx) must match what k create deployment generated – otherwise Argo CD adds a second container next to it.

Task 8: Let monitoring in (3 min)

Prometheus (namespace monitoring) must be able to reach Team Rot’s pods on port 80.

Solution

# on cp1
cat > allow-monitoring.yaml <<'EOF'
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-monitoring
  namespace: team-rot
spec:
  podSelector: {}
  policyTypes: [Ingress]
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: monitoring
    ports:
    - {port: 80, protocol: TCP}
EOF
k apply -f allow-monitoring.yaml
IP=$(k -n team-rot get pod -l app=katalog -o jsonpath='{.items[0].status.podIP}')
k -n monitoring run t --rm -i --restart=Never --image=curlimages/curl:8.17.0 --command -- \
  curl -s -o /dev/null -w '%{http_code}\n' -m 5 http://$IP 2>/dev/null | head -1

Expected:

networkpolicy.networking.k8s.io/allow-monitoring created
200

Evaluation

Task Domain Time Done?
1 Tenant Platform architecture 4
2 Scaling Platform architecture 5
3 Maintenance Platform architecture 2
4 Fault Observability & operations 5
5 Alert Observability & operations 6
6 Policy Security & policy 6
7 GitOps GitOps & CD 8
8 Network Security & policy 3

Target time: 39 minutes. If you took more than 50, repeat the slow tasks tomorrow without the solution.

Checkpoint

# on cp1
k -n team-rot get quota,hpa,pdb,prometheusrule,netpol -o name | wc -l
k -n team-rot get deploy -o custom-columns=NAME:.metadata.name,READY:.status.readyReplicas
k -n argocd get application team-rot-katalog -o jsonpath='{.status.sync.status}{"\n"}'

Expected:

7
NAME      READY
kaputt    1
katalog   2
Synced

Interview Note

  • How do you deal with time pressure? Sort tasks by points and effort, check after every task, don’t get stuck.
  • How do you know the syntax of a CRD without internet access? k explain <kind>.spec --recursive – also for Argo CD, Kyverno, Prometheus Operator.

Enterprise Note

  • The same procedures belong in runbooks and templates – what takes eight minutes in the exam should be a pull request against a template in everyday work.

Contents

More