Appearance
The local lab topologykubectl addresses one kind control-plane node, connected to two worker nodes on your computer.Your terminal>_Control planeAPI · schedulerloops · etcdWorker 1Worker 2kind / kv-labOne disposable cluster. Three nodes.
20 module labs4 practice challengeskind 0.33.0Kubernetes 1.37

Your local workbench

Set up a three-node lab cluster on macOS or Windows with WSL 2.

Use the same bundle on both platforms. Setup installs checksum-verified copies of kind v0.33.0 and kubectl v1.37.0 inside the extracted bundle.

macOS

  1. Install and start Docker Desktop for Mac. Choose Apple Silicon or Intel to match your Mac.
  2. Open Bash in Terminal with bash. Check python3 --version and install Python 3 for macOS if needed.

Windows with WSL 2

  1. In administrator PowerShell, run wsl --install -d Ubuntu. Restart if prompted and open Ubuntu to finish setup. Run wsl -l -v in PowerShell to confirm Ubuntu shows version 2. Microsoft’s WSL setup guide covers existing installs and upgrades.
  2. Install Docker Desktop for Windows and start it in Linux containers mode. Turn on the WSL 2 engine and enable Ubuntu under Settings → Resources → WSL Integration. Docker’s WSL setup guide shows the settings.
  3. Switch to the Ubuntu terminal for every command below. Run sudo apt update and sudo apt install curl python3 unzip.

1. Download the labs and create the cluster

Download the lab bundle and extract it. On Windows, extract it inside your Ubuntu home directory, for example with unzip /path/to/kv-labs.zip -d ~/kv-labs. In Bash, change to the extracted directory containing setup.sh and run:

bash setup.sh && source ./lab-env.sh

Expect one control-plane node and two workers, all Ready. Run source ./lab-env.sh in any new Bash session from the extracted directory. See the bundle README if Docker or setup reports an error.

2. Run your first exercise

From the extracted directory, run the reconciliation lab. Its runner creates the lab namespace and shows the ReplicaSet replacing a deleted Pod. The subshell leaves you in the bundle directory for the next exercise.

(
  cd m02 && bash run.sh && bash cleanup.sh
)

Each investigation includes its own requirements, expected results, and cleanup. Keep all files for an exercise together.

3. Remove the lab cluster

When you finish all exercises, save any lab data you want to keep, then delete the disposable cluster from the same terminal.

source ./lab-env.sh && kind delete cluster --name kv-lab

Choose an investigation.

24 exercises
m01 · Foundations

Compare a container process and a Pod

Lessons
Guided exercise

Objective

Run a standalone process and a Kubernetes Pod, then identify which address and port actually served an HTTP request.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Docker must be running and able to pull the BusyBox and nginx teaching images.
Initial state

There is no m01 Pod. The Docker command starts a short-lived BusyBox process, while resources.yaml declares a separate nginx Pod.

Expected results
  • The standalone process prints its hostname and user ID, then exits.
  • Pod m01 gets an IP and the nginx server answers on port 80 inside the Pod.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Run a standalone container and create the separate Kubernetes Pod.

(
  set -euo pipefail
  docker run --rm --name kv-lab-m01-process busybox:1.37.0 sh -c 'hostname; id; echo process-complete'
  kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/m01 --timeout=180s
)
Diagnose

Inspect the Pod IP, node, image and container state. The Pod is the object declared by resources.yaml.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get pod m01 -o wide
  kubectl --context kind-kv-lab -n kv-lab describe pod m01
)
Verify

Confirm the Pod has an IP and returns the stock nginx HTML.

(
  set -euo pipefail
  test -n "$(kubectl --context kind-kv-lab -n kv-lab get pod m01 -o jsonpath='{.status.podIP}')"
  kubectl --context kind-kv-lab -n kv-lab exec m01 -- wget -qO- -T 3 http://127.0.0.1:80 | grep -F 'Welcome to nginx!'
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Use exec to make a request inside the Pod network namespace. Here 127.0.0.1 refers to the Pod itself.

    kubectl --context kind-kv-lab -n kv-lab exec m01 -- wget -qO- -T 3 http://127.0.0.1:80
Official references
Exercise files 5 files
m02 · Foundations

Watch a ReplicaSet replace a deleted Pod

Lessons
Guided exercise

Objective

Trace Deployment ownership and verify that the controller replaces a Pod with a new identity.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • The Deployment needs enough capacity to schedule two small nginx Pods.
Initial state

The setup applies Deployment m02 with two replicas and waits for both to become available.

Expected results
  • A ReplicaSet owns the original Pod.
  • After you delete one Pod, its UID disappears and the same Deployment again has two ready replicas.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Apply the Deployment and wait for it to become available.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
  kubectl --context kind-kv-lab -n kv-lab rollout status deployment/m02 --timeout=180s
)
Diagnose

Find the controllers and inspect the Pod owner. The owner is a ReplicaSet, which is itself owned by the Deployment.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get deployment m02
  kubectl --context kind-kv-lab -n kv-lab get replicasets -l app=m02
  kubectl --context kind-kv-lab -n kv-lab get pods -l app=m02 -o jsonpath='{range .items[*]}{.metadata.name}{" "}{.metadata.ownerReferences[0].kind}{"/"}{.metadata.ownerReferences[0].name}{"\n"}{end}'
)
Verify

Check the ready replica count and compare the current Pod names against your initial list.

(
  set -euo pipefail
  test "$(kubectl --context kind-kv-lab -n kv-lab get deployment m02 -o jsonpath='{.status.readyReplicas}')" = 2
  kubectl --context kind-kv-lab -n kv-lab get pods -l app=m02 -o wide
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Save the victim UID, delete the Pod, then wait for the replacement. The Deployment specification still asks for two replicas.

    (
      set -euo pipefail
      old=$(kubectl --context kind-kv-lab -n kv-lab get pods -l app=m02 -o jsonpath='{.items[0].metadata.name}')
      old_uid=$(kubectl --context kind-kv-lab -n kv-lab get pod "$old" -o jsonpath='{.metadata.uid}')
      kubectl --context kind-kv-lab -n kv-lab delete pod "$old" --wait=true
      kubectl --context kind-kv-lab -n kv-lab rollout status deployment/m02 --timeout=180s
      kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod -l app=m02 --timeout=180s
      uids=$(kubectl --context kind-kv-lab -n kv-lab get pods -l app=m02 -o jsonpath='{.items[*].metadata.uid}')
      case " $uids " in *" $old_uid "*) echo 'Old Pod UID still present' >&2; false;; esac
    )
Official references
Exercise files 5 files
m03 · Foundations

Update a ConfigMap without replacing it

Lessons
Guided exercise

Objective

Use an explicit context and label selector, then distinguish object identity from resource version.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Leave your current kubectl context alone. The commands explicitly target the local lab.
Initial state

ConfigMap m03 has the lab=m03 label and data.message=hello. No application Pods are needed.

Expected results
  • The selector finds the ConfigMap in kv-lab.
  • A new annotation appears, resourceVersion changes, and the UID stays the same.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Create the ConfigMap.

kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
Diagnose

Read the ConfigMap by its lab label. Compare the selected context with the default one shown by current-context.

(
  set -euo pipefail
  kubectl config current-context
  kubectl --context kind-kv-lab -n kv-lab get configmaps -l lab=m03 -o yaml
)
Verify

Confirm the declared data is intact and the annotation is set.

