CKA prep, by exam domain · Lesson 10 of 12 · about 60 minutes

Workloads and scheduling

Running apps and deciding where they land: rolling updates that stall instead of breaking, rollbacks that renumber, ConfigMaps and Secrets, probes that restart or sideline a pod, a memory limit that kills, an autoscaler under load, and nodeSelectors, affinity, taints and quotas on a real cluster.

Exam domain: Workloads and scheduling · 15% of the exam

By the end you'll know

  • How a rolling update replaces pods, and why a bad image stalls it instead of taking the app down
  • How rollback history really numbers revisions, and how CHANGE-CAUSE can mislead you
  • How to feed a ConfigMap and a Secret into a pod, and why changing them doesn't change running pods
  • What liveness, readiness and startup probes each do when they fail
  • What OOMKilled and exit code 137 mean, and how requests and limits set a pod's QoS class
  • How the Horizontal Pod Autoscaler decides how many pods to run
  • How nodeSelector, node affinity, taints and tolerations steer pods, and what a ResourceQuota blocks

Before you start

  • You need: the cluster from Lesson 2, all nodes Ready, and metrics-server from Lesson 4 (for k top and autoscaling).
  • The output below is from real runs on November 29, 2026, in New York, on an Apple silicon Mac.

Workloads and scheduling is 15% of the exam. It's the domain closest to everyday work: shipping a new version, configuring an app, keeping it healthy, and deciding which machine runs it. This lesson covers all of it in one namespace, then removes every change from the cluster at the end.

Setup

(cp1)

BASH
k create ns wl-lab
k config set-context --current --namespace=wl-lab
Code
namespace/wl-lab created
Context "kubernetes-admin@kubernetes" modified.
  • set-context --current --namespace=wl-lab changes the default namespace in your kubeconfig's current context. Every command after this runs in wl-lab, so you can drop -n.
  • Put it back at the end. A default namespace that no longer exists makes every later command look empty or fail. The clean-up does it.

Rolling updates and rollbacks

(cp1)

BASH
k create deploy web --image=nginx:1.27-alpine --replicas=3
k rollout status deploy/web
k set image deploy/web nginx=nginx:1.28-alpine
k rollout status deploy/web
k annotate deploy/web kubernetes.io/change-cause="nginx 1.28"
  • set image deploy/web nginx=IMAGE: nginx is the container name, not the Deployment's (Lesson 1).
  • rollout status waits until the rollout finishes, or fails.
  • annotate ... kubernetes.io/change-cause="..." writes a note that rollout history shows. The old --record flag that did this is gone.
Code
deployment.apps/web image updated
Waiting for deployment "web" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "web" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "web" rollout to finish: 2 old replicas are pending termination...
Waiting for deployment "web" rollout to finish: 1 old replicas are pending termination...
deployment "web" successfully rolled out

That's a rolling update: new pods come up a few at a time while old ones go, so the app never fully stops. Behind the scenes, the Deployment made a second ReplicaSet for the new version and moved the count over from the old one.

A bad image

(cp1)

BASH
k set image deploy/web nginx=nginx:1.99-alpine
k rollout status deploy/web --timeout=30s
k get pods

nginx:1.99-alpine doesn't exist. --timeout=30s stops waiting, since this rollout will never finish.

Code
Waiting for deployment "web" rollout to finish: 1 out of 3 new replicas have been updated...
error: timed out waiting for the condition
NAME                   READY   STATUS         RESTARTS   AGE
web-64fc786fb9-8f64t   1/1     Running        0          38s
web-64fc786fb9-hgqpv   1/1     Running        0          31s
web-64fc786fb9-q4w5d   1/1     Running        0          34s
web-66944fc8df-6dx6p   0/1     ErrImagePull   0          30s

All three old pods kept running. A rolling update has two limits, both 25% by default:

  • maxSurge: how many extra pods may exist during the update. 25% of 3, rounded up, is 1.
  • maxUnavailable: how many pods may be missing. 25% of 3, rounded down, is 0.

So Kubernetes added one new pod and waited for it to become Ready before removing an old one. It never became Ready, so nothing old was removed. A bad rollout stalls; it doesn't take the app down. The two hash suffixes, 64fc786fb9 and 66944fc8df, are the old and new ReplicaSets.

History and undo

(cp1)

BASH
k rollout history deploy/web
k rollout undo deploy/web
k rollout status deploy/web
k rollout history deploy/web
k get deploy web -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'
Code
REVISION  CHANGE-CAUSE
1         <none>
2         nginx 1.28
3         nginx 1.28

deployment.apps/web rolled back
deployment "web" successfully rolled out

REVISION  CHANGE-CAUSE
1         <none>
3         nginx 1.28
4         nginx 1.28

nginx:1.28-alpine

