CKAD: Application Deployment
20% of the CKAD exam, 4 competencies. Back to the CKAD 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.
Use Kubernetes primitives to implement common deployment strategies (e.g. blue/green or canary)
Section titled “Use Kubernetes primitives to implement common deployment strategies (e.g. blue/green or canary)”Know
- Blue/green: two Deployments, switch the Service selector. Canary: two Deployments behind one Service, with replica counts setting the traffic share.
Read
Demo: Blue/green with a selector, canary with replicas
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace ckad-strategykubectl config set-context --current --namespace=ckad-strategy -
Blue/green: two Deployments, one Service. Switch by changing the selector.
Terminal window for c in blue green; dokubectl create deployment $c --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- /agnhost netexec --http-port=8080kubectl label deployment $c colour=$ckubectl patch deployment $c -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"colour\":\"$c\"}}}}}"donekubectl create service clusterip live --tcp=80:8080kubectl patch service live -p '{"spec":{"selector":{"colour":"blue"}}}'kubectl run c1 --rm -i --restart=Never --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- wget -qO- -T 3 http://live/hostname; echokubectl patch service live -p '{"spec":{"selector":{"colour":"green"}}}'kubectl run c2 --rm -i --restart=Never --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- wget -qO- -T 3 http://live/hostname; echo -
Canary: a Service that selects a shared label, and replicas in a 3 to 1 ratio.
Terminal window kubectl create service clusterip canary-svc --tcp=80:8080kubectl patch service canary-svc -p '{"spec":{"selector":{"track":"web"}}}'kubectl create deployment stable --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 --replicas=3 -- /agnhost netexec --http-port=8080kubectl create deployment canary --image=registry.k8s.io/e2e-test-images/agnhost:2.55 --replicas=1 -- /agnhost netexec --http-port=8080for d in stable canary; do kubectl patch deployment $d -p '{"spec":{"template":{"metadata":{"labels":{"track":"web"}}}}}'; donekubectl rollout status deployment/stable && kubectl rollout status deployment/canarykubectl run c3 --rm -i --restart=Never --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- sh -c 'for i in $(seq 1 20); do wget -qO- -T 3 http://canary-svc/hostname; echo; done' | cut -d- -f1 | sort | uniq -c
What you should see: Blue/green flips all traffic at once: the first reply is from a blue pod, the second from green. The canary gets roughly a quarter of the 20 requests because it is one pod in four. For an exact percentage regardless of pod count, use weighted backendRefs in a Gateway API HTTPRoute.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace ckad-strategyPractise
- Run a 4-to-1 canary with two Deployments sharing an
applabel, then promote it.
Understand Deployments and how to perform rolling updates
Section titled “Understand Deployments and how to perform rolling updates”Know
maxSurgeandmaxUnavailablecontrol the pace; readiness decides when a new pod counts.kubectl rollout undogoes back.
Read
Demo: Control the pace of a rollout
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace ckad-rollingkubectl config set-context --current --namespace=ckad-rolling -
A Deployment that adds one pod at a time and never drops below full capacity.
Terminal window kubectl apply -f - <<'EOF'apiVersion: apps/v1kind: Deploymentmetadata:name: pacedspec:replicas: 4minReadySeconds: 5strategy:type: RollingUpdaterollingUpdate:maxSurge: 1maxUnavailable: 0selector:matchLabels:app: pacedtemplate:metadata:labels:app: pacedspec:containers:- name: appimage: registry.k8s.io/e2e-test-images/agnhost:2.66.1args: ["netexec", "--http-port=8080"]readinessProbe:httpGet: {path: /readyz, port: 8080}EOFkubectl rollout status deployment/paced -
Update it, pause halfway, look, and resume.
Terminal window kubectl set image deployment/paced app=registry.k8s.io/e2e-test-images/agnhost:2.55sleep 8; kubectl rollout pause deployment/pacedkubectl get replicasets -l app=pacedkubectl rollout resume deployment/pacedkubectl rollout status deployment/pacedkubectl rollout history deployment/paced
What you should see: While paused, the old and new ReplicaSets both have pods and the total never goes below 4. maxUnavailable: 0 plus a readiness probe means capacity only drops after a new pod is ready; minReadySeconds adds a soak time before each next step.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace ckad-rollingOn this site
Use the Helm package manager to deploy existing packages
Section titled “Use the Helm package manager to deploy existing packages”Know
- Find a chart, inspect its values (
helm show values), install with overrides, upgrade, and roll back.helm list -Ashows releases.
Read
Demo: Install, upgrade, and roll back a public chart
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace ckad-helmkubectl config set-context --current --namespace=ckad-helm -
Install podinfo, a small demo app published as an OCI chart. Look before you install.
Terminal window helm show values oci://ghcr.io/stefanprodan/charts/podinfo --version 6.17.0 | head -20helm install web oci://ghcr.io/stefanprodan/charts/podinfo --version 6.17.0 -n ckad-helmkubectl rollout status deployment/web-podinfohelm list -
Upgrade with a changed value, then roll back.
Terminal window helm upgrade web oci://ghcr.io/stefanprodan/charts/podinfo --version 6.17.0 -n ckad-helm --set replicaCount=3 --set ui.message=upgradedhelm history webhelm get values webhelm rollback web 1helm history webkubectl get deployment web-podinfo
What you should see: helm history shows revision 1 (install), 2 (upgrade), and 3 (rollback to 1). After the rollback the Deployment is back to 1 replica. helm get values shows only the values you set, not the chart defaults.
Clean up:
helm uninstall web -n ckad-helmkubectl config set-context --current --namespace=defaultkubectl delete namespace ckad-helmPractise
- Install a chart into its own namespace with
--create-namespace, upgrade one value, then roll back.
Kustomize
Section titled “Kustomize”Know
- A
kustomization.yamllists resources and applies patches, name prefixes, labels, and image overrides. Apply withkubectl apply -k.
Read
Demo: One base, two environments
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace ckad-kustomizekubectl config set-context --current --namespace=ckad-kustomize -
A base and two overlays, plus a generated ConfigMap.
Terminal window mkdir -p kz/base kz/dev kz/prodcat > kz/base/deploy.yaml <<'EOF'apiVersion: apps/v1kind: Deploymentmetadata:name: webspec:replicas: 1selector:matchLabels:app: webtemplate:metadata:labels:app: webspec:containers:- name: appimage: registry.k8s.io/e2e-test-images/agnhost:2.66.1args: ["netexec", "--http-port=8080"]envFrom:- configMapRef:name: web-configEOFcat > kz/base/kustomization.yaml <<'EOF'resources:- deploy.yamlconfigMapGenerator:- name: web-configliterals:- LOG_LEVEL=infoEOFcat > kz/dev/kustomization.yaml <<'EOF'resources:- ../basenamePrefix: dev-namespace: ckad-kustomizeEOFcat > kz/prod/kustomization.yaml <<'EOF'resources:- ../basenamePrefix: prod-namespace: ckad-kustomizereplicas:- name: webcount: 3configMapGenerator:- name: web-configbehavior: mergeliterals:- LOG_LEVEL=warnEOFdiff <(kubectl kustomize kz/dev) <(kubectl kustomize kz/prod) -
Apply both.
Terminal window kubectl apply -k kz/dev && kubectl apply -k kz/prodkubectl get deployments,configmaps
What you should see: The diff shows the prefix, the replica count, and a different ConfigMap name: the generator adds a hash of the content to the name, and the Deployment’s reference is rewritten to match. Change a value and the name changes, which forces a rollout.
Clean up:
rm -rf kzkubectl config set-context --current --namespace=defaultkubectl delete namespace ckad-kustomizePractise
- Create a base and a production overlay that changes replicas and the image tag.
Domain and competency names are from the CNCF CKAD curriculum (v1.37), cncf/curriculum, licensed CC BY 4.0. Summaries, demos, and exercises are original to this site.