Mock exam 2

A second, completely fresh paper: 15 timed tasks, 120 minutes, 100 points, weighted like the real blueprint (15/25/25/20/15) with zero overlap against Mock exam 1 (same domains, different competencies). You just need make full with nothing extra staged. Task 5 pulls one public Helm chart, so keep normal internet access available; everything else runs locally. Your clock and score are tracked independently from paper 1.

Lab layers
make full
Tasks
15
Target
70+ / 100
Your score
0/ 100

The clock

persists across reloads
time remaining
120:00
Click a task's dot once its grading command passes. Your score updates above.

Same rules as paper 1: start the clock, stay out of the curriculum pages and answers below, and wait until the end to run the grading block. Official docs and --help are allowed, just like on exam day. If the grader can't observe it, it doesn't count. Aim for 70+ overall with zero domains at 0. If a task stalls, note the time, skip it, and come back.

Tasks

click a task to collapse it · click the dot to score it

Create StorageClass mock2-retain using the local-path provisioner (rancher.io/local-path) with volumeBindingMode: WaitForFirstConsumer and reclaimPolicy: Retain. In default, create a 1Gi PVC named mock2-data using that class, plus a sleeping busybox:1.37 pod named mock2-pod that mounts it. The claim must reach Bound and its backing PV must carry the Retain reclaim policy.

Create namespace mock2-net containing a Deployment and Service both named web (image ghcr.io/nginxinc/nginx-unprivileged:1.27-alpine, port 8080, 1 replica), plus two idle busybox:1.37 pods: trusted (labeled access=web) and other. Default-deny all ingress and egress across the namespace, then open just enough traffic so trusted can fetch http://web:8080 by Service name while other is completely blocked.

Create Argo CD Application mock2-demo pointing at the already-registered platform repo (http://gitea.lab:3000/lab/platform.git), path demo-app/base, deploying into namespace mock2-argo (have Argo CD create it) with automated sync, prune, and self-heal turned on. Prove self-heal works: scale the live Deployment to 5 by hand and watch Argo CD snap it right back to 2 without any git commit or extra kubectl command.

Author Task mock2-stamp so it emits a result named stamp starting with mock2-, and Task mock2-echo so it accepts a param msg and prints it. Wire both into Pipeline mock2-relay (in default) as pipeline tasks named stamp and echo, with echo running after stamp and receiving that result as its param. Run the pipeline: the PipelineRun must reach Succeeded and the echo step's logs must print the stamp.

Using Flux, create a HelmRepository for https://stefanprodan.github.io/podinfo and a HelmRelease named mock2-podinfo (in flux-system) installing the podinfo chart into namespace mock2-helm (create it yourself or let Flux do it) with 2 replicas set via values. The release must report Ready with both replicas serving.

Using the installed CloudNativePG operator, spin up a single-instance Postgres cluster named mock2-pg in default (1Gi storage, light resource footprint). Wait until the operator reports it healthy, then write the auto-generated application username from its connection Secret to /tmp/mock2-pg-user.txt.

Author a kro ResourceGraphDefinition named mock2space defining kind Mock2Space (schema: string team, plus string cpu defaulting to "1") that expands into a Namespace named after team and a ResourceQuota tenant-quota inside it capping requests.cpu at the given value. Create instance green (team mock2-green, cpu "2") and confirm both the namespace and quota come up cleanly.

Create WorkflowTemplate mock2-greeter in default with an input parameter who (default nobody) and a single step printing hello <who>. Submit Workflow mock2-hello referencing that template and overriding who to platform. It must reach Succeeded with hello platform in its logs. (Make sure it runs under a ServiceAccount carrying the executor rights the curriculum warns about, or it will fail no matter how clean your template is.)

Create a PrometheusRule that records namespace:pods_running:count, the count of Running pods per namespace derived from kube_pod_status_phase. Prove Prometheus is evaluating it by querying the new series through the API and getting non-empty results.

Query the lab's Loki with LogQL to save every log line from namespace argocd over the last hour mentioning mock2-demo (task 3's Application; its self-heal left footprints in the application controller logs) into /tmp/mock2-logs.txt, one raw line per line with no timestamps or JSON wrapping. The file must be non-empty and every line must contain mock2-demo. (Skipped task 3? Any Application name works to practice, though the grader specifically greps for mock2-demo.)