Two surprises:

  • Revision 3 says nginx 1.28, but it's the broken 1.99. The annotation lives on the Deployment, and each new revision copies whatever it says at that moment. I didn't update it for 1.99, so revision 3 inherited the old note. Update CHANGE-CAUSE with every change, or the history misleads you.
  • Undo moved forward, not back. rollout undo copied revision 2's pod template into a new revision, 4, and revision 2 disappeared from the list. So a second undo would flip back to revision 3, the broken one. To pick a specific revision, use k rollout undo deploy/web --to-revision=N, after checking it with k rollout history deploy/web --revision=N.

The jsonpath line confirms the Deployment is back on nginx:1.28-alpine.

ConfigMaps and Secrets

(cp1)

BASH
k create configmap app-config --from-literal=COLOR=blue --from-literal=MODE=lab
k create secret generic app-secret --from-literal=PASSWORD=not-a-real-one
k set env deploy/web --from=configmap/app-config
k set env deploy/web --from=secret/app-secret
k rollout status deploy/web
k exec deploy/web -- env | grep -E "COLOR|MODE|PASSWORD"
  • --from-literal=KEY=VALUE: one key per flag. --from-file reads keys from files instead.
  • set env deploy/web --from=configmap/NAME: turns every key into an environment variable in the pod template. Changing the template triggers a rollout.
  • k exec deploy/web -- env runs env in one of the Deployment's pods.
Code
MODE=lab
COLOR=blue
PASSWORD=not-a-real-one

A Secret is encoded, not encrypted

(cp1)

BASH
k get secret app-secret -o jsonpath='{.data.PASSWORD}'; echo
k get secret app-secret -o jsonpath='{.data.PASSWORD}' | base64 -d; echo
Code
bm90LWEtcmVhbC1vbmU=
not-a-real-one

The stored value is base64, a way of writing any bytes as plain text. base64 -d turns it straight back, with no key. Anyone who can get a Secret can read it. What protects a Secret is RBAC (and the edit role includes Secrets, Lesson 6), plus encryption at rest in etcd if the cluster turns it on. Never the base64.

Running pods don't see changes

(cp1)

BASH
k create configmap app-config --from-literal=COLOR=green --from-literal=MODE=lab --dry-run=client -o yaml | k apply -f -
k exec deploy/web -- env | grep COLOR
k rollout restart deploy/web
k rollout status deploy/web
k exec deploy/web -- env | grep COLOR

The first line is the "re-create in place" pattern: generate the YAML, then apply it over the existing ConfigMap.

Code
Warning: resource configmaps/app-config is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by kubectl apply. kubectl apply should only be used on resources created declaratively by either kubectl create --save-config or kubectl apply. The missing annotation will be patched automatically.
configmap/app-config configured
COLOR=blue
deployment.apps/web restarted
...
deployment "web" successfully rolled out
COLOR=green
  • COLOR=blue after the change. Environment variables are copied once, when the container starts. The ConfigMap said green; the running pod still said blue.
  • rollout restart replaced every pod without changing the image, and the new pods read green.
  • A ConfigMap mounted as a volume is different: its files update inside running pods after a short delay. Environment variables never do.
  • The warning is harmless. apply keeps a copy of what it last applied, in an annotation, to work out what to remove next time. The ConfigMap was made with create, so it had none, and kubectl added it.

Probes

The kubelet can check each container's health in three ways, and each failure does something different. Two pods, each with a probe that can't pass, because nginx has no /healthz or /ready page:

(cp1)

BASH
cat > probes.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata:
  name: live-fail
  labels: { app: probes }
spec:
  containers:
  - name: nginx
    image: nginx:1.28-alpine
    livenessProbe:
      httpGet: { path: /healthz, port: 80 }
      initialDelaySeconds: 3
      periodSeconds: 5
      failureThreshold: 2
---
apiVersion: v1
kind: Pod
metadata:
  name: ready-fail
  labels: { app: probes }
spec:
  containers:
  - name: nginx
    image: nginx:1.28-alpine
    readinessProbe:
      httpGet: { path: /ready, port: 80 }
      periodSeconds: 5
EOF
k apply -f probes.yaml
k create service clusterip probes --tcp=80:80
sleep 45
k get pods -l app=probes
k describe pod live-fail | tail -12
k describe svc probes | grep -i endpoints
  • httpGet: the kubelet requests that page; any 200 to 399 response is a pass. A probe can also run a command (exec) or open a TCP port (tcpSocket).
  • initialDelaySeconds: 3 waits before the first check. periodSeconds: 5 checks every 5 seconds. failureThreshold: 2 acts after 2 failures in a row.
  • k create service clusterip probes --tcp=80:80 makes a Service that selects app=probes: create service uses its own name as the selector. --tcp is port:targetPort.
