Skip to content

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

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

    Terminal window
    kubectl create namespace ckad-strategy
    kubectl config set-context --current --namespace=ckad-strategy
  2. Blue/green: two Deployments, one Service. Switch by changing the selector.

    Terminal window
    for c in blue green; do
    kubectl create deployment $c --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- /agnhost netexec --http-port=8080
    kubectl label deployment $c colour=$c
    kubectl patch deployment $c -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"colour\":\"$c\"}}}}}"
    done
    kubectl create service clusterip live --tcp=80:8080
    kubectl 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; echo
    kubectl 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
  3. 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:8080
    kubectl 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=8080
    kubectl create deployment canary --image=registry.k8s.io/e2e-test-images/agnhost:2.55 --replicas=1 -- /agnhost netexec --http-port=8080
    for d in stable canary; do kubectl patch deployment $d -p '{"spec":{"template":{"metadata":{"labels":{"track":"web"}}}}}'; done
    kubectl rollout status deployment/stable && kubectl rollout status deployment/canary
    kubectl 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:

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

Practise

  • Run a 4-to-1 canary with two Deployments sharing an app label, then promote it.

Understand Deployments and how to perform rolling updates

Section titled “Understand Deployments and how to perform rolling updates”

Know

  • maxSurge and maxUnavailable control the pace; readiness decides when a new pod counts. kubectl rollout undo goes back.

Read

Demo: Control the pace of a rollout

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

    Terminal window
    kubectl create namespace ckad-rolling
    kubectl config set-context --current --namespace=ckad-rolling
  2. A Deployment that adds one pod at a time and never drops below full capacity.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: paced
    spec:
    replicas: 4
    minReadySeconds: 5
    strategy:
    type: RollingUpdate
    rollingUpdate:
    maxSurge: 1
    maxUnavailable: 0
    selector:
    matchLabels:
    app: paced
    template:
    metadata:
    labels:
    app: paced
    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}
    EOF
    kubectl rollout status deployment/paced
  3. Update it, pause halfway, look, and resume.

    Terminal window
    kubectl set image deployment/paced app=registry.k8s.io/e2e-test-images/agnhost:2.55
    sleep 8; kubectl rollout pause deployment/paced
    kubectl get replicasets -l app=paced
    kubectl rollout resume deployment/paced
    kubectl rollout status deployment/paced
    kubectl 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:

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

On 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 -A shows releases.

Read

Demo: Install, upgrade, and roll back a public chart

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

    Terminal window
    kubectl create namespace ckad-helm
    kubectl config set-context --current --namespace=ckad-helm
  2. 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 -20
    helm install web oci://ghcr.io/stefanprodan/charts/podinfo --version 6.17.0 -n ckad-helm
    kubectl rollout status deployment/web-podinfo
    helm list
  3. 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=upgraded
    helm history web
    helm get values web
    helm rollback web 1
    helm history web
    kubectl 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:

Terminal window
helm uninstall web -n ckad-helm
kubectl config set-context --current --namespace=default
kubectl delete namespace ckad-helm

Practise

  • Install a chart into its own namespace with --create-namespace, upgrade one value, then roll back.

Know

  • A kustomization.yaml lists resources and applies patches, name prefixes, labels, and image overrides. Apply with kubectl apply -k.

Read

Demo: One base, two environments

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

    Terminal window
    kubectl create namespace ckad-kustomize
    kubectl config set-context --current --namespace=ckad-kustomize
  2. A base and two overlays, plus a generated ConfigMap.

    Terminal window
    mkdir -p kz/base kz/dev kz/prod
    cat > kz/base/deploy.yaml <<'EOF'
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: web
    spec:
    replicas: 1
    selector:
    matchLabels:
    app: web
    template:
    metadata:
    labels:
    app: web
    spec:
    containers:
    - name: app
    image: registry.k8s.io/e2e-test-images/agnhost:2.66.1
    args: ["netexec", "--http-port=8080"]
    envFrom:
    - configMapRef:
    name: web-config
    EOF
    cat > kz/base/kustomization.yaml <<'EOF'
    resources:
    - deploy.yaml
    configMapGenerator:
    - name: web-config
    literals:
    - LOG_LEVEL=info
    EOF
    cat > kz/dev/kustomization.yaml <<'EOF'
    resources:
    - ../base
    namePrefix: dev-
    namespace: ckad-kustomize
    EOF
    cat > kz/prod/kustomization.yaml <<'EOF'
    resources:
    - ../base
    namePrefix: prod-
    namespace: ckad-kustomize
    replicas:
    - name: web
    count: 3
    configMapGenerator:
    - name: web-config
    behavior: merge
    literals:
    - LOG_LEVEL=warn
    EOF
    diff <(kubectl kustomize kz/dev) <(kubectl kustomize kz/prod)
  3. Apply both.

    Terminal window
    kubectl apply -k kz/dev && kubectl apply -k kz/prod
    kubectl 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:

Terminal window
rm -rf kz
kubectl config set-context --current --namespace=default
kubectl delete namespace ckad-kustomize

Practise

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