CKA: Workloads and Scheduling
15% of the CKA exam, 5 competencies. Back to the CKA overview.
Each competency lists what to know and the official documentation to read, then a demo you can run. Demos run on the demo lab, a throwaway kind cluster on your own machine; set it up once before you start.
Understand application deployments and how to perform rolling update and rollbacks
Section titled “Understand application deployments and how to perform rolling update and rollbacks”Know
- A Deployment manages ReplicaSets; any change to the pod template starts a rollout bounded by
maxSurgeandmaxUnavailable. kubectl rollout status,history,undo, andrestartare the tools.
Read
Demo: Roll out, break, roll back
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace cka-rolloutkubectl config set-context --current --namespace=cka-rollout -
Deploy version one and record why.
Terminal window kubectl create deployment web --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 --replicas=4 -- /agnhost netexec --http-port=8080kubectl annotate deployment web kubernetes.io/change-cause="initial release"kubectl rollout status deployment/web -
Roll out a broken image.
Terminal window kubectl set image deployment/web agnhost=registry.k8s.io/e2e-test-images/agnhost:0.0.0-missingkubectl annotate deployment web kubernetes.io/change-cause="bad tag" --overwritekubectl rollout status deployment/web --timeout=60skubectl get pods -l app=web -
Read the history and roll back.
Terminal window kubectl rollout history deployment/webkubectl rollout undo deployment/web --to-revision=1kubectl rollout status deployment/webkubectl get pods -l app=web
What you should see: During the bad rollout only one new pod is created and it sits in ImagePullBackOff, while three old pods keep serving: the default maxUnavailable: 25% protects you. rollout undo brings back revision 1 without touching the YAML.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace cka-rolloutPractise
- Roll out a bad image, watch it stall, and roll back to a specific revision with
--to-revision.
On this site
Use ConfigMaps and Secrets to configure applications
Section titled “Use ConfigMaps and Secrets to configure applications”Know
- Consume as environment variables (fixed at start) or volume files (updated by the kubelet, except with
subPath).
Read
Demo: Same config, two delivery methods
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace cka-configkubectl config set-context --current --namespace=cka-config -
Create a ConfigMap and a Secret.
Terminal window kubectl create configmap app-config --from-literal=LOG_LEVEL=info --from-literal=app.properties='mode=demo'kubectl create secret generic app-secret --from-literal=DB_PASSWORD='s3cret'kubectl get secret app-secret -o jsonpath='{.data.DB_PASSWORD}' | base64 -d; echo -
Consume them as environment variables and as files.
Terminal window kubectl apply -f - <<'EOF'apiVersion: v1kind: Podmetadata:name: configuredspec:containers:- name: appimage: registry.k8s.io/e2e-test-images/busybox:1.37.0-2command: ["sh", "-c", "echo LOG_LEVEL=$LOG_LEVEL; ls /etc/app; cat /etc/app/app.properties; sleep 3600"]env:- name: LOG_LEVELvalueFrom:configMapKeyRef:name: app-configkey: LOG_LEVEL- name: DB_PASSWORDvalueFrom:secretKeyRef:name: app-secretkey: DB_PASSWORDvolumeMounts:- name: configmountPath: /etc/appvolumes:- name: configconfigMap:name: app-configEOFkubectl wait --for=condition=Ready pod/configured --timeout=120s && kubectl logs configured -
Change the ConfigMap and see which method picks it up.
Terminal window kubectl create configmap app-config --from-literal=LOG_LEVEL=debug --from-literal=app.properties='mode=changed' --dry-run=client -o yaml | kubectl apply -f -sleep 70; kubectl exec configured -- sh -c 'echo env=$LOG_LEVEL; cat /etc/app/app.properties'
What you should see: The Secret is only base64: anyone who can read it can decode it. After the update the mounted file shows mode=changed (within about a minute), but the environment variable still says info. Env vars are read once at container start.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace cka-configPractise
- Mount a Secret as a file with mode 0400 and inject one ConfigMap key as an environment variable.
On this site
Configure workload autoscaling
Section titled “Configure workload autoscaling”Know
- The HorizontalPodAutoscaler scales replicas on metrics; resource-based scaling divides usage by requests, so pods need requests.
- Vertical scaling (VPA) and the cluster autoscaler are add-ons outside core Kubernetes.
Read
Demo: Scale on CPU with a HorizontalPodAutoscaler
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace cka-hpakubectl config set-context --current --namespace=cka-hpa -
Use the example app from the official HPA walkthrough. It needs metrics-server, installed in the lab setup.
Terminal window kubectl apply -f https://k8s.io/examples/application/php-apache.yamlkubectl autoscale deployment php-apache --cpu=50% --min=1 --max=5kubectl get hpa php-apache -
Put load on it from another pod and watch.
Terminal window kubectl run load --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- sh -c 'while sleep 0.01; do wget -q -O- http://php-apache; done'kubectl get hpa php-apache -w # Ctrl-C after a few minutes -
Remove the load and read why it scaled.
Terminal window kubectl delete pod loadkubectl describe hpa php-apache | sed -n '/Conditions:/,$p'
What you should see: CPU climbs above 50% of the request and replicas rise toward 5. After the load stops, scale-down waits for the 5-minute stabilization window before removing pods. --cpu replaces the deprecated --cpu-percent flag in kubectl v1.37.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace cka-hpaPractise
- Create an HPA with
kubectl autoscale deployment web --cpu=50% --min=2 --max=5and check its targets.
On this site
Understand the primitives used to create robust, self-healing, application deployments
Section titled “Understand the primitives used to create robust, self-healing, application deployments”Know
- Controllers replace failed pods; probes tell the kubelet when to restart or stop sending traffic; PodDisruptionBudgets limit voluntary disruptions.
Read
Demo: Probes, a disruption budget, and a drain
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace cka-robustkubectl config set-context --current --namespace=cka-robust -
A Deployment with readiness and liveness probes and a PodDisruptionBudget.
Terminal window kubectl apply -f - <<'EOF'apiVersion: apps/v1kind: Deploymentmetadata:name: robustspec:replicas: 3selector:matchLabels:app: robusttemplate:metadata:labels:app: robustspec:containers:- name: appimage: registry.k8s.io/e2e-test-images/agnhost:2.66.1args: ["netexec", "--http-port=8080"]readinessProbe:httpGet: {path: /readyz, port: 8080}periodSeconds: 5livenessProbe:httpGet: {path: /healthz, port: 8080}periodSeconds: 10---apiVersion: policy/v1kind: PodDisruptionBudgetmetadata:name: robustspec:minAvailable: 2selector:matchLabels:app: robustEOFkubectl rollout status deployment/robust -
Kill the process inside one pod: the liveness probe and restart policy recover it.
Terminal window POD=$(kubectl get pod -l app=robust -o jsonpath='{.items[0].metadata.name}')kubectl exec $POD -- wget -qO- 'http://localhost:8080/exit?code=1' || truesleep 15; kubectl get pod $POD -
Drain a worker: the PDB decides how fast pods can leave.
Terminal window kubectl get pdb robustkubectl drain kind-worker --ignore-daemonsets --delete-emptydir-data --timeout=90skubectl get pods -l app=robust -o widekubectl uncordon kind-worker
What you should see: The killed container restarts (RESTARTS goes to 1) in the same pod. The drain evicts pods one at a time and never lets fewer than 2 be available; with all 3 on one node you would see Cannot evict pod as it would violate the pod’s disruption budget retries until replacements are ready elsewhere.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace cka-robustOn this site
Configure Pod admission and scheduling (limits, node affinity, etc.)
Section titled “Configure Pod admission and scheduling (limits, node affinity, etc.)”Know
- Requests and limits, LimitRange defaults, and ResourceQuota caps are checked at admission. Node affinity, taints, tolerations, and topology spread constraints shape placement.
Read
- Resource management for pods and containers
- Limit ranges
- Assigning pods to nodes
- Pod topology spread constraints
Demo: Defaults, quotas, affinity, and taints together
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace cka-admissionkubectl config set-context --current --namespace=cka-admission -
Give the namespace default limits and a quota.
Terminal window kubectl apply -f - <<'EOF'apiVersion: v1kind: LimitRangemetadata:name: defaultsspec:limits:- type: Containerdefault: {cpu: 200m, memory: 128Mi}defaultRequest: {cpu: 100m, memory: 64Mi}---apiVersion: v1kind: ResourceQuotametadata:name: smallspec:hard:pods: "3"requests.cpu: "500m"EOFkubectl run p1 --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pausekubectl get pod p1 -o jsonpath='{.spec.containers[0].resources}{"\n"}'kubectl describe resourcequota small -
Taint a node, then place a pod there with a toleration and node affinity.
Terminal window kubectl taint nodes kind-worker2 dedicated=demo:NoSchedulekubectl apply -f - <<'EOF'apiVersion: v1kind: Podmetadata:name: tolerantspec:tolerations:- key: dedicatedoperator: Equalvalue: demoeffect: NoScheduleaffinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: kubernetes.io/hostnameoperator: Invalues: ["kind-worker2"]containers:- name: appimage: registry.k8s.io/e2e-test-images/agnhost:2.66.1args: ["pause"]EOFkubectl get pod tolerant -o wide -
Hit the quota.
Terminal window kubectl run p3 --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pausekubectl run p4 --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pause
What you should see: p1 has resources it never asked for: the LimitRange filled them in at admission. tolerant lands on kind-worker2 despite the taint. p4 is rejected with exceeded quota: small because three pods already exist.
Clean up:
kubectl taint nodes kind-worker2 dedicated=demo:NoSchedule-kubectl config set-context --current --namespace=defaultkubectl delete namespace cka-admissionPractise
- Taint a node and schedule one pod onto it with a toleration plus node affinity.
On this site
Domain and competency names are from the CNCF CKA curriculum (v1.37), cncf/curriculum, licensed CC BY 4.0. Summaries, demos, and exercises are original to this site.