Code
NAME         READY   STATUS             RESTARTS     AGE
live-fail    0/1     CrashLoopBackOff   3 (5s ago)   45s
ready-fail   0/1     Running            0            45s
Code
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  45s                default-scheduler  Successfully assigned wl-lab/live-fail to worker2
  Normal   Started    15s (x4 over 45s)  kubelet            spec.containers{nginx}: Container started
  Warning  Unhealthy  5s (x8 over 40s)   kubelet            spec.containers{nginx}: Liveness probe failed: HTTP probe failed with statuscode: 404
  Normal   Killing    5s (x4 over 35s)   kubelet            spec.containers{nginx}: Container nginx failed liveness probe, will be restarted
  Warning  BackOff    4s (x2 over 5s)    kubelet            spec.containers{nginx}: Back-off restarting failed container nginx in pod live-fail_wl-lab(6ae387d3-48f4-49fc-bed7-e81d5f02a119)
Code
Endpoints:                

Liveness failed, so the kubelet killed and restarted the container, 4 times in 45 seconds, then started waiting longer between restarts: CrashLoopBackOff. The same status as ticket 6 in Lesson 4, but a different cause. nginx was fine; the probe was wrong. When a pod crash-loops but its logs look healthy, look for Liveness probe failed in describe.

Readiness failed, so ready-fail kept running with no restarts, but 0/1 and out of the Service. The Service has no endpoints at all: live-fail has no readiness probe, so it counts as ready whenever it's running, but during backoff it isn't.

The two Tolerations lines are worth a look too. Kubernetes adds them to every pod, and they're why pods waited 5 minutes before eviction when a node went down in Lesson 3.

Now give ready-fail the page it's asking for:

(cp1)

BASH
k exec ready-fail -- sh -c 'echo ok > /usr/share/nginx/html/ready'
sleep 10
k get pods -l app=probes
k describe svc probes | grep -i endpoints
Code
NAME         READY   STATUS             RESTARTS      AGE
live-fail    0/1     CrashLoopBackOff   3 (15s ago)   55s
ready-fail   1/1     Running            0             55s
Endpoints:                10.244.189.72:80

1/1, still 0 restarts, and its IP joined the Service. Readiness is checked for the pod's whole life, so a pod can drop out of a Service when it's busy and come back when it recovers.

ProbeWhen it failsUse it for
LivenessThe container is killed and restartedAn app that hangs and won't recover on its own
ReadinessThe pod is removed from Service endpointsAn app that's busy, or still warming up
StartupThe container is killed; the other probes wait until it passesA slow-starting app that liveness would otherwise kill

Requests, limits and OOMKilled

Requests are what the scheduler reserves for a container on a node. Limits are the most it may use. A container that goes over its memory limit is killed:

(cp1)

BASH
cat > hog.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata:
  name: hog
spec:
  restartPolicy: Never
  containers:
  - name: hog
    image: busybox:1.37
    command: ["sh", "-c", "tail /dev/zero"]
    resources:
      requests: { memory: 30Mi }
      limits: { memory: 50Mi }
EOF
k apply -f hog.yaml
sleep 15
k get pod hog
k describe pod hog | grep -A6 "State:"
  • tail /dev/zero: tail keeps everything since the last line break, and /dev/zero is an endless stream with no line breaks. Its memory grows until something stops it.
  • restartPolicy: Never keeps it dead, so you can read why.
Code
NAME   READY   STATUS      RESTARTS   AGE
hog    0/1     OOMKilled   0          16s
    State:          Terminated
      Reason:       OOMKilled
      Exit Code:    137
      Started:      Sun, 29 Nov 2026 17:13:56 +0000
      Finished:     Sun, 29 Nov 2026 17:13:56 +0000
  • OOMKilled means out of memory: the Linux kernel killed the process the moment it passed 50Mi, in under a second.
  • Exit code 137 is 128 + 9. Codes above 128 mean "killed by a signal", and 9 is SIGKILL, which can't be caught. See 137, think memory limit.
  • CPU is different. A container over its CPU limit is slowed down (throttled), never killed.

Requests and limits on a Deployment, and QoS

(cp1)

BASH
k set resources deploy/web --requests=cpu=50m,memory=32Mi --limits=cpu=200m,memory=64Mi
k rollout status deploy/web
k get pods -l app=web -o jsonpath='{.items[0].status.qosClass}{"\n"}'
  • cpu=50m is 50 millicores, a twentieth of one CPU core. Mi is mebibytes.
  • status.qosClass is the Quality of Service class Kubernetes gives a pod from its requests and limits.
Code
deployment "web" successfully rolled out
BestEffort