kube-prometheus-stack ships with a permanently firing Watchdog alert. Without modifying any rule, create a 2-hour Alertmanager silence matching alertname=Watchdog with a comment containing mock2, and verify the alert flips to suppressed. (Expire the silence after grading; it's a dead-man's-switch alert meant to prove the alerting pipeline is alive.)

Using the installed policy engine, automatically generate a default-deny NetworkPolicy named default-deny in every newly created namespace whose name begins with mock2-gen, and only those, leaving all other exam namespaces untouched. Prove both halves: a matching namespace gets the policy, and a non-matching one doesn't.

Create Secret mock2-token in team-b with key token = s3cr3t, applying only its sealed form to the cluster. Encrypt it for this cluster's controller with kubeseal, apply the SealedSecret, and let the controller materialize the real Secret.

Create namespace mock2-restricted enforcing the restricted Pod Security Standard. Run pod hardened there (image ghcr.io/nginxinc/nginx-unprivileged:1.27-alpine) with a compliant securityContext so it reaches Running. A bare kubectl run in that namespace must be rejected.

The Trivy Operator tracks a CIS compliance rollup for this cluster. Pull its current fail count straight from the report object's status (not a dashboard) and write that bare number to /tmp/mock2-cis.txt. (On a freshly built cluster, the rollup stays empty until its scheduled cron fires hours later, so nudging the operator to populate it immediately is part of the challenge.)

Grading

grade partial credit strictly

Run the full block below; each check prints what earns the points. Running make grade EXAM=2 executes this exact block straight out of this page, so paper and grader always stay in lockstep.

# 1
kubectl get sc mock2-retain -o jsonpath='{.volumeBindingMode}/{.reclaimPolicy}{"\n"}'                # WaitForFirstConsumer/Retain
kubectl get pvc mock2-data -o jsonpath='{.status.phase}{"\n"}'                                       # Bound
kubectl get pv "$(kubectl get pvc mock2-data -o jsonpath='{.spec.volumeName}')" \
  -o jsonpath='{.spec.persistentVolumeReclaimPolicy}{"\n"}'                                          # Retain
# 2
kubectl -n mock2-net exec trusted -- wget -qO- -T 3 http://web:8080 >/dev/null && echo trusted-reaches-web
kubectl -n mock2-net exec other -- wget -qO- -T 3 http://web:8080 >/dev/null 2>&1 || echo other-blocked
kubectl -n mock2-net get netpol --no-headers | wc -l                                                 # at least a deny + your allows
# 3
kubectl -n argocd get app mock2-demo -o jsonpath='{.status.sync.status}/{.status.health.status}{"\n"}'   # Synced/Healthy
kubectl -n argocd get app mock2-demo -o jsonpath='{.spec.syncPolicy.automated.selfHeal}{"\n"}'       # true
kubectl -n mock2-argo scale deploy demo --replicas=5 && sleep 25 && \
kubectl -n mock2-argo get deploy demo -o jsonpath='{.spec.replicas}{"\n"}'                           # 2 (Argo CD put it back)
# 4
kubectl get pipelinerun -l tekton.dev/pipeline=mock2-relay \
  -o jsonpath='{.items[*].status.conditions[?(@.type=="Succeeded")].status}' | grep -o True | head -1   # True (a run Succeeded; failed retries don't hurt)