(
  set -euo pipefail
  test "$(kubectl --context kind-kv-lab -n kv-lab get cm m03 -o jsonpath='{.data.message}')" = hello
  test -n "$(kubectl --context kind-kv-lab -n kv-lab get cm m03 -o jsonpath='{.metadata.annotations.experiment}')"
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Capture the UID and version, write a unique annotation, then re-read both values. Treat resourceVersion as an opaque value.

    (
      set -euo pipefail
      uid=$(kubectl --context kind-kv-lab -n kv-lab get cm m03 -o jsonpath='{.metadata.uid}')
      before=$(kubectl --context kind-kv-lab -n kv-lab get cm m03 -o jsonpath='{.metadata.resourceVersion}')
      value=$(python3 -c 'import uuid; print("metadata-" + uuid.uuid4().hex)')
      kubectl --context kind-kv-lab -n kv-lab annotate cm m03 "experiment=$value" --overwrite
      kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
      test "$(kubectl --context kind-kv-lab -n kv-lab get cm m03 -o jsonpath='{.metadata.uid}')" = "$uid"
      test "$(kubectl --context kind-kv-lab -n kv-lab get cm m03 -o jsonpath='{.metadata.resourceVersion}')" != "$before"
      test "$(kubectl --context kind-kv-lab -n kv-lab get cm m03 -o jsonpath='{.metadata.annotations.experiment}')" = "$value"
    )
Official references
Exercise files 5 files
m04 · Foundations

Trace init ordering and a shared volume

Lessons
Guided exercise

Objective

Read init-container status and logs, then prove that two app containers can see the same emptyDir file.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • The accompanying container is a regular second container. The Secret contains teaching data.
Initial state

Pod m04 uses a ConfigMap and a Secret. Its init container prepares a file, then its app and companion containers start.

Expected results
  • The init container finishes successfully before startup of the app.
  • The app logs prepared and the greeting. The companion can read the shared file.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Apply the Pod and config objects and wait for readiness.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/m04 --timeout=180s
)
Diagnose

Read the init status and inspect logs from the three named containers separately.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get pod m04 -o jsonpath='{.status.initContainerStatuses[0].state.terminated.reason}{"\n"}'
  kubectl --context kind-kv-lab -n kv-lab logs m04 -c prepare
  kubectl --context kind-kv-lab -n kv-lab logs m04 -c app
  kubectl --context kind-kv-lab -n kv-lab logs m04 -c companion --tail=2
)
Verify

Check successful init completion and matching volume contents.

(
  set -euo pipefail
  test "$(kubectl --context kind-kv-lab -n kv-lab get pod m04 -o jsonpath='{.status.initContainerStatuses[0].state.terminated.exitCode}')" = 0
  app=$(kubectl --context kind-kv-lab -n kv-lab exec m04 -c app -- cat /work/ready)
  companion=$(kubectl --context kind-kv-lab -n kv-lab exec m04 -c companion -- cat /work/ready)
  test "$app" = prepared
  test "$companion" = "$app"
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Read the same path from each running container. Both mounts refer to the Pod-scoped emptyDir.

    (
      set -euo pipefail
      kubectl --context kind-kv-lab -n kv-lab exec m04 -c app -- cat /work/ready
      kubectl --context kind-kv-lab -n kv-lab exec m04 -c companion -- cat /work/ready
    )
Official references
Exercise files 5 files
m05 · Foundations

Remove a ready backend without restarting it

Lessons
Guided exercise

Objective

Observe how a readiness failure updates EndpointSlices, then restore readiness and roll back a Pod template change.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Give probe and EndpointSlice updates time to converge. The lab intentionally changes one of two web Pods.
Initial state

Deployment m05 is available, and both Pods initially satisfy the readiness probe because /tmp/ready exists.

Expected results
  • One Pod becomes unready and its EndpointSlice entry reports ready=false while its restart count stays stable.
  • Restoring the sentinel returns the Pod to Ready. A separate template edit creates a rollout that you can undo.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Apply the Deployment and Service and wait for two available replicas.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
  kubectl --context kind-kv-lab -n kv-lab rollout status deployment/m05 --timeout=180s
)
Diagnose

Read the readiness probe and see the backend conditions before making a change.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get deployment m05 -o yaml
  kubectl --context kind-kv-lab -n kv-lab get endpointslices -l kubernetes.io/service-name=m05 -o yaml
)
Verify

Confirm the Deployment is available and undo removed the release annotation.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab rollout status deployment/m05 --timeout=180s
  test "$(kubectl --context kind-kv-lab -n kv-lab get deployment m05 -o jsonpath='{.status.readyReplicas}')" = 2
  test -z "$(kubectl --context kind-kv-lab -n kv-lab get deployment m05 -o jsonpath='{.spec.template.metadata.annotations.release}')"
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Remove the sentinel from one Pod, wait for Ready=false, and check that the restart count stays the same.

    (
      set -euo pipefail
      pod=$(kubectl --context kind-kv-lab -n kv-lab get pods -l app=m05 -o jsonpath='{.items[0].metadata.name}')
      before=$(kubectl --context kind-kv-lab -n kv-lab get pod "$pod" -o jsonpath='{.status.containerStatuses[0].restartCount}')
      kubectl --context kind-kv-lab -n kv-lab exec "$pod" -- rm /tmp/ready
      kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready=false "pod/$pod" --timeout=60s
      kubectl --context kind-kv-lab -n kv-lab wait --for="jsonpath={.endpoints[?(@.targetRef.name==\"$pod\")].conditions.ready}=false" endpointslice -l kubernetes.io/service-name=m05 --timeout=60s
      test "$(kubectl --context kind-kv-lab -n kv-lab get pod "$pod" -o jsonpath='{.status.containerStatuses[0].restartCount}')" = "$before"
      kubectl --context kind-kv-lab -n kv-lab get endpointslices -l kubernetes.io/service-name=m05 -o yaml
      kubectl --context kind-kv-lab -n kv-lab exec "$pod" -- touch /tmp/ready
      kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready "pod/$pod" --timeout=60s
    )
  2. Edit the Pod template, wait for the rollout, and then undo it. The template edit changes the revision.

    (
      set -euo pipefail
      kubectl --context kind-kv-lab -n kv-lab patch deployment m05 --type merge -p '{"spec":{"template":{"metadata":{"annotations":{"release":"two"}}}}}'
      kubectl --context kind-kv-lab -n kv-lab rollout status deployment/m05 --timeout=180s
      kubectl --context kind-kv-lab -n kv-lab rollout history deployment/m05
      kubectl --context kind-kv-lab -n kv-lab rollout undo deployment/m05
    )
Official references
Exercise files 5 files
m06 · Foundations

Restore HTTP to a Service with no backends

Lessons
Troubleshooting challenge

Objective

Trace an HTTP failure from a client Pod to a Service selector and repair routing without changing the healthy web Deployment.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Run the commands from the m06 directory. The default kind DNS and Service dataplane are sufficient.
Initial state

The starter creates Deployment m06, Service m06, and Pod m06-client. It first confirms HTTP works, then changes the selector to app=no-match. The web Pods stay Ready and DNS still resolves.

Expected results
  • Service m06 selects Pods labeled app=m06 and has at least one ready backend.
  • A new HTTP request from m06-client receives the nginx page. The Deployment and client stay in place.
Run, inspect & clean up
Setup

Create the fixture and stop with DNS working and HTTP deliberately broken.

bash start.sh
Diagnose

Confirm the web Pods are ready and record their app label.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get deployment m06
  kubectl --context kind-kv-lab -n kv-lab get pods -l app=m06 --show-labels
)

Compare the Service selector with the Pod labels. The EndpointSlice should have no ready backend.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get service m06 -o jsonpath='{.spec.selector}{"\n"}'
  kubectl --context kind-kv-lab -n kv-lab get endpointslices -l kubernetes.io/service-name=m06 -o yaml
)

Resolve the Service name from the same client, then probe a new HTTP connection. Expect the DNS lookup and the command itself to succeed, with the HTTP probe reporting HTTP_FAILED.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab exec m06-client -- nslookup m06.kv-lab.svc.cluster.local
  kubectl --context kind-kv-lab -n kv-lab exec m06-client -- sh -c 'if wget -qO- -T 2 http://m06 >/dev/null; then echo HTTP_OK; else echo HTTP_FAILED; fi'
)
Verify

Wait for a ready backend and a successful request from m06-client.