BestEffort is wrong, and the command is to blame. .items[0] takes the first pod in the list, and straight after a rollout the list can still include old pods shutting down, which have no requests. Check every pod instead:

(cp1)

BASH
k get pods -l app=web -o custom-columns=NAME:.metadata.name,QOS:.status.qosClass
Code
NAME                   QOS
web-86d64bbbf9-5pm5l   Burstable
web-86d64bbbf9-7hdhm   Burstable
web-86d64bbbf9-zjb2n   Burstable
  • Burstable: requests set, lower than the limits.
  • Guaranteed: requests equal to limits, for CPU and memory, in every container.
  • BestEffort: nothing set. When a node runs short of memory, these pods are evicted first.

Autoscaling

The Horizontal Pod Autoscaler (HPA) changes a Deployment's replica count from CPU use, measured as a percentage of each pod's CPU request. That's why web needed requests first.

(cp1)

BASH
k top pods -l app=web
k autoscale deploy web --min=2 --max=5 --cpu-percent=50
k get hpa web
k expose deploy web --port=80
k run load --image=busybox:1.37 --restart=Never -- sh -c 'while true; do wget -q -O- http://web >/dev/null; done'
sleep 90
k get hpa web
k top pods -l app=web
k describe hpa web | tail -8
k delete pod load
  • --min=2 --max=5: the range the HPA may choose from. --cpu-percent=50: aim for 50% of each pod's 50m request, so 25m.
  • The load pod requests nginx's page as fast as it can, forever. -q -O- means quiet and print to standard output; >/dev/null throws the page away.
Code
Flag --cpu-percent has been deprecated, Use --cpu with percentage or resource quantity format (e.g., '70%' for utilization or '500m' for milliCPU).
NAME   REFERENCE        TARGETS       MINPODS   MAXPODS   REPLICAS   AGE
web    Deployment/web   cpu: 0%/50%   2         5         3          0s
...
NAME   REFERENCE        TARGETS        MINPODS   MAXPODS   REPLICAS   AGE
web    Deployment/web   cpu: 26%/50%   2         5         3          90s
NAME                   CPU(cores)   MEMORY(bytes)   
web-86d64bbbf9-5pm5l   12m          3Mi             
web-86d64bbbf9-7hdhm   16m          3Mi             
web-86d64bbbf9-zjb2n   11m          3Mi             
Conditions:
  Type            Status  Reason               Message
  ----            ------  ------               -------
  AbleToScale     True    ScaleDownStabilized  recent recommendations were higher than current one, applying the highest recent recommendation
  ScalingActive   True    ValidMetricFound     the HPA was able to successfully calculate a replica count from cpu resource utilization (percentage of request)
  ScalingLimited  False   DesiredWithinRange   the desired count is within the acceptable range
  • The flag has changed: use --cpu=50% now. --cpu-percent still works, with a warning.
  • 26% is below the 50% target, so no scale-up. One load loop wasn't enough.
  • The HPA's sum: desired pods = current pods × (current % ÷ target %), rounded up. 3 × 26 ÷ 50 = 1.56, so it actually wanted 2, the minimum.
  • ScaleDownStabilized is why it stayed at 3. For scaling down, the HPA uses the highest recommendation from the last 5 minutes (the default), so a brief dip doesn't remove pods you'll need again.
  • ScalingActive True, ValidMetricFound is the line to check when an HPA seems broken. Without metrics-server, or without a CPU request, it's False and TARGETS shows <unknown>.

Four load loops instead of one:

(cp1)

BASH
k create deploy load --image=busybox:1.37 --replicas=4 -- sh -c 'while true; do wget -q -O- http://web >/dev/null; done'
sleep 90
k get hpa web
k top pods -l app=web
k describe hpa web | grep -A8 Events
k delete deploy load
Code
NAME   REFERENCE        TARGETS        MINPODS   MAXPODS   REPLICAS   AGE
web    Deployment/web   cpu: 81%/50%   2         5         5          4m19s
NAME                   CPU(cores)   MEMORY(bytes)   
web-86d64bbbf9-5pm5l   41m          3Mi             
web-86d64bbbf9-5wfnr   41m          3Mi             
web-86d64bbbf9-7hdhm   41m          3Mi             
web-86d64bbbf9-p2rqr   41m          3Mi             
web-86d64bbbf9-zjb2n   40m          3Mi             
Events:
  Type    Reason             Age   From                       Message
  ----    ------             ----  ----                       -------
  Normal  SuccessfulRescale  64s   horizontal-pod-autoscaler  New size: 5; reason: cpu resource utilization (percentage of request) above target
  • 3 to 5 in one step. The sum came out above 5, so it went straight to --max.
  • Still 81% at 5 pods. The load wanted more, but --max is a hard cap. That cap is what protects your nodes from a runaway scale-up.
  • About 41m per pod against a 200m limit. The HPA works from the request, not the limit.

