Skip to content

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 maxSurge and maxUnavailable.
  • kubectl rollout status, history, undo, and restart are the tools.

Read

Demo: Roll out, break, roll back

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace cka-rollout
    kubectl config set-context --current --namespace=cka-rollout
  2. 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=8080
    kubectl annotate deployment web kubernetes.io/change-cause="initial release"
    kubectl rollout status deployment/web
  3. Roll out a broken image.

    Terminal window
    kubectl set image deployment/web agnhost=registry.k8s.io/e2e-test-images/agnhost:0.0.0-missing
    kubectl annotate deployment web kubernetes.io/change-cause="bad tag" --overwrite
    kubectl rollout status deployment/web --timeout=60s
    kubectl get pods -l app=web
  4. Read the history and roll back.

    Terminal window
    kubectl rollout history deployment/web
    kubectl rollout undo deployment/web --to-revision=1
    kubectl rollout status deployment/web
    kubectl 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:

Terminal window
kubectl config set-context --current --namespace=default
kubectl delete namespace cka-rollout

Practise

  • 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

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace cka-config
    kubectl config set-context --current --namespace=cka-config
  2. 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
  3. Consume them as environment variables and as files.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: v1
    kind: Pod
    metadata:
    name: configured
    spec:
    containers:
    - name: app
    image: registry.k8s.io/e2e-test-images/busybox:1.37.0-2
    command: ["sh", "-c", "echo LOG_LEVEL=$LOG_LEVEL; ls /etc/app; cat /etc/app/app.properties; sleep 3600"]
    env:
    - name: LOG_LEVEL
    valueFrom:
    configMapKeyRef:
    name: app-config
    key: LOG_LEVEL
    - name: DB_PASSWORD
    valueFrom:
    secretKeyRef:
    name: app-secret
    key: DB_PASSWORD
    volumeMounts:
    - name: config
    mountPath: /etc/app
    volumes:
    - name: config
    configMap:
    name: app-config
    EOF
    kubectl wait --for=condition=Ready pod/configured --timeout=120s && kubectl logs configured
  4. 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:

Terminal window
kubectl config set-context --current --namespace=default
kubectl delete namespace cka-config

Practise

  • Mount a Secret as a file with mode 0400 and inject one ConfigMap key as an environment variable.

On this site

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

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace cka-hpa
    kubectl config set-context --current --namespace=cka-hpa
  2. 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.yaml
    kubectl autoscale deployment php-apache --cpu=50% --min=1 --max=5
    kubectl get hpa php-apache
  3. 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
  4. Remove the load and read why it scaled.

    Terminal window
    kubectl delete pod load
    kubectl 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:

Terminal window
kubectl config set-context --current --namespace=default
kubectl delete namespace cka-hpa

Practise

  • Create an HPA with kubectl autoscale deployment web --cpu=50% --min=2 --max=5 and 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

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace cka-robust
    kubectl config set-context --current --namespace=cka-robust
  2. A Deployment with readiness and liveness probes and a PodDisruptionBudget.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: robust
    spec:
    replicas: 3
    selector:
    matchLabels:
    app: robust
    template:
    metadata:
    labels:
    app: robust
    spec:
    containers:
    - name: app
    image: registry.k8s.io/e2e-test-images/agnhost:2.66.1
    args: ["netexec", "--http-port=8080"]
    readinessProbe:
    httpGet: {path: /readyz, port: 8080}
    periodSeconds: 5
    livenessProbe:
    httpGet: {path: /healthz, port: 8080}
    periodSeconds: 10
    ---
    apiVersion: policy/v1
    kind: PodDisruptionBudget
    metadata:
    name: robust
    spec:
    minAvailable: 2
    selector:
    matchLabels:
    app: robust
    EOF
    kubectl rollout status deployment/robust
  3. 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' || true
    sleep 15; kubectl get pod $POD
  4. Drain a worker: the PDB decides how fast pods can leave.

    Terminal window
    kubectl get pdb robust
    kubectl drain kind-worker --ignore-daemonsets --delete-emptydir-data --timeout=90s
    kubectl get pods -l app=robust -o wide
    kubectl 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:

Terminal window
kubectl config set-context --current --namespace=default
kubectl delete namespace cka-robust

On 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

Demo: Defaults, quotas, affinity, and taints together

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace cka-admission
    kubectl config set-context --current --namespace=cka-admission
  2. Give the namespace default limits and a quota.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: v1
    kind: LimitRange
    metadata:
    name: defaults
    spec:
    limits:
    - type: Container
    default: {cpu: 200m, memory: 128Mi}
    defaultRequest: {cpu: 100m, memory: 64Mi}
    ---
    apiVersion: v1
    kind: ResourceQuota
    metadata:
    name: small
    spec:
    hard:
    pods: "3"
    requests.cpu: "500m"
    EOF
    kubectl run p1 --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pause
    kubectl get pod p1 -o jsonpath='{.spec.containers[0].resources}{"\n"}'
    kubectl describe resourcequota small
  3. Taint a node, then place a pod there with a toleration and node affinity.

    Terminal window
    kubectl taint nodes kind-worker2 dedicated=demo:NoSchedule
    kubectl apply -f - <<'EOF'
    apiVersion: v1
    kind: Pod
    metadata:
    name: tolerant
    spec:
    tolerations:
    - key: dedicated
    operator: Equal
    value: demo
    effect: NoSchedule
    affinity:
    nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
    nodeSelectorTerms:
    - matchExpressions:
    - key: kubernetes.io/hostname
    operator: In
    values: ["kind-worker2"]
    containers:
    - name: app
    image: registry.k8s.io/e2e-test-images/agnhost:2.66.1
    args: ["pause"]
    EOF
    kubectl get pod tolerant -o wide
  4. Hit the quota.

    Terminal window
    kubectl run p3 --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pause
    kubectl 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:

Terminal window
kubectl taint nodes kind-worker2 dedicated=demo:NoSchedule-
kubectl config set-context --current --namespace=default
kubectl delete namespace cka-admission

Practise

  • 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.