bash verify.sh
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. DNS resolves the Service name to its stable address. The selector determines which Pod addresses can serve traffic. Change the selector to match the existing web Pods.

    kubectl --context kind-kv-lab -n kv-lab patch service m06 --type merge -p '{"spec":{"selector":{"app":"m06"}}}'
  2. Use Verify in the Run, inspect & clean up section. EndpointSlice and dataplane updates can take a moment to converge.

Official references
Exercise files 8 files
m07 · Intermediate

Explain why a Pod is Pending

Lessons
Guided exercise

Objective

Use scheduling conditions and node labels to trace an impossible placement constraint.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Use the default lab nodes. Leave their labels unchanged for this exercise.
Initial state

m07-allowed can schedule, while m07-pending requests a node label absent from the cluster. The runner waits for the expected status of both.

Expected results
  • m07-pending is Pending with PodScheduled=False and reason Unschedulable.
  • m07-allowed is Ready and reports Burstable QoS.
Run, inspect & clean up
Setup

Create the two Pod fixtures.

bash run.sh
Diagnose

Read the scheduling condition and compare the requested selector to actual node labels.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab describe pod m07-pending
  kubectl --context kind-kv-lab -n kv-lab get pod m07-pending -o jsonpath='{.spec.nodeSelector}{"\n"}'
  kubectl --context kind-kv-lab get nodes --show-labels
)
Verify

Confirm the two distinct outcomes.

(
  set -euo pipefail
  test "$(kubectl --context kind-kv-lab -n kv-lab get pod m07-pending -o 'jsonpath={.status.conditions[?(@.type=="PodScheduled")].reason}')" = Unschedulable
  test "$(kubectl --context kind-kv-lab -n kv-lab get pod m07-allowed -o jsonpath='{.status.qosClass}')" = Burstable
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/m07-allowed --timeout=60s
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. The selector is a hard scheduling requirement, so the scheduler rejects every node. Burstable QoS is a separate consequence of the allowed Pod resource configuration. Leave the two fixtures as they are to preserve the comparison.

Official references
Exercise files 5 files
m08 · Intermediate

Restore one client path through a NetworkPolicy

Lessons
Troubleshooting challenge

Objective

Use observed HTTP traffic and Pod labels to reason about a deny policy, then allow the intended client.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Use the pinned kind networking configuration. A functioning policy implementation is necessary for the deny test.
Initial state

Setup confirms a working HTTP path from m08-client to m08, applies deny.yaml, and waits for a new request to fail.

Expected results
  • The labeled client succeeds after applying the narrow allow rule.
  • The deny policy remains in place and the allow policy names the intended client through its selector.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Confirm the baseline succeeds before applying the deny policy.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
  kubectl --context kind-kv-lab -n kv-lab rollout status deployment/m08 --timeout=180s
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/m08-client --timeout=180s
  result=
  for attempt in $(seq 1 30); do
    result=$(kubectl --context kind-kv-lab -n kv-lab exec m08-client -- sh -c 'if wget -qO- -T 2 http://m08 >/dev/null 2>&1; then echo HTTP_OK; else echo HTTP_FAILED; fi') || exit 1
    [ "$result" = HTTP_OK ] && break
    sleep 1
  done
  printf "%s\n" "$result"
  test "$result" = HTTP_OK
  kubectl --context kind-kv-lab -n kv-lab apply -f deny.yaml
  result=
  for attempt in $(seq 1 30); do
    result=$(kubectl --context kind-kv-lab -n kv-lab exec m08-client -- sh -c 'if wget -qO- -T 2 http://m08 >/dev/null 2>&1; then echo HTTP_OK; else echo HTTP_FAILED; fi') || exit 1
    [ "$result" = HTTP_FAILED ] && break
    sleep 1
  done
  printf "%s\n" "$result"
  test "$result" = HTTP_FAILED
)
Diagnose

Inspect the two workloads, the deny policy, and the ready Service backends. Then confirm a fresh request now fails.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get pods -l lab=m08 --show-labels
  kubectl --context kind-kv-lab -n kv-lab get networkpolicy -l lab=m08 -o yaml
  kubectl --context kind-kv-lab -n kv-lab get endpointslices -l kubernetes.io/service-name=m08
  result=
  for attempt in $(seq 1 30); do
    result=$(kubectl --context kind-kv-lab -n kv-lab exec m08-client -- sh -c 'if wget -qO- -T 2 http://m08 >/dev/null 2>&1; then echo HTTP_OK; else echo HTTP_FAILED; fi') || exit 1
    [ "$result" = HTTP_FAILED ] && break
    sleep 1
  done
  printf "%s\n" "$result"
  test "$result" = HTTP_FAILED
)
Verify

Check both policies and make a new HTTP request from the same client.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get -f deny.yaml -f allow.yaml
  result=
  for attempt in $(seq 1 30); do
    result=$(kubectl --context kind-kv-lab -n kv-lab exec m08-client -- sh -c 'if wget -qO- -T 2 http://m08 >/dev/null 2>&1; then echo HTTP_OK; else echo HTTP_FAILED; fi') || exit 1
    [ "$result" = HTTP_OK ] && break
    sleep 1
  done
  printf "%s\n" "$result"
  test "$result" = HTTP_OK
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Apply the allow policy. Policies are additive, so this grants the selected client access without deleting the deny policy.

    kubectl --context kind-kv-lab -n kv-lab apply -f allow.yaml
Official references
Exercise files 7 files
m09 · Intermediate

Keep a PVC file across Pod replacement

Lessons
Guided exercise

Objective

Follow the PVC to its bound volume and verify that replacing its consumer leaves stored content intact.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Use the default local-path provisioner. This lab demonstrates a Pod replacement on local storage.
Initial state

The fixture creates PVC m09 and its consumer Pod. The default StorageClass provisions a local volume once the consumer is placed.

Expected results
  • The claim becomes Bound.
  • A new Pod reads the original marker from /data/proof.txt and uses the same PV.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Create the claim and its first consumer.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/m09 --timeout=180s
)
Diagnose

Inspect the claim, StorageClass binding mode, mount and backing PV.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get pvc m09
  kubectl --context kind-kv-lab get storageclass
  volume=$(kubectl --context kind-kv-lab -n kv-lab get pvc m09 -o jsonpath='{.spec.volumeName}')
  kubectl --context kind-kv-lab get pv "$volume"
  kubectl --context kind-kv-lab -n kv-lab describe pod m09
)
Verify

Read the existing marker from the replacement Pod.

(
  set -euo pipefail
  test "$(kubectl --context kind-kv-lab -n kv-lab get pvc m09 -o jsonpath='{.status.phase}')" = Bound
  test "$(kubectl --context kind-kv-lab -n kv-lab exec m09 -- cat /data/proof.txt)" = survives-pod-replacement
)
Clean up

Remove the Pod and claim. The lab provisioner will reclaim the volume and delete the teaching file.

bash cleanup.sh
Solution
  1. Write the marker, replace only the Pod, and compare the old and new UIDs and volume bindings.

    (
      set -euo pipefail
      old=$(kubectl --context kind-kv-lab -n kv-lab get pod m09 -o jsonpath='{.metadata.uid}')
      volume=$(kubectl --context kind-kv-lab -n kv-lab get pvc m09 -o jsonpath='{.spec.volumeName}')
      kubectl --context kind-kv-lab -n kv-lab exec m09 -- sh -c 'echo survives-pod-replacement > /data/proof.txt'
      kubectl --context kind-kv-lab -n kv-lab delete pod m09 --wait=true
      kubectl --context kind-kv-lab -n kv-lab apply -f consumer.yaml
      kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/m09 --timeout=180s
      test "$(kubectl --context kind-kv-lab -n kv-lab get pod m09 -o jsonpath='{.metadata.uid}')" != "$old"
      test "$(kubectl --context kind-kv-lab -n kv-lab get pvc m09 -o jsonpath='{.spec.volumeName}')" = "$volume"
    )