I didn't see the scale-down. Nine and a half minutes after creating the HPA, it was still at 5, and I cleaned up before the 5-minute window had passed. With the load gone, it would have dropped back toward 2. Scale-down is slow on purpose.

Choosing nodes

nodeSelector and node affinity

(cp1)

BASH
k label node worker1 disk=ssd
k get nodes -L disk
cat > sched.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata: { name: on-ssd }
spec:
  nodeSelector: { disk: ssd }
  containers:
  - { name: nginx, image: nginx:1.28-alpine }
---
apiVersion: v1
kind: Pod
metadata: { name: on-nvme }
spec:
  nodeSelector: { disk: nvme }
  containers:
  - { name: nginx, image: nginx:1.28-alpine }
---
apiVersion: v1
kind: Pod
metadata: { name: prefer-nvme }
spec:
  affinity:
    nodeAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - { key: disk, operator: In, values: [nvme] }
  containers:
  - { name: nginx, image: nginx:1.28-alpine }
EOF
k apply -f sched.yaml
sleep 10
k get pods on-ssd on-nvme prefer-nvme -o wide
k describe pod on-nvme | grep -A3 Events
  • k label node NODE KEY=VALUE adds a label. -L disk adds a DISK column.
  • nodeSelector is the simple form: only nodes with all these labels.
  • preferredDuringScheduling... is the soft form of node affinity: try for a match, run anywhere if there isn't one. weight (1 to 100) ranks several preferences.
  • requiredDuringScheduling... is the hard form. It's like nodeSelector, with operators such as In, NotIn and Exists.
  • IgnoredDuringExecution: affinity is checked only when a pod is placed. Changing a node's labels later doesn't move running pods.
Code
NAME      STATUS   ROLES           AGE     VERSION   DISK
cp1       Ready    control-plane   5d13h   v1.37.3   
worker1   Ready    <none>          5d13h   v1.37.3   ssd
worker2   Ready    <none>          5d13h   v1.37.3   
Code
NAME          READY   STATUS    RESTARTS   AGE   IP               NODE      NOMINATED NODE   READINESS GATES
on-ssd        1/1     Running   0          10s   10.244.235.141   worker1   <none>           <none>
on-nvme       0/1     Pending   0          10s   <none>           <none>    <none>           <none>
prefer-nvme   1/1     Running   0          10s   10.244.189.84    worker2   <none>           <none>
Events:
  Type     Reason            Age   From               Message
  ----     ------            ----  ----               -------
  Warning  FailedScheduling  10s   default-scheduler  0/3 nodes are available: 1 node(s) had untolerated taint(s), 2 node(s) didn't match Pod's node affinity/selector. preemption: 0/3 nodes are available: 3 Preemption is not helpful for scheduling.
  • on-ssd went to worker1, the only node labeled disk=ssd.
  • on-nvme is Pending, and the message accounts for every node: the taint is cp1's control-plane taint from Lesson 2, and the two that didn't match are the workers. "Preemption is not helpful" means evicting lower-priority pods wouldn't make room.
  • prefer-nvme ran anyway, on worker2. Preferred is a wish, not a rule.

Taints and tolerations

A taint is a "keep out" mark on a node. A toleration is a pass on a pod that lets it ignore one. The scheduler won't place a pod on a tainted node unless the pod tolerates the taint.

(cp1)

BASH
k get pods -l app=web -o wide
k taint node worker2 dedicated=batch:NoSchedule
k get pods -l app=web -o wide
  • k taint node NODE KEY=VALUE:EFFECT: the key and value are names you choose; the effect sets how strict it is.
Code
NAME                   READY   STATUS    RESTARTS   AGE     IP               NODE      ...
web-86d64bbbf9-5pm5l   1/1     Running   0          9m51s   10.244.189.74    worker2   ...
web-86d64bbbf9-5wfnr   1/1     Running   0          5m3s    10.244.189.79    worker2   ...
web-86d64bbbf9-7hdhm   1/1     Running   0          9m50s   10.244.235.143   worker1   ...
web-86d64bbbf9-p2rqr   1/1     Running   0          5m3s    10.244.235.142   worker1   ...
web-86d64bbbf9-zjb2n   1/1     Running   0          9m50s   10.244.189.76    worker2   ...
node/worker2 tainted

The list after the taint was identical: three web pods still on worker2. NoSchedule only affects new placements.

EffectNew pods without a tolerationPods already running
NoScheduleNot placed thereLeft alone
PreferNoScheduleAvoided, unless there's nowhere elseLeft alone
NoExecuteNot placed thereEvicted (Lesson 3)

Now 4 pods without a toleration, and 4 with one:

(cp1)