kubectl logs -l tekton.dev/pipelineTask=echo | grep mock2-                                           # the stamp crossed the task boundary
# 5
flux get helmrelease mock2-podinfo -n flux-system                                                    # Ready True
kubectl -n mock2-helm get deploy mock2-podinfo -o jsonpath='{.status.readyReplicas}{"\n"}'           # 2
# 6
kubectl get clusters.postgresql.cnpg.io mock2-pg -o jsonpath='{.status.phase}{"\n"}'                 # Cluster in healthy state
kubectl get clusters.postgresql.cnpg.io mock2-pg -o jsonpath='{.status.readyInstances}{"\n"}'        # 1
[ "$(cat /tmp/mock2-pg-user.txt)" = "$(kubectl get secret mock2-pg-app -o jsonpath='{.data.username}' | base64 -d)" ] && echo user-matches
# 7
kubectl get rgd mock2space -o jsonpath='{.status.state}{"\n"}'                                       # Active
kubectl get mock2space green -o name                                                                 # the instance exists
kubectl get ns mock2-green -o jsonpath='{.status.phase}{"\n"}'                                       # Active
kubectl -n mock2-green get resourcequota tenant-quota -o jsonpath='{.spec.hard.requests\.cpu}{"\n"}' # 2
# 8
kubectl get workflowtemplate mock2-greeter -o name                                                   # the template exists
kubectl get wf mock2-hello -o jsonpath='{.status.phase}{"\n"}'                                       # Succeeded
kubectl logs -l workflows.argoproj.io/workflow=mock2-hello -c main | grep 'hello platform'           # the override landed
# 9
kubectl -n monitoring port-forward svc/prometheus-kube-prometheus-prometheus 19090:9090 & sleep 3
curl -s 'http://localhost:19090/api/v1/query?query=namespace:pods_running:count' | jq '.data.result | length'   # > 0: recording
# 10
test -s /tmp/mock2-logs.txt && echo non-empty
test "$(grep -c mock2-demo /tmp/mock2-logs.txt)" = "$(wc -l < /tmp/mock2-logs.txt | tr -d ' ')" && echo every-line-matches
# 11
kubectl -n monitoring port-forward svc/prometheus-kube-prometheus-alertmanager 19093:9093 & sleep 3
curl -s http://localhost:19093/api/v2/silences | jq -r '.[] | select(.status.state=="active") | .matchers[].value'   # Watchdog
curl -s 'http://localhost:19093/api/v2/alerts?filter=alertname%3D%22Watchdog%22' | jq -r '.[0].status.state'         # suppressed
# 12
kubectl create ns mock2-gen-1 --dry-run=client -o yaml | kubectl apply -f - ; sleep 5; kubectl -n mock2-gen-1 get netpol default-deny -o name   # generated
kubectl create ns mock2-plain --dry-run=client -o yaml | kubectl apply -f - ; sleep 5; kubectl -n mock2-plain get netpol --no-headers | wc -l   # 0: the scope held
# 13
kubectl -n team-b get sealedsecret mock2-token -o name                                               # the git-safe form
kubectl -n team-b get secret mock2-token -o jsonpath='{.data.token}' | base64 -d; echo               # s3cr3t (controller unsealed it)
# 14
kubectl get ns mock2-restricted -o jsonpath='{.metadata.labels.pod-security\.kubernetes\.io/enforce}{"\n"}'   # restricted
kubectl -n mock2-restricted get pod hardened -o jsonpath='{.status.phase}{"\n"}'                     # Running
kubectl -n mock2-restricted run naked --image=busybox:1.37 --restart=Never -- sleep 5 2>&1 | grep -ci 'violate'   # >=1 (rejected)
# 15
[ "$(cat /tmp/mock2-cis.txt)" = "$(kubectl get "$(kubectl get clustercompliancereport -o name | grep -m1 cis)" \
  -o jsonpath='{.status.summary.failCount}')" ] && echo fail-count-matches                          # the CIS report carries its benchmark version in its name

Answers

open only after grading

Just the key moves here; each points back to the curriculum section where we unpack the full pattern.

1 · storage class, claim, binding

Straight from section 1.3. The classic gotcha is waiting for the PVC to bind before the pod exists: with WaitForFirstConsumer, sitting Pending with no events is completely expected until mock2-pod mounts it. Set reclaimPolicy: Retain on the StorageClass, and the PV inherits it at provision time.

2 · NetworkPolicy isolation

Follow examples/multitenancy/team-a.yaml (sections 1.1 and 1.4): a namespace-wide default-deny, an egress rule allowing DNS to kube-dns, and a matched pair of rules: egress from access=web pods to web on port 8080, plus ingress to web from access=web. Both ends have to open, and forgetting DNS breaks trusted before it even tries port 8080.

3 · self-healing Application

Covered in section 2.2: define an Application with source repoURL/path, destination.namespace: mock2-argo, syncPolicy.automated: {prune: true, selfHeal: true}, and syncOptions: [CreateNamespace=true]. Since the lab already registered the repo, no credentials setup is needed. Self-heal snaps your manual scale-up back to replicas: 2 within seconds.

4 · Tekton results

Covered in section 2.4: mock2-stamp writes its value to $(results.stamp.path), and the Pipeline passes params: [{name: msg, value: $(tasks.stamp.results.stamp)}] into echo (notice that references the pipeline task name, not the Task object name) alongside runAfter: [stamp] (even though the result reference already orders them). If the run hangs forever, you've referenced a result that was never emitted; tkn pr describe will call it right out.

5 · Flux HelmRelease