Official references
Exercise files 6 files
m10 · Intermediate

Compare identity, node coverage, and completion

Lessons
Guided exercise

Objective

Read the status of a StatefulSet, DaemonSet, Job, suspended CronJob, and disruption budget.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Use the regular three-node topology. Leave the nodes schedulable and the CronJob suspended.
Initial state

The runner creates one StatefulSet replica, a DaemonSet, a short-lived Job, a suspended CronJob and a PodDisruptionBudget.

Expected results
  • StatefulSet m10 has a Ready m10-0 Pod. DaemonSet m10-agent has a Ready agent on each eligible node.
  • Job m10-job completes and the suspended CronJob does not create a scheduled run.
Run, inspect & clean up
Setup

Create the workload controllers and wait for the StatefulSet and Job.

bash run.sh
Diagnose

Inspect the stable ordinal and the DaemonSet node placement, then read the Job result and scheduled workload state.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get pod m10-0 -o wide
  kubectl --context kind-kv-lab -n kv-lab get daemonset m10-agent
  kubectl --context kind-kv-lab -n kv-lab get pods -l app=m10-agent -o wide
  kubectl --context kind-kv-lab -n kv-lab logs job/m10-job
  kubectl --context kind-kv-lab -n kv-lab get cronjob m10-schedule
  kubectl --context kind-kv-lab -n kv-lab describe pdb m10
)
Verify

Check the distinct controller signals.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/m10-0 --timeout=90s
  kubectl --context kind-kv-lab -n kv-lab rollout status daemonset/m10-agent --timeout=90s
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Complete job/m10-job --timeout=90s
  test "$(kubectl --context kind-kv-lab -n kv-lab get cronjob m10-schedule -o jsonpath='{.spec.suspend}')" = true
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Read identity from the StatefulSet ordinal, coverage from the DaemonSet desired count, and success from the Job Complete condition. The suspended CronJob holds a schedule for future Jobs. A disruption budget governs voluntary disruptions to matching Pods.

Official references
Exercise files 5 files
m11 · Intermediate

Demonstrate a least-privilege ServiceAccount

Lessons
Guided exercise

Objective

Read the Role and its binding, prove the allowed and denied actions, and inspect security settings on the Pod.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • The disposable kind administrator must be able to impersonate the exercise ServiceAccount.
Initial state

Setup makes a reader Role and a RoleBinding for m11-reader, then starts a restricted Pod that uses the ServiceAccount without an automatic token mount.

Expected results
  • The account can list Pods in kv-lab and is denied a Secret read.
  • The process runs as UID 1000 and the Pod has automatic token mounting disabled.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Create the ServiceAccount, Role, RoleBinding and Pod.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/m11 --timeout=180s
)
Diagnose

Inspect the binding subject and the actions allowed by the referenced Role.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get role m11-reader -o yaml
  kubectl --context kind-kv-lab -n kv-lab get rolebinding m11-reader -o yaml
  kubectl --context kind-kv-lab -n kv-lab get pod m11 -o yaml
)
Verify

Impersonate the account for allow and deny checks. Then inspect the running container UID and token-mount setting.

(
  set -euo pipefail
  identity=system:serviceaccount:kv-lab:m11-reader
  test "$(kubectl --context kind-kv-lab -n kv-lab auth can-i list pods --as="$identity")" = yes
  test "$(kubectl --context kind-kv-lab -n kv-lab auth can-i get secrets --as="$identity")" = no
  test "$(kubectl --context kind-kv-lab -n kv-lab exec m11 -- id -u)" = 1000
  test "$(kubectl --context kind-kv-lab -n kv-lab get pod m11 -o jsonpath='{.spec.automountServiceAccountToken}')" = false
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. The binding grants the account listed in its subject the namespaced verbs from the Role. Kubernetes authorizes the API action independently from the UID and capabilities inside the container.

Official references
Exercise files 5 files
m12 · Intermediate

Separate a crashing process from a routing fault

Lessons
Troubleshooting challenge

Objective

Use logs and Service evidence to identify two independent failures, then restore routing to healthy Pods.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Keep m12-crash in its deliberate failed state. Fix only the Service.
Initial state

m12-crash exits because required config is missing. Deployment m12 is healthy, but Service m12 uses a selector that matches none of its Pods.

Expected results
  • You can identify the configuration fault from the crash logs.
  • Service m12 routes traffic to the healthy Deployment while the separate crash fixture is untouched.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Create the independent crash and routing fixtures.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
  kubectl --context kind-kv-lab -n kv-lab rollout status deployment/m12 --timeout=180s
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/m12-client --timeout=180s
)
Diagnose

Wait for the process to emit the deliberate configuration error. Use the Pod description to inspect its restart and last exit state.

(
  set -euo pipefail
  logs=
  for attempt in $(seq 1 45); do
    logs=$(kubectl --context kind-kv-lab -n kv-lab logs m12-crash 2>/dev/null) || true
    [[ "$logs" = *'fatal: missing required config'* ]] && break
    sleep 1
  done
  printf '%s\n' "$logs"
  [[ "$logs" = *'fatal: missing required config'* ]]
  kubectl --context kind-kv-lab -n kv-lab describe pod m12-crash
)

Compare healthy web Pod labels, Service selector, EndpointSlices and a failing client request.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get pods -l app=m12 --show-labels
  kubectl --context kind-kv-lab -n kv-lab get service m12 -o yaml
  kubectl --context kind-kv-lab -n kv-lab get endpointslices -l kubernetes.io/service-name=m12 -o yaml
  result=
  for attempt in $(seq 1 30); do
    result=$(kubectl --context kind-kv-lab -n kv-lab exec m12-client -- sh -c 'if wget -qO- -T 2 http://m12 >/dev/null 2>&1; then echo HTTP_OK; else echo HTTP_FAILED; fi') || exit 1
    [ "$result" = HTTP_FAILED ] && break
    sleep 1
  done
  printf "%s\n" "$result"
  test "$result" = HTTP_FAILED
)
Verify

Require success from the original client and confirm that a separate crash fixture still exists.

(
  set -euo pipefail
  result=
  for attempt in $(seq 1 30); do
    result=$(kubectl --context kind-kv-lab -n kv-lab exec m12-client -- sh -c 'if wget -qO- -T 2 http://m12 >/dev/null 2>&1; then echo HTTP_OK; else echo HTTP_FAILED; fi') || exit 1
    [ "$result" = HTTP_OK ] && break
    sleep 1
  done
  printf "%s\n" "$result"
  test "$result" = HTTP_OK
  kubectl --context kind-kv-lab -n kv-lab get pod m12-crash
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Match the Service selector to the web Pods. The unrelated crash does not explain why the Service selected no backends.

    kubectl --context kind-kv-lab -n kv-lab patch service m12 --type merge -p '{"spec":{"selector":{"app":"m12"}}}'
Official references
Exercise files 5 files
m13 · Intermediate

Render Kustomize and diagnose unavailable HPA metrics

Lessons
Guided exercise

Objective

Inspect the generated configuration and determine why the baseline HPA cannot calculate CPU utilization.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • The default kind profile has no Metrics Server. Leave it uninstalled to reproduce the expected condition.
Initial state

The local Kustomization declares two replicas and generates a ConfigMap. Applying it creates a CPU-target HPA and its target Deployment.

Expected results
  • The rendered configuration contains a generated ConfigMap and two replicas.
  • The HPA target resolves, but ScalingActive=False reports FailedGetResourceMetric.
Run, inspect & clean up
Setup

Render and apply the Kustomization, then wait for the target Deployment.

bash run.sh
Diagnose

Inspect the rendered YAML, the target Deployment CPU requests and the HPA conditions. The generated ConfigMap is not mounted by this Deployment.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab kustomize .
  kubectl --context kind-kv-lab -n kv-lab get deployment m13 -o yaml
  kubectl --context kind-kv-lab -n kv-lab describe hpa m13
)
Verify