BASH
cat > batch.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: { name: batch }
spec:
  replicas: 4
  selector: { matchLabels: { app: batch } }
  template:
    metadata: { labels: { app: batch } }
    spec:
      tolerations:
      - { key: dedicated, operator: Equal, value: batch, effect: NoSchedule }
      containers:
      - { name: nginx, image: nginx:1.28-alpine }
EOF
k create deploy plain --image=nginx:1.28-alpine --replicas=4
k apply -f batch.yaml
sleep 15
k get pods -l 'app in (plain,batch)' -o wide

-l 'app in (plain,batch)' is a set-based selector: pods whose app label is either value.

Code
NAME                     READY   STATUS    RESTARTS   AGE   IP               NODE      ...
batch-5676b5b75c-2cf67   1/1     Running   0          15s   10.244.189.75    worker2   ...
batch-5676b5b75c-7zmwj   1/1     Running   0          15s   10.244.235.165   worker1   ...
batch-5676b5b75c-hwcwf   1/1     Running   0          15s   10.244.235.160   worker1   ...
batch-5676b5b75c-rlrbq   1/1     Running   0          15s   10.244.189.78    worker2   ...
plain-5486f4d6c-hcv4q    1/1     Running   0          15s   10.244.235.134   worker1   ...
plain-5486f4d6c-pg9th    1/1     Running   0          15s   10.244.235.138   worker1   ...
plain-5486f4d6c-rctfg    1/1     Running   0          15s   10.244.235.145   worker1   ...
plain-5486f4d6c-xb8w7    1/1     Running   0          15s   10.244.235.176   worker1   ...
  • All four plain pods on worker1: worker2 is tainted and cp1 has its own taint.
  • batch split across both workers. A toleration allows; it doesn't attract. It removes the "keep out" for that pod, and nothing more.

To dedicate a node, you need both halves: a taint plus a toleration to keep everyone else off, and a nodeSelector or affinity to make the chosen pods go only there.

ResourceQuotas

A ResourceQuota caps a namespace's totals.

(cp1)

BASH
k create quota wl-quota --hard=pods=20,requests.cpu=1,limits.memory=2Gi
k describe quota wl-quota
k run noreq --image=nginx:1.28-alpine
Code
Resource       Used   Hard
--------       ----   ----
limits.memory  320Mi  2Gi
pods           18     20
requests.cpu   250m   1
Error from server (Forbidden): pods "noreq" is forbidden: failed quota: wl-quota: must specify limits.memory for: noreq; requests.cpu for: noreq
  • Used: 320Mi is the 5 web pods at 64Mi each, and 250m is 5 times 50m.
  • pods 18/20: every pod counts, including the dead hog and the crash-looping live-fail.
  • must specify, not exceeded. Once a quota covers CPU or memory, every new pod must set those values. Pods that were already running are left alone.

Give a pod the values the quota needs, without opening an editor:

(cp1)

BASH
k run withreq --image=nginx:1.28-alpine --dry-run=client -o yaml > withreq.yaml
k set resources -f withreq.yaml --local --requests=cpu=50m --limits=memory=64Mi -o yaml > withreq-fixed.yaml
k apply -f withreq-fixed.yaml

set resources -f FILE --local -o yaml edits the YAML from the file without touching the cluster (--local), and prints the result.

Code
pod/withreq created

What happens when a Deployment hits the quota:

(cp1)

BASH
k scale deploy plain --replicas=6
sleep 5
k get deploy plain
Code
deployment.apps/plain scaled
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
plain   4/6     4            4           68s

4/6, and no Pending pods. The quota didn't stop a pod; it stopped the ReplicaSet from creating the two new ones, because plain sets no requests. So there's nothing to describe on the pod side. The reason is in the ReplicaSet's events: k describe rs -l app=plain. Read the whole Events list: I used grep -A4 Events, and it cut off after the two successful creates, before the failure lines.

How the drills work

Each drill is a task to do from a blank terminal. Try it first, without looking. Then open "Show the fast way" to compare your commands, and read the notes under them: they cover the part people usually get wrong. Repeat a drill a few days later until you can do it cold, because the exam leaves little time to look things up.

The drills

Update Deployment web's nginx container to nginx:1.28-alpine, record why, then roll back to the revision before the update.

Show the fast way
BASH
k set image deploy/web nginx=nginx:1.28-alpine
k annotate deploy/web kubernetes.io/change-cause="nginx 1.28" --overwrite
k rollout status deploy/web
k rollout history deploy/web
k rollout undo deploy/web --to-revision=N
k rollout status deploy/web

The container name comes first in set image: check it with k get deploy web -o jsonpath='{.spec.template.spec.containers[*].name}'. --overwrite replaces an existing CHANGE-CAUSE instead of failing. Use --to-revision when you need a specific one; a plain undo only flips between the last two.

Create a ConfigMap with LOG_LEVEL=debug and a Secret with API_KEY=abc123. Give Deployment web both as environment variables, and prove the pods see them.

Show the fast way
BASH
k create configmap web-config --from-literal=LOG_LEVEL=debug
k create secret generic web-secret --from-literal=API_KEY=abc123
k set env deploy/web --from=configmap/web-config
k set env deploy/web --from=secret/web-secret
k rollout status deploy/web
k exec deploy/web -- env | grep -E "LOG_LEVEL|API_KEY"

Changing the ConfigMap later won't change running pods. Environment variables are read at container start: k rollout restart deploy/web picks up new values.

Add a readiness probe to Deployment web that checks GET / on port 80 every 5 seconds, and a liveness probe that checks the same page after a 10 second delay.

Show the fast way
YAML
        readinessProbe:
          httpGet: { path: /, port: 80 }
          periodSeconds: 5
        livenessProbe:
          httpGet: { path: /, port: 80 }
          initialDelaySeconds: 10
BASH
k edit deploy web
k rollout status deploy/web
k describe pod -l app=web | grep -E "Liveness|Readiness"

The probes go under the container, at the same level as image. A readiness failure leaves pods Running but 0/1 and out of the Service; a liveness failure restarts them. Copy the shape from the docs page "Configure Liveness, Readiness and Startup Probes".

Make Deployment web scale between 2 and 5 replicas, aiming for 60% CPU. Check the autoscaler can read metrics.

Show the fast way
BASH
k set resources deploy/web --requests=cpu=50m
k autoscale deploy web --min=2 --max=5 --cpu=60%
k get hpa web
k describe hpa web | grep -A4 Conditions

No CPU request, no autoscaling: the target is a percentage of the request, so TARGETS shows <unknown> without one. ScalingActive True means metrics are flowing.

Reserve node NODE for pods labeled app=batch: other pods must stay off it, and batch pods must run only there.

Show the fast way
BASH
k taint node NODE dedicated=batch:NoSchedule
k label node NODE dedicated=batch
YAML
      tolerations:
      - { key: dedicated, operator: Equal, value: batch, effect: NoSchedule }
      nodeSelector: { dedicated: batch }
BASH
k get pods -l app=batch -o wide

Both halves are needed. The taint keeps others off; the toleration only lets batch on. The nodeSelector is what keeps batch from landing anywhere else. Remove them afterwards with k taint node NODE dedicated=batch:NoSchedule- and k label node NODE dedicated-.

Limit namespace NS to 10 pods and 2Gi of memory limits, then create a pod that the quota accepts.

Show the fast way
BASH
k create quota ns-quota -n NS --hard=pods=10,limits.memory=2Gi
k run app -n NS --image=nginx:1.28-alpine --dry-run=client -o yaml > app.yaml
k set resources -f app.yaml --local --limits=memory=128Mi -o yaml > app-fixed.yaml
k apply -f app-fixed.yaml
k describe quota ns-quota -n NS

A memory quota means every new pod must set a memory limit, or it's rejected with must specify. If a Deployment stops short of its replica count with no Pending pods, read its ReplicaSet's events.

On exam day

  • Watch every rollout with k rollout status, and check the result with k get pods.
  • Check container names before k set image; it's the most common slip.
  • Use --to-revision when a task names a version to go back to.
  • Put probes and resources under the container, in the right YAML level. Copy the shape from the docs.
  • Read Pending pods with k describe: the FailedScheduling message accounts for every node.
  • Undo what you change on nodes, such as labels and taints, unless the task says to keep them.

Clean up

(cp1)

BASH
k taint node worker2 dedicated=batch:NoSchedule-
k label node worker1 disk-
k config set-context --current --namespace=default
k delete ns wl-lab
rm probes.yaml hog.yaml sched.yaml batch.yaml withreq.yaml withreq-fixed.yaml
k describe node worker2 | grep Taints
k get nodes -L disk
k config view --minify | grep namespace

A trailing - removes: ...:NoSchedule- removes the taint, and disk- removes the label. config view --minify shows only the current context.

Code
node/worker2 untainted
node/worker1 unlabeled
Context "kubernetes-admin@kubernetes" modified.
namespace "wl-lab" deleted
Taints:             <none>
NAME      STATUS   ROLES           AGE     VERSION   DISK
cp1       Ready    control-plane   5d13h   v1.37.3   
worker1   Ready    <none>          5d13h   v1.37.3   
worker2   Ready    <none>          5d13h   v1.37.3   
    namespace: default

Node labels and taints live on the nodes, not in the namespace, so deleting wl-lab alone would have left them behind.