Covered in section 2.3: run flux create source helm podinfo --url=https://stefanprodan.github.io/podinfo, then flux create helmrelease mock2-podinfo --source=HelmRepository/podinfo --chart=podinfo --target-namespace=mock2-helm --create-target-namespace --release-name=mock2-podinfo --interval=5m with --values (or an inline spec) setting replicaCount: 2. Don't miss --release-name: when targetNamespace is set without it, Flux defaults to <targetNamespace>-<name>, so the chart creates mock2-helm-mock2-podinfo instead of mock2-podinfo and the grader misses it.

6 · CloudNativePG

Covered in section 3.3. A minimal Cluster (postgresql.cnpg.io/v1) with instances: 1 and storage: {size: 1Gi} is all you need. Watch kubectl get clusters.postgresql.cnpg.io -w until phase hits "Cluster in healthy state." The operator creates Secret mock2-pg-app, where jsonpath='{.data.username}' | base64 -d yields app. (We intentionally run this in default: examples/crossplane/pg-cluster.yaml explains why a default-deny tenant namespace hangs initdb forever.)

7 · kro RGD

Take section 3.6's tenantspace example and rename it: schema kind Mock2Space with team: string and cpu: string | default="1", expanding into ns (a Namespace named ${schema.spec.team}) and quota (placed in ${ns.metadata.name} with requests.cpu: ${schema.spec.cpu}). Watch out for the YAML flow-style trap from section 3.6: quote ${…} expressions whenever they appear inside flow-style braces. Instance: kind Mock2Space, name green, spec: {team: mock2-green, cpu: "2"}.

8 · WorkflowTemplate + parameter

Covered in section 3.4: define a WorkflowTemplate whose spec.arguments.parameters declares who with a default and a step echoing {{workflow.parameters.who}}, then submit a Workflow using workflowTemplateRef: {name: mock2-greeter} with its own arguments.parameters override. Give the ServiceAccount create and patch on workflowtaskresults.argoproj.io. That's the same executor RBAC requirement as paper 1, called out in the prompt since this task is testing templates, not RBAC tricks.

9 · recording rule

Covered in section 4.2: create a PrometheusRule in monitoring with groups[].rules[]: {record: "namespace:pods_running:count", expr: 'count by (namespace) (kube_pod_status_phase{phase="Running"} == 1)'}. Our lab's Prometheus picks up all rules (ruleSelectorNilUsesHelmValues=false); on a stock install you'd need the matching release label, just like with ServiceMonitors. Give it a minute or two before querying so the operator can reload the rule file and finish an evaluation cycle (~90s in our test runs).

10 · LogQL extraction

Covered in section 4.3: port-forward Loki (kubectl -n monitoring port-forward svc/loki 3100:3100), then run curl -sG http://localhost:3100/loki/api/v1/query_range --data-urlencode 'query={namespace="argocd"} |= "mock2-demo"' --data-urlencode 'limit=1000' | jq -r '.data.result[].values[][1] | rtrimstr("\n")' into the file (query_range already defaults to the past hour). That rtrimstr really matters: Alloy stores lines with trailing newlines, so skipping it prints blank lines between entries and trips the every-line-matches check. logcli works great too if you have it handy.

11 · Alertmanager silence

Covered in section 4.2. The Alertmanager pod already carries amtool: run kubectl -n monitoring exec alertmanager-prometheus-kube-prometheus-alertmanager-0 -- amtool silence add alertname=Watchdog --duration=2h --comment=mock2 --author=you --alertmanager.url=http://localhost:9093, or POST JSON to /api/v2/silences over a port-forward. Notice the architecture: a silenced alert keeps firing in Prometheus while Alertmanager suppresses the notification, which is why the grader checks for suppressed instead of resolved. Clean up afterward with amtool silence expire <id>.

12 · generate policy

Covered in section 5.2: author a GeneratingPolicy (policies.kyverno.io/v1) named, say, mock2-generate-default-deny. Match CREATE on namespaces in matchConstraints.resourceRules, narrow it via matchConditions with object.metadata.name.startsWith('mock2-gen'), build the NetworkPolicy in a variable as a list of dyn() maps (name: default-deny, empty podSelector, policyTypes: [Ingress, Egress]), and emit it with generate: [{expression: "generator.Apply(object.metadata.name, variables.deny)"}]. Skip matchConditions and mock2-plain gets a policy too, failing the second check. (Classic ClusterPolicy generate rules are rejected outright by Kyverno 1.20.) You don't need extra RBAC here: the chart's kyverno:background-controller ClusterRole already grants create/update/delete on networkpolicies (check for RBACPermissionsGranted in the policy status), and generation fires within a second. You only need an aggregated ClusterRole (labeled rbac.kyverno.io/aggregate-to-background-controller: "true") when generating kinds outside that default set.