Wait for the metrics failure reason and confirm that the target Deployment remains available.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab wait --for='jsonpath={.status.conditions[?(@.type=="ScalingActive")].reason}=FailedGetResourceMetric' hpa/m13 --timeout=90s
  kubectl --context kind-kv-lab -n kv-lab rollout status deployment/m13 --timeout=90s
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. The HPA needs resource metrics from the metrics API to compute observed CPU utilization. It uses the declared CPU requests when metrics arrive. Here the expected outcome is diagnosing missing metrics; the exercise does not require traffic generation or a scaling event.

Official references
Exercise files 6 files
m14 · Advanced

Resolve a field conflict and release a finalizer

Lessons
Guided exercise

Objective

Observe two independent API mechanisms: field ownership during a write and a finalizer blocking deletion.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Only remove the teaching finalizer on this ConfigMap. It has no external state to clean up.
Initial state

Field manager kv-gitops owns declared data on ConfigMap m14. A different manifest proposes a conflicting value.

Expected results
  • An apply by kv-human fails with a field conflict.
  • After adding the teaching finalizer, deletion sets a timestamp. Removing the finalizer completes deletion.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Establish the original field ownership.

kubectl --context kind-kv-lab -n kv-lab apply --server-side --field-manager=kv-gitops -f resources.yaml
Diagnose

Inspect field ownership and require a genuine conflict from the second manager.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get configmap m14 -o yaml --show-managed-fields
  if result=$(kubectl --context kind-kv-lab -n kv-lab apply --server-side --field-manager=kv-human -f conflict.yaml 2>&1); then
    echo 'Expected an SSA field conflict' >&2; exit 1
  fi
  printf '%s\n' "$result" | grep -i conflict
)
Verify

Wait for the ConfigMap to disappear from the API.

kubectl --context kind-kv-lab -n kv-lab wait --for=delete configmap/m14 --timeout=30s
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Resolve intent with the current owner. Keep the original writer and value for this exercise. The finalizer below demonstrates a separate deletion mechanism. Start with the clean teaching ConfigMap, before any finalizers have been added.

  2. Request deletion with a finalizer present and inspect the timestamp. Remove the lab marker after confirming that this fixture has no external work.

    (
      set -euo pipefail
      test -z "$(kubectl --context kind-kv-lab -n kv-lab get configmap m14 -o jsonpath='{.metadata.finalizers[*]}')"
      kubectl --context kind-kv-lab -n kv-lab patch configmap m14 --type merge -p '{"metadata":{"finalizers":["labs.kv.example/hold"]}}'
      kubectl --context kind-kv-lab -n kv-lab delete configmap m14 --wait=false
      test -n "$(kubectl --context kind-kv-lab -n kv-lab get configmap m14 -o jsonpath='{.metadata.deletionTimestamp}')"
      kubectl --context kind-kv-lab -n kv-lab get configmap m14 -o yaml
      bash release-hold.sh
    )
Official references
Exercise files 7 files
m15 · Advanced

Read Leases and verify a convergent apply

Lessons
Guided exercise

Objective

Compare a manually written Lease with control-plane Leases and check whether repeated desired state changes object identity.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • The pinned kind cluster uses kubeadm control-plane components and includes their Leases in kube-system.
Initial state

The lab starts with ConfigMap m15 and a manually created Lease. The fixture has no election contender or Lease-renewal process.

Expected results
  • Lease m15 identifies manual-demo as its holder.
  • Repeatedly applying the ConfigMap preserves its UID and data.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Create the teaching Lease and ConfigMap.

kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
Diagnose

Compare the teaching Lease to the control-plane Leases and read the ConfigMap.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get lease m15 -o yaml
  kubectl --context kind-kv-lab -n kube-system get leases
  kubectl --context kind-kv-lab -n kv-lab get configmap m15 -o yaml
)

Open a short watch. The initial output is the current ConfigMap. With no changes made, the watch can end at the request deadline.

(
  set -euo pipefail
  status=0
  watch=$(kubectl --context kind-kv-lab -n kv-lab get configmap m15 --watch --request-timeout=6s -o name 2>&1) || status=$?
  printf '%s\n' "$watch"
  printf '%s\n' "$watch" | grep -Fx configmap/m15
  if [ "$status" -ne 0 ]; then
    printf '%s\n' "$watch" | grep -Ei 'timeout|timed out|context deadline'
  fi
)
Verify

Check the named holder and the ConfigMap data independently.

(
  set -euo pipefail
  test "$(kubectl --context kind-kv-lab -n kv-lab get lease m15 -o jsonpath='{.spec.holderIdentity}')" = manual-demo
  kubectl --context kind-kv-lab -n kv-lab get configmap m15 -o yaml
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Save identity and data, apply the file again, and compare. A controller can reconcile repeatedly without replacing the object.

    (
      set -euo pipefail
      before=$(kubectl --context kind-kv-lab -n kv-lab get configmap m15 -o jsonpath='{.metadata.uid}{.data}')
      kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
      kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
      test "$(kubectl --context kind-kv-lab -n kv-lab get configmap m15 -o jsonpath='{.metadata.uid}{.data}')" = "$before"
    )
Official references
Exercise files 5 files
m16 · Advanced

Reconcile a WebApp and repair a deleted child

Lessons
Guided exercise

Objective

Install a custom API and use a small polling reconciler to bring its owned objects back to the declared state.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Python 3 runs the reconciler locally with your lab kubeconfig. Leave the shared WebApp CRD installed until you finish m16 and m20.
Initial state

The WebApp CRD is established and WebApp m16 declares one replica. The reconciler has yet to create any children.

Expected results
  • The WebApp owns the Deployment and ConfigMap. Repeated reconciliation keeps the Deployment identity stable.
  • Deleting the ConfigMap is repaired, and declaring two replicas results in two ready Pods.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Install the CRD, wait for it to be established, then create the custom resource.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab apply -f crd.yaml
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Established crd/webapps.labs.kv.example --timeout=60s
  kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
)
Diagnose

Read the custom-resource spec and inspect which children exist before running the reconciler.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get webapp m16 -o yaml
  kubectl --context kind-kv-lab -n kv-lab get deployment,configmap -l lab=m16
)
Verify

Confirm that the ConfigMap was recreated with the right owner and two replicas are Ready.

(
  set -euo pipefail
  test "$(kubectl --context kind-kv-lab -n kv-lab get configmap m16 -o jsonpath='{.metadata.ownerReferences[0].uid}')" = "$(kubectl --context kind-kv-lab -n kv-lab get webapp m16 -o jsonpath='{.metadata.uid}')"
  test "$(kubectl --context kind-kv-lab -n kv-lab get deployment m16 -o jsonpath='{.status.readyReplicas}')" = 2
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Run the reconciler, check the owner reference, then re-run it and verify the Deployment UID and generation are stable.

    (
      set -euo pipefail
      python3 webapp-reconciler.py --once
      kubectl --context kind-kv-lab -n kv-lab rollout status deployment/m16 --timeout=180s
      before=$(kubectl --context kind-kv-lab -n kv-lab get deployment m16 -o jsonpath='{.metadata.uid}:{.metadata.generation}')
      python3 webapp-reconciler.py --iterations 2 --interval 1
      test "$(kubectl --context kind-kv-lab -n kv-lab get deployment m16 -o jsonpath='{.metadata.uid}:{.metadata.generation}')" = "$before"
      test "$(kubectl --context kind-kv-lab -n kv-lab get deployment m16 -o jsonpath='{.metadata.ownerReferences[0].uid}')" = "$(kubectl --context kind-kv-lab -n kv-lab get webapp m16 -o jsonpath='{.metadata.uid}')"
    )
  2. Delete the owned ConfigMap and declare two replicas on the parent. Run a reconciliation pass to repair the child and update the Deployment.

    (
      set -euo pipefail
      kubectl --context kind-kv-lab -n kv-lab delete configmap m16
      kubectl --context kind-kv-lab -n kv-lab patch webapp m16 --type merge -p '{"spec":{"replicas":2}}'
      python3 webapp-reconciler.py --once
      kubectl --context kind-kv-lab -n kv-lab rollout status deployment/m16 --timeout=180s
    )
Official references
Exercise files 7 files
m17 · Advanced

Identify a container memory-limit termination

Lessons
Guided exercise

Objective

Distinguish a container OOM termination from node pressure using the Pod state and node conditions.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Use the provided 16 MiB limit. The fixture uses a bounded write to a memory-backed volume.
Initial state

The fixture starts m17-oom. Its process fills a small memory-backed volume and reaches the container memory limit.

Expected results
  • The container terminates with reason OOMKilled.
  • The lab nodes remain Ready.
Run, inspect & clean up
Setup

Run the bounded fixture and wait for its terminal state.

bash run.sh
Diagnose

Inspect the container state and memory settings and view the worker conditions.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab describe pod m17-oom
  kubectl --context kind-kv-lab get nodes
)
Verify