In real life

  • Teams roll out by changing YAML in Git, and a tool like Argo CD or Flux applies it. k set image is for labs and emergencies.
  • Readiness probes matter more than liveness ones. A wrong liveness probe restarts healthy apps in a loop, as you saw. Many teams start with readiness only.
  • Set memory limits; be careful with CPU limits. A memory leak should be killed before it hurts the node. A CPU limit throttles an app even when the node has CPU to spare, so some teams set CPU requests only.
  • Secrets need more than base64: encryption at rest, tight RBAC, and often an external secret store.
  • Dedicated nodes (for GPUs, or noisy batch work) are always a taint plus a selector, exactly as in the drill.

Spot the problem

Work out what's wrong before you read the explanation.

"The rollout broke production." A teammate ran k set image with a typo in the tag, and says the site went down. k get pods shows three Running pods from the old ReplicaSet and one ErrImagePull. Did it break production? No. The rolling update added one new pod and stopped when it couldn't start, so the old pods kept serving. Fix the tag, or k rollout undo.

"We changed the ConfigMap, but the app still uses the old value." A team updated LOG_LEVEL in a ConfigMap an hour ago, and the pods still log at the old level. What's missing? A restart. Environment variables are read when a container starts. k rollout restart deploy/NAME replaces the pods, and the new ones read the new value.

"We tainted the GPU node for the ML jobs, and they still land elsewhere." The ML Deployment tolerates the taint, but half its pods run on ordinary nodes. Why? A toleration allows; it doesn't attract. Add a nodeSelector or node affinity for the GPU node's label.

Keep this

ToUse
Set a default namespacek config set-context --current --namespace=NS
Change an imagek set image deploy/NAME CONTAINER=IMAGE
Watch a rolloutk rollout status deploy/NAME
History and rollbackk rollout history deploy/NAME, k rollout undo deploy/NAME --to-revision=N
Restart all podsk rollout restart deploy/NAME
ConfigMap or Secret into envk set env deploy/NAME --from=configmap/CM (or secret/S)
Read a Secretk get secret S -o jsonpath=... then base64 -d
Requests and limitsk set resources deploy/NAME --requests=cpu=50m --limits=memory=64Mi
Autoscalek autoscale deploy NAME --min=2 --max=5 --cpu=50%
Label a nodek label node NODE KEY=VALUE (remove: KEY-)
Taint a nodek taint node NODE KEY=VALUE:NoSchedule (remove: add -)
Quota a namespacek create quota NAME --hard=pods=10,requests.cpu=1
Add resources to a YAML filek set resources -f FILE --local ... -o yaml
Exit code 137OOMKilled: a memory limit

Where you are now

You've watched a bad rollout stall safely and rolled it back, and you know how history really numbers revisions. You've fed configuration into pods, seen that a Secret is only encoded, and restarted pods to pick up changes. You've broken a liveness and a readiness probe and read the difference, killed a container with its memory limit, and watched an autoscaler scale up under load. And you've steered pods with labels, affinity, taints and tolerations, and hit a quota. Lesson 11 covers the last domain: storage.

Check yourself

  1. A Deployment with 3 replicas is updated to an image tag that doesn't exist. What do you see?

  2. rollout history shows revisions 1, 2 and 3. You run rollout undo. What does history show next?

  3. A pod shows Running, 0/1, with 0 restarts, and its Service has no endpoints. Which probe is failing?

  4. A container ends with Reason OOMKilled and exit code 137. What do you change?

  5. An HPA shows TARGETS cpu: unknown/50% and never scales. metrics-server is running. What's the likely cause?

  6. Node gpu1 has a taint, and the ML Deployment tolerates it. Some ML pods still run on other nodes. What's missing?

Key terms

  • Rolling update: replacing a Deployment's pods a few at a time, within maxSurge and maxUnavailable.
  • Revision: one version of a Deployment's pod template, kept for rollout undo.
  • ConfigMap / Secret: key-value configuration for pods. A Secret's values are base64-encoded, not encrypted.
  • Liveness / readiness / startup probe: health checks that restart a container, remove a pod from Services, or hold the other probes until startup finishes.
  • Requests / limits: what the scheduler reserves for a container, and the most it may use.
  • OOMKilled: a container killed by the kernel for passing its memory limit (exit code 137).
  • QoS class: Guaranteed, Burstable or BestEffort, from a pod's requests and limits. It sets eviction order.
  • HPA (Horizontal Pod Autoscaler): changes the replica count from CPU use as a percentage of request.
  • nodeSelector / node affinity: rules that limit or prefer the nodes a pod may use, by node label.
  • Taint / toleration: a "keep out" mark on a node, and a pod's pass to ignore it.
  • ResourceQuota: caps a namespace's total pods, requests and limits.

Go deeper