13 · sealed secret

Straight from section 5.1: kubectl -n team-b create secret generic mock2-token --from-literal=token=s3cr3t --dry-run=client -o yaml | kubeseal --controller-namespace kube-system --controller-name sealed-secrets -o yaml, then apply the result. The two controller flags are the gotcha: kubeseal's defaults assume a controller name our chart didn't use.

14 · restricted PSS

Covered in section 5.3. Label the namespace pod-security.kubernetes.io/enforce: restricted. Give the pod runAsNonRoot: true, seccompProfile: {type: RuntimeDefault}, and per-container allowPrivilegeEscalation: false plus capabilities: {drop: ["ALL"]} (grab examples/demo-app/ if you want a working template). Even better: trigger the bare-pod rejection once and read the error message: it literally lists every missing field for you.

15 · compliance report

Covered in section 5.4, with two realistic traps. First, the report isn't just named cis: kubectl get clustercompliancereport shows k8s-cis-1.23 because the benchmark version rides in the name, so always discover, never guess. Second, on a fresh cluster status.summary stays empty until the 6-hour cron fires, and any spec edit forces an immediate reconcile: kubectl patch clustercompliancereport k8s-cis-1.23 --type merge -p '{"spec":{"cron":"* * * * *"}}' populates the summary within a second (patch the cron back afterward). Then dump -o jsonpath='{.status.summary.failCount}' > /tmp/mock2-cis.txt. That's the core takeaway: compliance lives in queryable Kubernetes objects with real status fields, just like everything else on the platform.

After scoring

two papers, one picture

Lay this breakdown right beside your Mock exam 1 scores: any domain that came in low on both papers is a real gap, not an off day, and that's where your next evenings belong. Cross-check it against the dashboard's weak-spots panel too; when all three point at the same domain, trust them.

Clean up parents first: three of these namespaces have controllers standing right behind them, and deleting a namespace out from under its controller just triggers a fast rebuild. In our runs, Argo CD recreated mock2-argo in 15 seconds, Flux reinstalled mock2-helm in 70 seconds, and the kro instance holds onto mock2-green until you delete it.

# controllers first, or they rebuild what you are deleting
kubectl -n argocd delete app mock2-demo
flux -n flux-system delete helmrelease mock2-podinfo --silent
flux -n flux-system delete source helm podinfo --silent
kubectl delete mock2space green; kubectl delete rgd mock2space
# names below task text never fixed are yours; --ignore-not-found keeps the sweep going
kubectl delete generatingpolicy mock2-generate-default-deny --ignore-not-found
# now the namespaces stay gone
kubectl delete ns mock2-net mock2-argo mock2-helm mock2-green mock2-gen-1 mock2-plain mock2-restricted --ignore-not-found
# the default-namespace objects and the rest of the paper trail
kubectl delete pod mock2-pod; kubectl delete pvc mock2-data
kubectl delete pv "$(kubectl get pv -o jsonpath='{.items[?(@.spec.claimRef.name=="mock2-data")].metadata.name}')"   # Retain kept it, now Released
kubectl delete sc mock2-retain
kubectl delete cluster.postgresql.cnpg.io mock2-pg
kubectl delete pipelinerun -l tekton.dev/pipeline=mock2-relay
kubectl delete pipeline mock2-relay; kubectl delete task mock2-stamp mock2-echo
kubectl delete wf mock2-hello; kubectl delete workflowtemplate mock2-greeter
kubectl delete sa mock2-wf --ignore-not-found; kubectl delete role,rolebinding mock2-wf-taskresults --ignore-not-found
kubectl -n monitoring delete prometheusrule mock2-recording --ignore-not-found
kubectl -n team-b delete sealedsecret mock2-token          # its Secret goes with it
kubectl patch clustercompliancereport k8s-cis-1.23 --type merge -p '{"spec":{"cron":"0 */6 * * *"}}'   # if you sped it up
pkill -f 'port-forward.*1909[03]'                          # the two grading port-forwards, if you pasted by hand
# and let the Watchdog page someone again (both amtool calls need the url flag)
kubectl -n monitoring exec alertmanager-prometheus-kube-prometheus-alertmanager-0 -- sh -c \
  'am=http://localhost:9093; amtool silence expire $(amtool silence query -q alertname=Watchdog --alertmanager.url=$am) --alertmanager.url=$am'