Assert the termination reason directly and confirm node readiness.

(
  set -euo pipefail
  test "$(kubectl --context kind-kv-lab -n kv-lab get pod m17-oom -o jsonpath='{.status.containerStatuses[0].state.terminated.reason}')" = OOMKilled
  kubectl --context kind-kv-lab wait --for=condition=Ready nodes --all --timeout=90s
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Use state.terminated.reason for the diagnosis. The container memory limit constrains this workload while the node continues operating. Kubernetes Pod eviction is a different mechanism with its own reason and events.

Official references
Exercise files 5 files
m18 · Advanced

Capture a private etcd snapshot

Lessons
Guided exercise

Objective

Save a known API object in an etcd snapshot and establish that a private backup file exists outside the cluster.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Docker must be accessible. Keep the private snapshot directory for the optional restore. The snapshot contains the lab API state, including Secrets.
Initial state

The source kind cluster is running and the starter directory contains resources.yaml for a ConfigMap marker.

Expected results
  • The ConfigMap contains captured-before-disaster.
  • A non-empty kv-lab.db exists in the private directory printed by the runner. The source node no longer has the temporary copy.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Create the marker and identify the source etcd Pod.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
  kubectl --context kind-kv-lab -n kube-system get pod etcd-kv-lab-control-plane -o wide
)
Diagnose

Read the known marker before taking the snapshot and check the source API availability.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get configmap m18 -o yaml
  kubectl --context kind-kv-lab get --raw=/readyz
)
Verify

Check the source marker and both file locations.

(
  set -euo pipefail
  directory=$(python3 backup-path.py m18)
  test -s "$directory/kv-lab.db"
  test "$(kubectl --context kind-kv-lab -n kv-lab get configmap m18 -o jsonpath='{.data.marker}')" = captured-before-disaster
  docker exec kv-lab-control-plane test ! -e /var/lib/etcd/kv-lab.db
)
Clean up

Remove the marker when done with capture. The private snapshot remains available for the restore exercise.

bash cleanup.sh
Solution
  1. Run the snapshot procedure. It requests a consistent snapshot with the source etcd TLS files, copies it into the private directory, and removes the node copy.

    bash run.sh
Official references

Restore the snapshot into a new cluster

Guided exercise
Objective

Restore the saved marker through a separate API server and verify the original cluster still responds.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Complete snapshot capture first and keep the same private backup directory.
  • The restore needs Docker resources for a second single-node cluster. No kv-recovery cluster may exist. Read RECOVERY.md before starting.
Initial state

The source API is healthy and kv-lab.db is present. No recovery cluster exists.

Expected results
  • The recovered API returns captured-before-disaster from ConfigMap m18.
  • The source API still answers readiness checks. Cleanup removes only kv-recovery.
Run, inspect & clean up
Setup

Confirm the snapshot exists and the recovery name is free.

(
  set -euo pipefail
  directory=$(python3 backup-path.py m18)
  test -s "$directory/kv-lab.db"
  [[ "$(kind get clusters 2>/dev/null)" != *kv-recovery* ]]
)
Diagnose

Check which cluster provides the source API and which node currently hosts its etcd Pod.

(
  set -euo pipefail
  kubectl --context kind-kv-lab get --raw=/readyz
  kubectl --context kind-kv-lab -n kube-system get pod etcd-kv-lab-control-plane -o wide
)
Verify

Read the marker using the recovery-only kubeconfig and check the source API separately.

(
  set -euo pipefail
  directory=$(python3 backup-path.py m18)
  marker=$(KUBECONFIG="$directory/recovery.kubeconfig" kubectl --context kind-kv-recovery -n kv-lab get configmap m18 -o jsonpath='{.data.marker}')
  test "$marker" = captured-before-disaster
  kubectl --context kind-kv-lab get --raw=/readyz
)
Clean up

Delete the disposable recovery cluster. Keep any snapshot you explicitly want to retain.

bash cleanup-recovery.sh
Solution
  1. Run the offline restore. It creates kv-recovery, stops its API server and etcd, restores to a fresh data directory with a revision bump, and restarts both static Pods.

    bash restore-offline.sh
Official references
Exercise files 10 files
m19 · Advanced

Repair declarative drift and inspect ownership

Lessons
Troubleshooting challenge

Objective

Detect divergence from a declared ConfigMap and restore it with the designated field manager.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Use the disposable ConfigMap only. The compatibility note is optional reading.
Initial state

kv-gitops applies release=git-declared. A manual patch changes the live value to manual-drift.

Expected results
  • The diff identifies the drift.
  • The live value returns to git-declared, and managed fields show kv-gitops owning the declared field.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Apply the declaration, then introduce a manual edit.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab apply --server-side --field-manager=kv-gitops -f resources.yaml
  kubectl --context kind-kv-lab -n kv-lab patch configmap m19 --type merge -p '{"data":{"release":"manual-drift"}}'
)
Diagnose

Read the field managers and compare declared versus live state. The kubectl diff exit code 1 means there is a difference.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get configmap m19 -o yaml --show-managed-fields
  status=0
  kubectl --context kind-kv-lab -n kv-lab diff -f resources.yaml || status=$?
  test "$status" -eq 1
)
Verify

Check the restored field and inspect the resulting owner.

(
  set -euo pipefail
  test "$(kubectl --context kind-kv-lab -n kv-lab get configmap m19 -o jsonpath='{.data.release}')" = git-declared
  kubectl --context kind-kv-lab -n kv-lab get configmap m19 -o yaml --show-managed-fields
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. After confirming the declaration is authoritative for this lab, apply it as kv-gitops with an explicit ownership takeover. This local exercise models one reconciliation step.

    kubectl --context kind-kv-lab -n kv-lab apply --server-side --field-manager=kv-gitops --force-conflicts -f resources.yaml
Official references
Exercise files 6 files
m20 · Advanced

Cumulative capstones

Lessons

Recover a stateless request path

Troubleshooting challenge
Objective

Prove that an outage is in Service routing and restore the original client path.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Work in m20. Preserve the Deployment and client as you repair Service m20-web.
Initial state

Deployment m20-web has two available replicas, but Service m20-web selects app=broken-selector. A client is ready to probe the Service.

Expected results
  • The Service selector matches the existing workloads and has usable backends.
  • m20-client can download the nginx response from the original Service name.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Create the broken request path and wait for the healthy workload and its client.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab apply -f stateless.yaml
  kubectl --context kind-kv-lab -n kv-lab rollout status deployment/m20-web --timeout=180s
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/m20-client --timeout=180s
)
Diagnose

