Every level, in the open
Kubernetes
9 worlds · 90 levels · 9 bosses
SOLUTION HIDDENTeachers see answer keys in the classroom.
Sequel to Docker & Containers: build a tiny orchestrator from real processes, then drive the Kubernetes API with kubectl and real YAML. Honest note: the VM is too small for a cluster, so kubectl talks to KUBESIM, a simulated API server in your VM. Real clusters come in field levels.
Guided levels show the command first. Alone levels give the goal only. Bosses and exams are timed.
Jump to a world
World 1Fleet Yard
9 levelsBefore kubectl, build a tiny orchestrator out of real processes: a file that says what should run, and a loop that makes it so.
Level 1: Write it down
Objective: Write the desired state of the web app to ~/fleet/apps/web.conf: three lines app=web, replicas=3 and image=v1.
Imperative means giving orders (start a server, start another); declarative means writing down what should be true (3 web servers, version v1) and letting a program make it so, again and again. Kubernetes is declarative: every YAML file is a desired state.
Commands taught
desired-stateLevel 2: What's really running?
Objective: Compare ~/fleet/apps/web.conf with what's running, and tell Kern how many more web pods must start: kern NUMBER.
Actual state is what really runs: Kern's pod tool starts real busybox httpd processes, pod ls lists them (Running, or Exited when the process died) and ps shows the same processes. Dead pods serve nobody.
Commands taught
fleet-podLevel 3: Make it so
Objective: Fill in the two TODO F3 lines of ~/fleet/reconcile (delete Exited pods, start missing ones), then run it so 3 web pods run.
A reconcile pass reads the desired state, looks at the actual state and fixes the difference: delete what's dead, start what's missing (Kubernetes' ReplicaSet controller does exactly this). Kern's skeleton ~/fleet/reconcile has TODO lines tagged with the level that fills them.
Commands taught
reconcileLevel 4: Whose pods are these?
Objective: web is missing a pod, but reconcile thinks all is fine because it counts db-1 too: fill in TODO F4 (the selector) and run reconcile.
Pods carry labels (here app and image) and a controller picks its pods with a selector like app=web; without one, reconcile counts every pod in the yard, including the database team's db-1. In Kubernetes every ReplicaSet and Service has a selector: hidden -l app=web.
Commands taught
label-selectorLevel 5: Tools for the loop
Objective: Type each example once. They are dry runs, so you cannot break the fleet.
A control loop is shell plus pod. pod ls -q prints only names, -l filters by label, -s by status; [ -z TEXT ] is true when TEXT is empty; break leaves a loop; --loop and exec are how the controller starts itself. These are practice runs: nothing is changed.
Level 6: The control loop
Objective: Fill in TODO F5 in ~/fleet/controller, start it in the background, then kill a web pod's process and watch the loop replace it.
Running reconcile by hand fixes things once; a controller runs it forever in the background (while true; do reconcile; sleep 2; done), so a killed pod is replaced on the next pass: self-healing. Kubernetes' kube-controller-manager is a set of these loops.
Commands taught
control-loopLevel 7: Poke the fleet
Objective: Start the controller, let the chaos monkey kill one web pod, watch the loop heal it, then try two at once.
The control loop only proves itself when something breaks. chaos APP N is Kern's chaos monkey: it kills N running pods of APP, like a node losing them. If the loop works, the fleet heals by itself.
Level 8: Night tariff
Objective: Traffic is low tonight: scale web from 5 pods to 2 by changing the desired state, fill in TODO F6 and run reconcile. db-1 must stay untouched.
Scaling is just a new desired number: up is done (reconcile starts missing pods), down means deleting the extra ones, and only web's, thanks to the selector. hidden changes the same number.
Commands taught
scalingLevel 9: Kill-proof
Objective: Scale web to 4, keep db-1 alone, start the control loop, and survive the chaos monkey: the fleet must heal itself.
Everything at once: change the desired state, run the control loop in the background, then let Kern's chaos monkey kill pods. A good controller heals the fleet with nobody typing.
World 2Health & Discovery
7 levelsAlive isn't healthy and running isn't ready: health checks, one stable address for the whole fleet, and updates nobody notices.
Level 10: Alive isn't healthy
Objective: web-2 runs but its /healthz is gone: fill in TODO H1 of ~/fleet/reconcile (restart pods whose /healthz doesn't answer) and run it.
A process can run and still be broken (stuck, out of disk), so a liveness probe asks the app itself, here GET /healthz, and restarts it in place when there's no answer. In Kubernetes the kubelet does this (livenessProbe) and the RESTARTS column counts it.
Commands taught
liveness-probeLevel 11: Crash loop
Objective: web-3 runs a broken build and your reconcile restarts it every pass: fill in TODO H2 (backoff) and run reconcile.
A pod that crashes on start gets restarted again and again, and restarting at once forever floods logs and burns CPU, so Kubernetes waits longer each time (10 s, 20 s, 40 s, up to 5 min): CrashLoopBackOff. Ours waits 2^RESTARTS seconds, at most 60.
Commands taught
crashloop-backoffLevel 12: Not ready yet
Objective: web-3 is still warming up: fill in TODO H3 so reconcile writes the ready pods to ~/fleet/endpoints/web (NAME 127.0.0.1:PORT), then run it.
Ready is not alive: a pod warming its cache is healthy but shouldn't get customers yet, so a readiness probe (GET /ready) decides who goes in the endpoints list, the addresses traffic may go to. Not ready means no traffic, not a restart.
Commands taught
readiness-probeLevel 13: One address
Objective: Fill in TODO H4 so reconcile writes ~/fleet/svc/web.cfg from head.cfg plus one server line per endpoint and starts haproxy; then curl 127.0.0.1:8080/whoami.
Pods come and go with new ports, but customers need one address that never moves: a Service, here haproxy on 127.0.0.1:8080 with its server list generated from the endpoints file and reloaded when it changes. Kubernetes does it with a ClusterIP and kube-proxy rules.
Commands taught
service-endpointsfleet-customerLevel 14: One at a time
Objective: Roll out web v2: set image=v2 in ~/fleet/apps/web.conf, fill in TODO H5, then run reconcile pass after pass until all 3 pods run v2.
A new version means replacing every pod, never all at once: with maxUnavailable=1 you delete ONE old pod, wait until its replacement is ready, then the next (a not-ready old pod can always go, it serves nobody). Kubernetes Deployments roll out exactly like this.
Commands taught
rolling-updateLevel 15: Roll it back
Objective: v3 crashes: roll web back to v2 (earlier desired states are in ~/fleet/history) and let the running controller bring all 3 pods back to v2.
A bad rollout gets stuck: the new pod never gets ready, so maxUnavailable holds the old ones. Rollback = apply the previous desired state again; the broken pod goes first, it serves nobody. kubectl rollout undo does this with the previous ReplicaSet.
Commands taught
rollout-undoLevel 16: Zero downtime
Objective: Ship web v4 with zero failed customer requests: run the customer and the control loop, add the drain (TODO H7), then deploy v4.
A pod about to be deleted must leave the Service first (drain), get a moment to finish its requests, then stop: Kubernetes takes a terminating pod out of the endpoints first. Then ship v4 while a customer keeps clicking: zero failed requests.
World 3Pod Harbor
13 levelsFirst shift at the harbor cluster: meet kubectl, launch pods, write their YAML, read their events and logs, sort them with labels.
Level 17: kubectl, one verb at a time
Objective: Type each example once. They are dry runs, so you cannot break the cluster.
kubectl VERB RESOURCE NAME [flags]. Before you need them, meet the verbs and flags the next worlds use: cluster-info, run, scale, annotate, get -A / --sort-by, create with its flags, auth can-i, explain and exec. These are practice runs: nothing is changed.
Level 18: First look
Objective: Ask the cluster where its control plane runs and which nodes it has, peek at all its pods, then tell Kern the name of the control-plane node: kern NODE.
A cluster = machines (nodes) run by a control plane: API server, etcd (its database), scheduler, controller manager. kubectl only talks to the API server. SIM: here that is KUBESIM, a simulated API server in your VM.
Commands taught
kubesimkubectlLevel 19: Launch a pod
Objective: Launch a pod named harbor from the image nginx:1.27 and check that it is Running.
A Pod is the smallest thing Kubernetes runs: one or more containers sharing an IP and a lifetime. kubectl run NAME --image=IMAGE asks for one; the scheduler picks a node, its kubelet starts it. hidden shows READY and STATUS.
Commands taught
kubectl-runLevel 20: Write a Pod, line by line
Objective: Build dock.yaml one key at a time, create the pod with kubectl apply -f, and read it back with -o yaml.
A Kubernetes object is a YAML file with four top-level keys: apiVersion (which API and version), kind (what sort of object), metadata (its name and labels) and spec (what you want). Indentation is the nesting: two spaces = one level down, a dash starts a list item.
Commands taught
k8s-yamlk8s-yaml-podLevel 21: Write it down
Objective: Generate lamp.yaml (pod lamp, image nginx:1.26) in ~/kube/k16-pods with --dry-run=client -o yaml, then create the pod with kubectl apply -f.
Objects are YAML: apiVersion, kind, metadata, spec. Let kubectl write it: --dry-run=client -o yaml prints it without creating anything; save with > FILE, then kubectl apply -f FILE. The file is the truth you keep in git (the CKAD/CKA habit).
Level 22: Stuck at the dock
Objective: The pod crane has been Pending since the morning. Find the Reason of its warning event and tell Kern: kern REASON.
kubectl describe pod NAME tells one object's story and ends with its Events: what the scheduler and kubelet did, and why they failed. hidden lists the namespace's events. Pending = never placed on a node.
Commands taught
kubectl-describeLevel 23: A pod that will not start
Objective: Start a postgres pod called db, watch it crash, read its logs and its previous logs, then remove it.
kubectl logs POD prints what the container wrote. A crashing container restarts, so its current log may be empty: kubectl logs POD --previous (short -p) shows the run that died. This database image crashes until it gets a password.
Commands taught
kubectl-logsLevel 24: Same verb, one flag at a time
Objective: On the buoy fleet: try -n, --show-labels, -l and -o on get, describe with -l, then delete one pod by name and one by label.
kubectl VERB RESOURCE [NAME] [flags]. Get, describe and delete take the same few flags: -n NAMESPACE picks a namespace, -l key=value selects by label, -o wide / yaml / jsonpath='...' picks the output shape.
Level 25: The shipper's log
Objective: The pod shop has a sidecar container that ships crates. One crate was lost: read the sidecar's log and tell Kern the crate number: kern NUMBER.
kubectl logs POD shows what a container printed. With several containers (here web + a sidecar named shipper) use -c CONTAINER. After a crash, --previous (-p) shows the log of the container that died.
Level 26: Replace a pod
Objective: Create pod gull from gull.yaml, replace it after an image change, see a refused change (an env var), then force the replace.
kubectl replace -f FILE swaps the live object for the file's version. A running pod only accepts a few edits (the image, for instance); any other change is refused. kubectl replace --force -f FILE then deletes the pod and creates it again from the file.
Level 27: Stick a label on
Objective: Label buoy-2 zone=dock, label the whole app=buoy group, overwrite a value, then remove a label.
Labels are free-form key=value notes on any object. kubectl label TYPE NAME key=value adds one; with -l SELECTOR it labels every match; key- (a trailing dash) removes one; --overwrite changes an existing value.
Commands taught
k8s-labelsLevel 28: Tag the buoys
Objective: Quick: tag every app=buoy pod with zone=harbor (the lighthouse stays untagged) and remove the debug label from every pod.
Labels are key=value tags; selectors pick by them: -l app=buoy, -l debug (key exists). --show-labels shows them; kubectl label pods -l SEL k=v tags every match, k- removes a label, --overwrite changes one.
Level 29: The café keeps sinking
Objective: Kern's café pod keeps crashing. Diagnose it, fix ~/kube/k16-pods/cafe.yaml and bring the café back to Running.
CrashLoopBackOff: the container keeps exiting and the kubelet waits longer each time before restarting it. Method: describe → logs --previous → fix → verify. A bare Pod's spec is mostly immutable: fix the YAML and replace --force.
Commands taught
crashloop
World 4Deploy Docks
10 levelsStop babysitting pods: Deployments keep them alive, scale them, roll new versions out and back; Jobs do the night work.
Level 30: Unsinkable
Objective: Create a Deployment dock (nginx:1.27, 3 replicas), look at it, its ReplicaSet and pods, then delete its pods and watch new ones appear.
A Deployment keeps N pods of a template running: it makes a ReplicaSet, which makes the pods and replaces any that vanish (the Fleet Yard's reconcile loop). kubectl create deployment NAME --image=IMG --replicas=N.
Commands taught
k8s-deploymentLevel 31: A Deployment, written down
Objective: Write quay.yaml (a Deployment of 2 nginx pods) in three pieces, apply it, then change replicas in the file and apply again.
A Deployment's YAML is a Pod's YAML wrapped one level deeper: spec.replicas says how many, spec.selector says which pods are yours, and spec.template is the Pod to stamp out (its labels must match the selector). apiVersion here is apps/v1.
Commands taught
k8s-yaml-deploymentLevel 32: More cranes
Objective: A ship is coming in: scale the crane Deployment from 2 to 5 replicas and check that all 5 are Ready.
kubectl scale deployment NAME --replicas=N changes the desired count; the ReplicaSet adds or removes pods to match. It only changes spec.replicas: same template, same pods kept.
Commands taught
kubectl-scaleLevel 33: New engines
Objective: Upgrade the ferry Deployment (container web) from nginx:1.26 to nginx:1.27, record the change-cause "nginx 1.27", then check the rollout status and history.
Changing the pod template (kubectl set image deployment/NAME CONTAINER=IMAGE) rolls out a new ReplicaSet while the old one shrinks. rollout status follows it; rollout history shows CHANGE-CAUSE, the annotation kubernetes.io/change-cause.
Commands taught
kubectl-rolloutLevel 34: Back to port
Objective: Someone kept experimenting on the tug Deployment. Roll it back to the revision whose change-cause says stable, and check all 3 pods run it.
kubectl rollout undo deployment/NAME goes back one revision; --to-revision=N goes to a specific one from rollout history (history --revision=N shows its template). An undo is itself a new rollout: the old ReplicaSet scales back up and gets a new revision number.
Commands taught
kubectl-rollout-undoLevel 35: See another namespace
Objective: In namespace tide: list its pods with -n, describe them by label, read a rollout history, then make tide your current namespace.
Objects live in namespaces. -n NAME looks into one; kubectl config set-context --current --namespace=NAME changes your default so every later command works there. kubectl describe -l and rollout history also take -n.
Commands taught
k8s-namespaceLevel 36: A dock of our own
Objective: Create the namespace docks, make it your current namespace, and run a Deployment crane (nginx:1.27, 2 replicas) in it.
Namespaces split a cluster into named rooms. kubectl create namespace NAME; -n NAME on any command, -A for all. kubectl config set-context --current --namespace=NAME changes your default namespace.
Level 37: Run a CronJob now
Objective: List the CronJob nightly, create a Job from it called backup-try, and check it completed.
A CronJob stamps out Jobs on a schedule. To run one right now, create a Job from it: kubectl create job NAME --from=cronjob/CRONJOB.
Commands taught
k8s-jobLevel 38: Night shift
Objective: Run the CronJob nightly now as Job backup-now, and Job tally (kern/backup:1.0, 3 completions, backoffLimit 2) from ~/kube/k16b-deploys/tally.yaml.
A Job runs pods until they succeed: completions = successes needed, backoffLimit = failures allowed. A CronJob makes Jobs on a schedule; create job NAME --from=cronjob/CJ runs one now. DaemonSet = one pod per node.
Commands taught
k8s-daemonsetLevel 39: Typo at high tide
Objective: In namespace tide, harbor-web's stuck upgrade must be diagnosed, rolled back without losing a healthy pod, then shipped right and scaled to 6.
ImagePullBackOff: the node cannot pull the image (typo, missing tag, private registry) and retries with back-off. With maxUnavailable 0 the old pods keep serving and the rollout just hangs. Diagnose, roll back, ship the right image.
Commands taught
imagepullbackoff
World 5Config Vault
9 levelsThe café's settings, passwords and appetites: ConfigMaps, Secrets and the CPU and memory every pod asks for.
Level 40: A ConfigMap, written down
Objective: Write shelf.yaml (kind ConfigMap with two keys), apply it, read it back, then make a second ConfigMap from a file.
A ConfigMap keeps settings outside the image: kind ConfigMap and a data: map of key: value. Write it as YAML, or build it from a file with kubectl create configmap NAME --from-file=FILE (the file name becomes the key).
Commands taught
k8s-configmapk8s-yaml-configmapLevel 41: The settings jar
Objective: Create ConfigMap cafe-config with CAFE_DB_HOST=db.cafe and MODE=day, and ConfigMap menu from the file ~/kube/k17/menu.json.
A ConfigMap holds settings as key/value pairs outside the image, so one image runs everywhere with different settings. --from-literal=KEY=value adds one key per flag; --from-file=FILE adds a key named after the file, holding the whole file.
Level 42: Settings in the blood
Objective: Run pod cafe (kern/cafe:v2) with CAFE_DB_HOST via valueFrom from cafe-config, and pod cafe-all (kern/cafe:v2) with all of cafe-config via envFrom.
A container reads a ConfigMap as environment variables: env[].valueFrom.configMapKeyRef picks ONE key (and can rename it), envFrom[].configMapRef takes EVERY key as a variable. A missing ConfigMap or key → CreateContainerConfigError.
Commands taught
k8s-env-fromLevel 43: Menu on the wall
Objective: Pod cafe3 (kern/cafe:v3) is crashing. Recreate it with the ConfigMap menu mounted at /etc/cafe (keep envFrom cafe-config) so it runs.
A ConfigMap can also be a volume: each key becomes a file (menu.json) in the folder of the volumeMount. kern/cafe:v3 reads /etc/cafe/menu.json and panics without it. A pod's volumes can't be changed in place: delete it and create it again (a Deployment would roll it for you).
Commands taught
k8s-configmap-volumeLevel 44: Not a safe
Objective: Read the password in the Secret cafe-db and tell Kern the decoded value with kern PASSWORD.
A Secret is like a ConfigMap whose values are base64. base64 is an ENCODING, not encryption: whoever can read the Secret can decode it. -o jsonpath='{.data.KEY}' prints one value, base64 -d decodes it. Real protection: RBAC and encryption at rest.
Commands taught
k8s-secretLevel 45: How much does it eat?
Objective: Run a deployment pans, look at its use with top, then set requests and a limit with kubectl set resources.
hidden shows live CPU and memory use. kubectl set resources changes a Deployment's requests (what it reserves; the scheduler counts them) and limits (the ceiling: pass the memory limit and the container is killed).
Commands taught
k8s-resourcesLevel 46: Three appetites
Objective: Run three nginx:1.27 pods: be as BestEffort, burst as Burstable and gold as Guaranteed (check .status.qosClass).
requests = what the scheduler reserves; limits = the ceiling (CPU throttled, memory OOMKilled). QoS class: BestEffort (none set), Burstable (some), Guaranteed (cpu AND memory limits = requests). Short on memory, a node evicts BestEffort first.
Level 47: The bakery's budget
Objective: Get bread (namespace bakery) running. Keep the quota; add a LimitRange (requests cpu 100m, memory 64Mi; memory limit 128Mi) and the missing Secret.
A ResourceQuota caps a namespace's totals. Once it covers cpu or memory, every new pod there MUST declare them, or: forbidden: failed quota: … must specify …. A LimitRange fills in defaults for containers that declare nothing. bread also needs its Secret bread-db (key password).
Commands taught
k8s-quotaLevel 48: Boss: The hungry kitchen
Objective: Diagnose menu-api (Pending) and hog (OOMKilled) and right-size both deployments so their pods run.
Two deployments are broken by their numbers: menu-api asks for more CPU than any node has (Pending, FailedScheduling), and hog uses more memory than its limit (the kernel OOM-kills it: OOMKilled, exit 137). Read the evidence, then right-size both.
World 6Service Town
9 levelsPods come and go with new IPs. Services, DNS names, Ingress and NetworkPolicies are how anything ever finds them.
Level 49: A sign on the door
Objective: Expose deployment menu (the café listens on 8080) as Service menu on port 80, then fetch http://menu from the client pod with kubectl exec … wget.
Pod IPs change whenever pods are replaced. A Service gives a stable IP and name; its selector picks pods and its Endpoints list each matching Ready pod's IP:port. kubectl expose deploy NAME --port=80 --target-port=8080: port for clients, targetPort = the container's.
Commands taught
k8s-serviceLevel 50: A Service, written down
Objective: Write menu-yaml.yaml (a Service for the pods labelled app: menu), apply it, and check it found its pods.
A Service is a stable name and IP in front of changing pods: spec.selector says which pods (by label), spec.ports maps port (what clients use) to targetPort (what the container listens on).
Commands taught
k8s-yaml-serviceLevel 51: Not ready yet
Objective: Service soup has no endpoints: its readiness probe asks /readyz. Point readiness at /ready (keep liveness on /healthz). The YAML is in ~/kube/k17b/soup.yaml.
A readinessProbe decides if a pod gets traffic: not ready → removed from the Service's endpoints (pod still runs). A livenessProbe decides if the container is alive: failing → the kubelet restarts it. kern/cafe answers /ready for readiness and /healthz for liveness.
Commands taught
k8s-probesLevel 52: Phone book
Objective: From pod client (namespace default), resolve the Service oven in namespace kitchen with nslookup, and tell Kern the address it returns: kern IP.
CoreDNS (10.96.0.10) names every Service: oven in its own namespace, oven.kitchen from other namespaces, oven.kitchen.svc.cluster.local in full. Short names only work in the same namespace (resolv.conf search list). Ask from inside: kubectl exec client -- nslookup NAME.
Commands taught
k8s-dnsLevel 53: The front gate
Objective: Create Ingress cafe (class nginx): host cafe.local → Service menu:80, host tea.local → Service tea:80. Then fetch http://tea.local from the client pod.
An Ingress is HTTP routing (host, path → Service:port) for an ingress controller, here ingress-nginx (ingressClassName nginx). kubectl create ingress NAME --class=nginx --rule="HOST/PATH=SVC:PORT". SIM: cluster DNS answers each Ingress host with the controller's IP.
Commands taught
k8s-ingressLevel 54: Fix a Service in place
Objective: Expose deployment menu with a wrong targetPort, spot it, fix it with patch -p, then change a replica count with a JSON patch.
kubectl expose makes a Service for a Deployment: --name, --type (ClusterIP, NodePort, LoadBalancer), --port, --target-port. kubectl patch changes a live object without a file: -p takes a JSON snippet that is merged in; --type=json takes a list of operations.
Level 55: Doors to the street
Objective: For deployment menu make Service menu-np (NodePort, 80 → 8080, nodePort 30080) and Service menu-lb (LoadBalancer, 80 → 8080). Both need endpoints.
type: NodePort opens one port (30000–32767) on EVERY node and forwards it to the Service. type: LoadBalancer also asks the cloud for an external load balancer; on a bare cluster nobody answers, so EXTERNAL-IP stays <pending>.
Commands taught
k8s-nodeportLevel 56: Members only
Objective: In default: policy default-deny (all pods, Ingress, no rules) and policy allow-client (app=client → app=web, TCP 80). Prove client still gets http://web.
By default any pod reaches any pod. A NetworkPolicy selects pods; once selected for Ingress, only listed sources get in. podSelector: {} + policyTypes [Ingress] + no rules = default deny. Policies add up. The CNI enforces them (SIM: exec wget/nslookup).
Commands taught
k8s-networkpolicyLevel 57: Boss: The café is down
Objective: Get http://cafe answering from the client pod: fix the Service's selector and targetPort and the deployment's readiness probe.
The café's pods run, but http://cafe from the client pod fails. A Service reaches nothing when its selector matches no pod labels, when its targetPort isn't the container's port, or when the pods aren't Ready. This one has all three.
World 7Guard Tower
8 levelsEvery pod has an identity and every identity has keys. Hand out exactly the keys a job needs, prove it, and lock the doors.
Level 58: Name badge
Objective: In namespace tower, create the ServiceAccount scribe and run a pod ledger (busybox:1.37, sleep 86400) as scribe, without a mounted token.
Every pod runs as a ServiceAccount (default: default). Its token is mounted at /var/run/secrets/kubernetes.io/serviceaccount so the pod can call the API. A pod that never calls the API shouldn't carry one: automountServiceAccountToken: false.
Commands taught
k8s-serviceaccountLevel 59: One room, one key
Objective: In tower: Role reader (get, list, watch pods + get pods/log), given to the ServiceAccount tower:scribe by a RoleBinding scribe-reads.
RBAC only allows. A Role lists rules (apiGroups, resources, verbs) in one namespace; a RoleBinding gives it to subjects (User, Group, ServiceAccount): kubectl create role … --verb --resource; kubectl create rolebinding … --role --serviceaccount NS:NAME.
Commands taught
k8s-rbac-roleLevel 60: Ask the guard
Objective: Three ServiceAccounts live in tower: bell, lamp and quill. Only one of them may delete pods in tower. Find it with kubectl auth can-i and tell Kern: kern NAME.
kubectl auth can-i VERB RESOURCE asks the API server's authorizer: yes or no. Add --as=system:serviceaccount:NAMESPACE:NAME to ask for someone else (impersonation, needs admin rights) and -n for the namespace. --list prints everything that identity may do there.
Commands taught
kubectl-auth-can-iLevel 61: Master keys
Objective: Let tower:watcher list pods in every namespace, and give tower:helper the built-in ClusterRole edit, but only inside yard.
A ClusterRole is a Role without a namespace. Bound by a ClusterRoleBinding it works in EVERY namespace (and for nodes etc.). Bound by a RoleBinding it works only in that binding's namespace: reuse one definition (like the built-in edit) per namespace.
Commands taught
k8s-clusterroleLevel 62: The manual
Objective: Audit: 'a process must not gain more privileges than its parent'. Find that securityContext field with kubectl explain and tell Kern: kern FIELD.
Nobody memorises the API. kubectl explain RESOURCE.FIELD.FIELD prints a field's type and docs from the server (pod.spec.containers.securityContext …); --recursive shows the tree below. Allowed in CKA/CKAD and faster than any search.
Commands taught
kubectl-explainLevel 63: Roll an image, as someone else
Objective: In namespace shop, roll storefront's web container to nginx:1.27 as yourself, then roll it again as the ci-bot ServiceAccount.
kubectl set image deploy/NAME CONTAINER=IMAGE rolls a Deployment to a new image. -n picks the namespace, and --as=USER asks the API server to treat you as another identity (a ServiceAccount is system:serviceaccount:NAMESPACE:NAME): the way to test what a bot can do.
Level 64: Not as root
Objective: In tower, run pod safe (kern/api:1.1, container api): UID 1000 non-root, read-only root fs, no privilege escalation, no capabilities. Prove it: exec id.
securityContext hardens a pod: runAsNonRoot (kubelet refuses root), runAsUser (the UID), readOnlyRootFilesystem, hidden, capabilities drop [ALL]. Pod-level fields apply to all containers; container-level ones win.
Level 65: Keys for the robot
Objective: shop:ci-bot may only roll out deployment images in shop: no secrets, no other namespaces. Cut its old access, grant the minimum, prove it as the bot.
Least privilege: give an identity exactly the verbs on exactly the resources in exactly the namespace its job needs, nothing more, and prove both the yes and the no.
World 8Storage & Ops
10 levelsDay two: disks that outlive pods, reading a busy cluster fast, scaling with the rush, servicing nodes, and shipping a whole app in one go.
Level 66: The pantry
Objective: Create claim beans (1Gi, RWO) and see it wait, mount it in pod roaster so it binds, then claim the static volume pv-archive with a PVC archive.
A PVC asks for storage (size, access mode); a PV is the disk. A StorageClass makes PVs on demand. The default class here (like kind) is WaitForFirstConsumer: Pending until a pod uses it. Admins can also pre-make PVs for claims with storageClassName: "".
Commands taught
k8s-storageLevel 67: Stuck in the pantry
Objective: The claims menu, photos and logs (claims.yaml) should bind to the static PVs pv-menu, pv-photos, pv-logs. Fix claims.yaml until all are Bound.
A Pending PVC always has a reason in kubectl describe pvc: a class that doesn't exist (ProvisioningFailed), no PV big enough, or no PV offering that access mode (FailedBinding). A claim's spec can't be edited after creation: fix the YAML, delete the claim and apply it again.
Level 68: Speed reading
Objective: In namespace orders, tell Kern (kern ANSWER): till's image, the pod whose ServiceAccount isn't default, and the oldest pod.
-o jsonpath='{.spec.replicas}' prints one field, -o custom-columns=NAME:.metadata.name,SA:.spec.serviceAccountName builds your own table, --sort-by=.metadata.creationTimestamp sorts a list. CKA habit: never scroll YAML for one value.
Commands taught
kubectl-output-formatsLevel 69: Close and open a node
Objective: Cordon worker-2, see SchedulingDisabled in hidden, then uncordon it.
kubectl cordon NODE marks a node unschedulable: running pods stay, but no new pod lands there. kubectl uncordon NODE opens it again. A forgotten cordon is a classic reason pods stay Pending.
Level 70: Alarm board
Objective: Two namespaces have trouble and a node was left cordoned. Find the Warnings cluster-wide and fix all three (café images: kern/cafe:v1 to v3; nodes: 2 CPUs).
Events are the cluster's short-term memory (about an hour): hidden shows every recent problem in every namespace, newest last. Then describe the object it names.
Commands taught
kubectl-eventsLevel 71: Lunch rush
Objective: Autoscale barista (2 to 6 replicas, 50% CPU), fix <unknown> with a 100m cpu request, then start the rush (kubesim/load=3) and watch it scale out.
An HPA moves a Deployment's replicas to keep average CPU near a target, as a percent of each pod's cpu REQUEST (no request: <unknown>). SIM: no metrics-server here; KUBESIM fakes CPU and the annotation kubesim/load stands in for traffic.
Commands taught
k8s-hpaLevel 72: Night maintenance
Objective: Drain worker-1 and bring it back, then reserve worker-2 for the roaster: taint it roaster=only:NoSchedule and let only the roaster deployment in.
cordon = no new pods; drain = cordon + evict (controllers re-create pods elsewhere; --ignore-daemonsets); uncordon reopens. A taint key=value:NoSchedule keeps pods off unless they tolerate it. Field levels repeat this on a real cluster.
Commands taught
kubectl-draink8s-taintsLevel 73: Autoscale in a namespace
Objective: In namespace orders: give deployment till a CPU request, autoscale it 2 to 4 at 60%, and check the HPA.
kubectl autoscale deploy NAME --min --max --cpu-percent creates a HorizontalPodAutoscaler. -n puts the command in the right namespace, and the Deployment needs a CPU request, or the HPA cannot compute a percentage.
Level 74: Files for a chart
Objective: Write Chart.yaml and values.yaml for a chart called notes, then use sed with & to extend a value.
Helm packages a Kubernetes app as a chart: a folder with Chart.yaml (apiVersion v2, name, version) and values.yaml (default settings). These are plain files, so you can write them with printf. sed's & in a replacement stands for whatever the pattern matched.
Level 75: Ship the café
Objective: Ship the café from release/: apply the folder, finish the deployment, fix what blocks traffic, prove http://cafe.local/menu answers from inside a pod.
A release is many objects that depend on each other. kubectl apply -f DIR applies every file in the directory (alphabetical order, so 00-namespace.yaml goes first); re-run it after every fix, then verify end to end, the way a customer would.
Commands taught
kubectl-apply-dir
World 9Chart Harbor
15 levelsThe café leaves the simulator: a real k3s cluster, your own namespace, and Helm to install, upgrade, roll back and write charts.
Level 76: Hello, real cluster
Objective: Find the name of your namespace, then create a ConfigMap named hello in it with the key namespace set to that name.
This is not KUBESIM. kubectl here talks to a real k3s cluster on the lab server. You own one namespace, chosen by your kubeconfig's context; the rest of the cluster answers Forbidden. Try hidden and see.
Commands taught
k19-real-clusterLevel 77: The Helm toolbox
Objective: Type each Helm example Kern shows; nothing runs, and the next levels use every command for real.
helm is one program with many sub-commands. Look at a chart (lint, template), find one (repo, search, show), pack one (package), run one (install, upgrade, rollback, uninstall) and read what happened (list, status, history, get).
Commands taught
k19-helmLevel 78: One command, whole app
Objective: Install the chart in ~/charts/cafe as a release named web, then look at it with hidden and helm status.
Helm installs a chart (a folder of YAML templates plus default values) as a release: a named, versioned copy of the app in your namespace. Helm keeps each release's history in Secrets next to it.
Commands taught
k19-helm-installLevel 79: Values, not edits
Objective: Write ~/bakery.yaml with greeting "Fresh bread daily" and replicaCount 2, then install ~/charts/cafe as release bakery using that file.
A chart's values.yaml holds its defaults. You override them at install time with --set key=value or with -f FILE. A values file in git is better than a long --set line: you can review it.
Commands taught
k19-helm-valuesLevel 80: The upgrade that forgot
Objective: web runs 2 replicas. Change its greeting to "Now serving croissants" with helm upgrade, and keep the 2 replicas.
helm upgrade renders the chart again and moves the release to a new revision. Trap: if you pass any --set or -f, Helm starts from the chart defaults again, not from your last values. --reuse-values keeps them.
Commands taught
k19-helm-upgradeLevel 81: Back to the croissants
Objective: Revision 3 of web broke its rollout. Find the revision that serves croissants and roll web back to it with Helm.
Every upgrade is a revision. helm history lists them; helm get values --revision N shows one; helm rollback NAME N makes a NEW revision that copies N. In KUBESIM you used kubectl rollout undo: with Helm, undo through Helm, or the next upgrade brings the bad version back.
Commands taught
k19-helm-rollbackLevel 82: Look before you leap
Objective: Render ~/charts/cafe with ~/prod.yaml as release prod into ~/render/prod.yaml, without installing it. Then remove the stray release oops.
helm template renders a chart to plain YAML on your side, without the cluster: review it, diff it, keep it. helm get manifest NAME shows what a live release applied. helm uninstall removes a release and its objects.
Commands taught
k19-helm-templateLevel 83: The kiosk won't build
Objective: The chart in ~/charts/kiosk is broken. Make helm lint pass, install it as release kiosk, and make its page say Kiosk open.
helm lint checks a chart: YAML, template syntax, required fields. It finds broken templates; it can't know that a value's name is misspelled, because a missing value just renders as nothing. Render and read too.
Commands taught
k19-helm-lintLevel 84: A chart of your own
Objective: Write chart ~/charts/notes (version 0.1.0): ConfigMap <release>-notes, key message from .Values.message (default hello). Install as jot, message=ship-it.
A chart is just files: Chart.yaml (apiVersion v2, name, version), values.yaml (defaults) and templates/ (YAML with {{ }} holes). .Release.Name is the release's name, .Values.x a value. helm create makes a big starter chart; this one is tiny.
Commands taught
k19-helm-chartLevel 85: Loops and helpers
Objective: In ~/charts/cafe: list each .Values.menu item on its own page line, add .Values.extraLabels in the cafe.labels helper. Install as menu with -f ~/menu.yaml.
Templates are Go templates: {{ range .Values.list }} repeats, {{ with .Values.x }} runs only when x is set, define and include reuse a block (see templates/_helpers.tpl), toYaml prints a map, nindent fixes its indentation.
Commands taught
k19-helm-templatingLevel 86: The lab chart repository
Objective: Add the lab chart repo http://registry.ptr:5000/pkg/charts as lab, list lab/cafe's versions, and install release shop from lab/cafe 0.2.0 (the tested one).
Teams publish charts in a repository: an index.yaml plus .tgz files on any web server. helm repo add names it, helm search repo lists charts and versions, --version pins one. Pin what you tested: the newest isn't always it.
Commands taught
k19-helm-repoLevel 87: Ship it as a package
Objective: notes chart: add value owner (default kern) as ConfigMap key owner, bump to 0.2.0, package into ~/dist, upgrade jot from the .tgz, keep message=ship-it.
helm package turns a chart folder into NAME-VERSION.tgz, the file a repository serves. Bump version in Chart.yaml for every change: a version is a promise that its content never changes.
Commands taught
k19-helm-packageLevel 88: Deployed, and nobody home
Objective: Release api says deployed but has no pods. Find out why and fix it through Helm. ~/api-values.yaml is the source of truth.
helm says deployed when the API server ACCEPTED the objects, not when pods run. A Deployment can be accepted and still make no pods. Read events (hidden, kubectl describe rs). Fix it in the values file and upgrade: a kubectl fix is undone by the next upgrade.
Commands taught
k19-helm-debugLevel 89: Pager: the upgrade that can't
Objective: PAGE: release orders must run chart 0.4.0 from ~/charts/cafe-0.4.0, deployed, with 2 ready pods. The last upgrade failed.
Some fields can't change after creation; a Deployment's selector is one. If a new chart version changes selector labels, helm upgrade fails with field is immutable and the release is marked failed. Delete that one object (a short outage), then upgrade: Helm creates it fresh.
Commands taught
k19-helm-immutableLevel 90: BOSS: Opening night
Objective: Release night: deployed with ~/night-prod.yaml (greeting Opening night, 2 replicas), all pods ready, chart passing helm lint. Fix all in the way.
Helm marks a release pending-upgrade before applying anything, deployed only at the end. If helm dies in between (a killed CI job), the mark stays and every upgrade says another operation is in progress. helm history shows it; a rollback clears it.
Commands taught
k19-helm-pending
For teachers
Use these levels with a class
SOLUTION HIDDEN Teachers see answer keys in the classroom.