Compare Pod labels and Service configuration, then prove a failed request from the original client.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get pods -l app=m20-web --show-labels
  kubectl --context kind-kv-lab -n kv-lab get service m20-web -o yaml
  kubectl --context kind-kv-lab -n kv-lab get endpointslices -l kubernetes.io/service-name=m20-web
  result=
  for attempt in $(seq 1 30); do
    result=$(kubectl --context kind-kv-lab -n kv-lab exec m20-client -- sh -c 'if wget -qO- -T 2 http://m20-web >/dev/null 2>&1; then echo HTTP_OK; else echo HTTP_FAILED; fi') || exit 1
    [ "$result" = HTTP_FAILED ] && break
    sleep 1
  done
  printf "%s\n" "$result"
  test "$result" = HTTP_FAILED
)
Verify

Confirm the Deployment remains available and require a successful client request.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab rollout status deployment/m20-web --timeout=90s
  result=
  for attempt in $(seq 1 30); do
    result=$(kubectl --context kind-kv-lab -n kv-lab exec m20-client -- sh -c 'if wget -qO- -T 2 http://m20-web >/dev/null 2>&1; then echo HTTP_OK; else echo HTTP_FAILED; fi') || exit 1
    [ "$result" = HTTP_OK ] && break
    sleep 1
  done
  printf "%s\n" "$result"
  test "$result" = HTTP_OK
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Keep the Deployment in place and repair the Service selector.

    kubectl --context kind-kv-lab -n kv-lab patch service m20-web --type merge -p '{"spec":{"selector":{"app":"m20-web"}}}'
Official references

Restore a deleted file and replace its Pod

Troubleshooting challenge
Objective

Restore an external copy onto a persistent volume and independently compare bytes after Pod replacement.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Work in m20. Use the default local-path provisioner and the same private backup directory throughout. The small fixture is a plain file.
Initial state

The starter writes a fixed 19-byte CSV to the mounted PVC, checks the private copy, and deletes the live file. The claim itself stays bound.

Expected results
  • The restored file matches the backup before replacement.
  • It still matches after the original Pod is replaced with a new consumer of the same claim.
Run, inspect & clean up
Setup

Create the claim, write and capture the known fixture in a private directory, and stop after the intentional file loss.

bash capstone-stateful.sh start
Diagnose

Inspect the binding, the empty mounted directory, and the size of the known backup.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get pvc m20
  kubectl --context kind-kv-lab -n kv-lab exec m20-data -- ls -la /data
  directory=$(python3 backup-path.py m20)
  wc -c < "$directory/orders.csv"
)
Verify

Read the replacement Pod and compare byte counts and SHA-256 against the private backup.

bash capstone-stateful.sh verify
Clean up

Remove lab workloads and the teaching PVC. Retain the private backup only if you need it.

bash cleanup.sh
Solution
  1. Restore the backup with kubectl cp. The BusyBox image contains tar. The script compares bytes immediately after the copy.

    bash capstone-stateful.sh restore
  2. Replace only the consuming Pod. It mounts the original PVC when it becomes Ready.

    bash capstone-stateful.sh replace
Official references

Enforce ownership and repair a controller-managed child

Guided exercise
Objective

Separate declarative ownership of a custom resource from the controller that reconciles its children.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Work in m20. Use the local Python polling controller. Keep the shared WebApp CRD until finished with both m16 and m20.
Initial state

Field manager kv-gitops declares WebApp m20-platform. The reconciler creates the owned Deployment and ConfigMap, and a second manifest tries to change the declared spec.

Expected results
  • The second manager receives a genuine field conflict, and unchanged reconciliation preserves the Deployment identity.
  • The deleted child is repaired. Deleting the parent garbage-collects both children.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Install the API, create the parent as the declarative writer, and reconcile the children.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab apply -f crd.yaml
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Established crd/webapps.labs.kv.example --timeout=60s
  kubectl --context kind-kv-lab -n kv-lab apply --server-side --field-manager=kv-gitops -f platform.yaml
  python3 webapp-reconciler.py --once
  kubectl --context kind-kv-lab -n kv-lab rollout status deployment/m20-platform --timeout=180s
)
Diagnose

Compare field managers on the parent and child, then require the declared spec conflict from kv-human.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get webapp m20-platform -o yaml --show-managed-fields
  kubectl --context kind-kv-lab -n kv-lab get deployment m20-platform -o yaml --show-managed-fields
  if result=$(kubectl --context kind-kv-lab -n kv-lab apply --server-side --field-manager=kv-human -f platform-conflict.yaml 2>&1); then
    echo 'Expected an SSA field conflict' >&2; exit 1
  fi
  printf '%s\n' "$result" | grep -i conflict
)
Verify

Wait for Kubernetes garbage collection to remove both dependents.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab wait --for=delete deployment/m20-platform --timeout=90s
  kubectl --context kind-kv-lab -n kv-lab wait --for=delete configmap/m20-platform --timeout=90s
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Keep the existing parent intent. Re-run the controller and verify that the Deployment keeps its identity.

    (
      set -euo pipefail
      before=$(kubectl --context kind-kv-lab -n kv-lab get deployment m20-platform -o jsonpath='{.metadata.uid}:{.metadata.generation}')
      python3 webapp-reconciler.py --iterations 2 --interval 1
      test "$(kubectl --context kind-kv-lab -n kv-lab get deployment m20-platform -o jsonpath='{.metadata.uid}:{.metadata.generation}')" = "$before"
    )
  2. Delete the owned ConfigMap, run reconciliation, and verify that the child again contains the declared page. Then delete its owner.

    (
      set -euo pipefail
      kubectl --context kind-kv-lab -n kv-lab delete configmap m20-platform
      python3 webapp-reconciler.py --once
      test "$(kubectl --context kind-kv-lab -n kv-lab get configmap m20-platform -o jsonpath='{.data.index\.html}')" = gitops-declared-page
      kubectl --context kind-kv-lab -n kv-lab delete webapp m20-platform --wait=true
    )
Official references
Exercise files 15 files
p01 · Foundations

Fix a Service that targets the wrong port

Lessons
Troubleshooting challenge

Objective

Distinguish a backend port mismatch from a selector or readiness problem.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Work in p01. Preserve the nginx listener, ready Pods, and Service port 80.
Initial state

The Service selects a ready backend but sends connections to port 81. nginx listens on port 80.

Expected results
  • Traffic to the same Service port works after the targetPort is corrected.
  • The original selector and Pod remain unchanged.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Create the workload, Service and probe client.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab apply -f resources.yaml
  kubectl --context kind-kv-lab -n kv-lab rollout status deployment/p01 --timeout=180s
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/p01-client --timeout=180s
)
Diagnose

Check the resolved EndpointSlice port and confirm the actual listener works inside the web Pod. Compare with a failed Service request.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab get pods -l app=p01 --show-labels
  kubectl --context kind-kv-lab -n kv-lab get service p01 -o yaml
  kubectl --context kind-kv-lab -n kv-lab get endpointslices -l kubernetes.io/service-name=p01 -o yaml
  kubectl --context kind-kv-lab -n kv-lab exec deployment/p01 -- wget -qO- -T 2 http://127.0.0.1:80
  result=
  for attempt in $(seq 1 30); do
    result=$(kubectl --context kind-kv-lab -n kv-lab exec p01-client -- sh -c 'if wget -qO- -T 2 http://p01 >/dev/null 2>&1; then echo HTTP_OK; else echo HTTP_FAILED; fi') || exit 1
    [ "$result" = HTTP_FAILED ] && break
    sleep 1
  done
  printf "%s\n" "$result"
  test "$result" = HTTP_FAILED
)
Verify

Check the original selector and correct port, then require an HTTP response.

(
  set -euo pipefail
  test "$(kubectl --context kind-kv-lab -n kv-lab get service p01 -o jsonpath='{.spec.selector.app}:{.spec.ports[0].targetPort}')" = p01:80
  result=
  for attempt in $(seq 1 30); do
    result=$(kubectl --context kind-kv-lab -n kv-lab exec p01-client -- sh -c 'if wget -qO- -T 2 http://p01 >/dev/null 2>&1; then echo HTTP_OK; else echo HTTP_FAILED; fi') || exit 1
    [ "$result" = HTTP_OK ] && break
    sleep 1
  done
  printf "%s\n" "$result"
  test "$result" = HTTP_OK
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Keep the client-facing port and set the backend target port to the actual listener.

    kubectl --context kind-kv-lab -n kv-lab patch service p01 --type merge -p '{"spec":{"ports":[{"port":80,"targetPort":80}]}}'
Official references
Exercise files 4 files
p02 · Intermediate

Place a Pod on a tainted worker

Lessons
Troubleshooting challenge

Objective

Read scheduler evidence and allow one designated Pod onto a reserved worker with a narrowly matching toleration.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Work in p02. The default worker kv-lab-worker must exist. Leave its teaching taint in place while solving.
Initial state

The starter taints kv-lab-worker with labs.kv.example/p02=reserved:NoSchedule. Pod p02 selects that worker and remains Pending.

Expected results
  • The original Pod tolerates exactly the teaching taint and is assigned to kv-lab-worker.
  • Cleanup removes the annotation and taint added by the starter.
Run, inspect & clean up
Setup

Create the lab-owned taint and pending fixture.

bash start.sh
Diagnose

Compare the worker taint with the Pod constraints and the FailedScheduling event.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab describe pod p02
  kubectl --context kind-kv-lab describe node kv-lab-worker
)
Verify

Wait for readiness and read the assigned node.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/p02 --timeout=180s
  test "$(kubectl --context kind-kv-lab -n kv-lab get pod p02 -o jsonpath='{.spec.nodeName}')" = kv-lab-worker
)
Clean up

Remove the Pod and the worker metadata owned by this exercise.

bash cleanup.sh
Solution
  1. Append a toleration for the key, value and effect, leaving the default tolerations intact. Keep nodeSelector because a toleration permits placement but does not choose a node.

    kubectl --context kind-kv-lab -n kv-lab patch pod p02 --type json -p '[{"op":"add","path":"/spec/tolerations/-","value":{"key":"labs.kv.example/p02","operator":"Equal","value":"reserved","effect":"NoSchedule"}}]'
Official references
Exercise files 5 files
p03 · Intermediate

Bind a PVC with the intended StorageClass

Lessons
Troubleshooting challenge

Objective

Trace why a claim cannot be provisioned, then bind a clean teaching claim without modifying the provisioner.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Work in p03 and keep the kind local-path StorageClass. Only replace the unbound teaching claim.
Initial state

PVC p03 explicitly names p03-missing, which the cluster does not provide. Its consumer waits for storage.

Expected results
  • The replacement claim uses standard and becomes Bound.
  • The consuming Pod reads a file it wrote to the mounted directory.
Run, inspect & clean up
Setup

Check that the shell targets the disposable lab cluster and create its namespace if needed.

bash -c 'source ./_common.sh'

Apply the claim and its consumer.

kubectl --context kind-kv-lab -n kv-lab apply -f claim.yaml -f consumer.yaml
Diagnose

Compare the requested class with the available ones. Inspect the storage and scheduling events.

(
  set -euo pipefail
  kubectl --context kind-kv-lab get storageclass
  kubectl --context kind-kv-lab -n kv-lab describe pvc p03
  kubectl --context kind-kv-lab -n kv-lab describe pod p03
)
Verify

Wait for the mount, confirm the claim is bound and read back a marker.

(
  set -euo pipefail
  kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/p03 --timeout=180s
  test "$(kubectl --context kind-kv-lab -n kv-lab get pvc p03 -o jsonpath='{.spec.storageClassName}:{.status.phase}')" = standard:Bound
  test "$(kubectl --context kind-kv-lab -n kv-lab exec p03 -- cat /data/marker)" = storage-ready
)
Clean up

Remove the resources created by this exercise.

bash cleanup.sh
Solution
  1. Confirm the claim is Pending and has no assigned PV. Recreate the teaching claim with standard and let the existing consumer trigger provisioning.

    (
      set -euo pipefail
      if [ "$(kubectl --context kind-kv-lab -n kv-lab get pvc p03 -o jsonpath='{.status.phase}:{.spec.volumeName}')" != Pending: ]; then
        echo 'Refusing to replace a claim that is not Pending and unbound.' >&2
        false
      else
        kubectl --context kind-kv-lab -n kv-lab delete pvc p03 --wait=false &&
        kubectl --context kind-kv-lab -n kv-lab delete pod p03 --wait=true &&
        kubectl --context kind-kv-lab -n kv-lab wait --for=delete pvc/p03 --timeout=60s &&
        sed 's/storageClassName: p03-missing/storageClassName: standard/' claim.yaml | kubectl --context kind-kv-lab -n kv-lab apply -f - &&
        kubectl --context kind-kv-lab -n kv-lab apply -f consumer.yaml &&
        kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready pod/p03 --timeout=180s &&
        kubectl --context kind-kv-lab -n kv-lab exec p03 -- sh -c 'echo storage-ready > /data/marker'
      fi
    )
Official references
Exercise files 5 files
p04 · Intermediate

Grant a ServiceAccount one cross-namespace read

Lessons
Troubleshooting challenge

Objective

Use namespaced RBAC to allow access to one ConfigMap while keeping unrelated requests denied.

Requirements & expected results
Requirements
  • Use the dedicated kind-kv-lab context and the kv-lab namespace. Keep using the terminal where you set up the cluster.
  • Extract the lab bundle and change into the exercise directory. Keep its files together and run the snippets in Bash.
  • Work in p04 using credentials that can impersonate the teaching ServiceAccount. Reserve namespace kv-lab-p04-target for this exercise.
Initial state

ServiceAccount p04-reader has a ConfigMap read RoleBinding in kv-lab. The target ConfigMap is in a second namespace with no binding for this account.

Expected results
  • The intended ConfigMap read in the target namespace succeeds.
  • The same account is still denied ConfigMap writes, other ConfigMap reads in the target namespace, and Secret reads.
Run, inspect & clean up
Setup

Create the teaching account, home binding and the second namespace.

bash start.sh
Diagnose

Compare the same read permission across namespaces.

(
  set -euo pipefail
  identity=system:serviceaccount:kv-lab:p04-reader
  test "$(kubectl --context kind-kv-lab -n kv-lab auth can-i get configmaps --as="$identity")" = yes
  test "$(kubectl --context kind-kv-lab -n kv-lab-p04-target auth can-i get configmaps/p04-status --as="$identity")" = no
  kubectl --context kind-kv-lab -n kv-lab get rolebinding p04-reader -o yaml
)
Verify

Read the actual ConfigMap as the account, then assert the deny boundaries.

(
  set -euo pipefail
  identity=system:serviceaccount:kv-lab:p04-reader
  test "$(kubectl --context kind-kv-lab -n kv-lab-p04-target get cm p04-status --as="$identity" -o jsonpath='{.data.environment}')" = teaching
  test "$(kubectl --context kind-kv-lab -n kv-lab-p04-target auth can-i get configmaps/another --as="$identity")" = no
  test "$(kubectl --context kind-kv-lab -n kv-lab-p04-target auth can-i update configmaps/p04-status --as="$identity")" = no
  test "$(kubectl --context kind-kv-lab -n kv-lab-p04-target auth can-i get secrets --as="$identity")" = no
)
Clean up

Remove the home binding and the lab-owned target namespace.

bash cleanup.sh
Solution
  1. In the target namespace, grant get only for the named ConfigMap, and bind that Role to the account in kv-lab.

    (
      set -euo pipefail
      kubectl --context kind-kv-lab -n kv-lab-p04-target create role p04-status-reader --verb=get --resource=configmaps --resource-name=p04-status
      kubectl --context kind-kv-lab -n kv-lab-p04-target create rolebinding p04-status-reader --role=p04-status-reader --serviceaccount=kv-lab:p04-reader
    )
Official references
Exercise files 5 files

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu