Skip to content

KCNA: Container Orchestration

28% of the KCNA exam, 4 competencies. Back to the KCNA 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.

Know

  • Every pod gets its own IP, and pods can reach each other without NAT. A CNI plugin implements this.
  • Services give a stable virtual IP and DNS name in front of a changing set of pods.
  • Ingress and Gateway API route HTTP traffic from outside the cluster to Services.

Read

Demo: A Service in front of moving pods

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

    Terminal window
    kubectl create namespace kcna-net
    kubectl config set-context --current --namespace=kcna-net
  2. Run three replicas and put a Service in front.

    Terminal window
    kubectl create deployment web --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 --replicas=3 -- /agnhost netexec --http-port=8080
    kubectl expose deployment web --port=80 --target-port=8080
    kubectl rollout status deployment/web
  3. Call it by DNS name a few times from another pod.

    Terminal window
    kubectl run client --rm -i --restart=Never --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- \
    sh -c 'for i in 1 2 3 4 5 6; do wget -qO- -T 3 http://web/hostname; echo; done'
  4. See what the Service really points at.

    Terminal window
    kubectl get pods -l app=web -o wide
    kubectl get endpointslices -l kubernetes.io/service-name=web

What you should see: The replies rotate between pod names. The EndpointSlice lists the pod IPs behind the stable Service IP; delete a pod and the slice updates while the name web keeps working.

Clean up:

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

Practise

  • Expose a Deployment as a Service and resolve its name from another pod.

On this site

Know

  • The 4Cs: cloud, cluster, container, code. Each layer depends on the one around it.
  • RBAC grants permissions; Pod Security Standards restrict what pods may do; Secrets hold sensitive data but are only base64 unless encrypted at rest.

Read

Demo: Let the cluster refuse a risky pod

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

    Terminal window
    kubectl create namespace kcna-sec
    kubectl config set-context --current --namespace=kcna-sec
  2. Turn on the restricted Pod Security level for a namespace.

    Terminal window
    kubectl label namespace kcna-sec pod-security.kubernetes.io/enforce=restricted
  3. Try a pod that runs as root with default settings.

    Terminal window
    kubectl run rooty --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pause
  4. Now one that meets the standard.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: v1
    kind: Pod
    metadata:
    name: tidy
    spec:
    securityContext:
    runAsNonRoot: true
    runAsUser: 65534
    seccompProfile:
    type: RuntimeDefault
    containers:
    - name: app
    image: registry.k8s.io/e2e-test-images/agnhost:2.66.1
    args: ["pause"]
    securityContext:
    allowPrivilegeEscalation: false
    capabilities:
    drop: ["ALL"]
    EOF
    kubectl get pod tidy

What you should see: The first pod is rejected with violates PodSecurity "restricted:latest" and a list of every setting it is missing. The second is admitted. Nothing changed in the image; the pod spec is what the policy judges.

Clean up:

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

On this site

Know

  • Start from status and events: kubectl get, kubectl describe, then logs with kubectl logs --previous.
  • Know the common pod states: Pending, ContainerCreating, CrashLoopBackOff, ImagePullBackOff, OOMKilled.

Read

Demo: Three broken pods, three different signals

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

    Terminal window
    kubectl create namespace kcna-trouble
    kubectl config set-context --current --namespace=kcna-trouble
  2. Break a pod three ways.

    Terminal window
    kubectl run badimage --image=registry.k8s.io/e2e-test-images/does-not-exist:1.0
    kubectl run badcmd --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- sh -c 'echo starting; exit 1'
    kubectl apply -f - <<'EOF'
    apiVersion: v1
    kind: Pod
    metadata:
    name: hungry
    spec:
    containers:
    - name: app
    image: registry.k8s.io/e2e-test-images/busybox:1.37.0-2
    command: ["sh", "-c", "tail /dev/zero"]
    resources:
    limits:
    memory: 64Mi
    EOF
  3. Read the status column, then describe each one.

    Terminal window
    sleep 30; kubectl get pods
    kubectl describe pod badimage | sed -n '/Events:/,$p'
    kubectl logs badcmd --previous
    kubectl get pod hungry -o jsonpath='{.status.containerStatuses[0].lastState.terminated.reason}{"\n"}'

What you should see: badimage goes ErrImagePull then ImagePullBackOff, badcmd goes CrashLoopBackOff and its previous log says “starting”, and hungry is killed with reason OOMKilled. Each status points you to a different place to look.

Clean up:

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

Practise

  • Break a pod three ways (bad image, bad command, too little memory) and identify each from kubectl describe alone.

On this site

Know

  • Volumes live as long as the pod; PersistentVolumes outlive it. A PersistentVolumeClaim requests storage, a StorageClass provisions it dynamically.
  • CSI drivers connect Kubernetes to storage systems.

Read

Demo: Data that outlives the pod

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

    Terminal window
    kubectl create namespace kcna-storage
    kubectl config set-context --current --namespace=kcna-storage
  2. Claim storage from the default StorageClass.

    Terminal window
    kubectl get storageclass
    kubectl apply -f - <<'EOF'
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    name: data
    spec:
    accessModes: ["ReadWriteOnce"]
    resources:
    requests:
    storage: 1Gi
    EOF
    kubectl get pvc data
  3. Write a file from one pod, delete the pod, read it from another.

    Terminal window
    cat > writer.yaml <<'EOF'
    apiVersion: v1
    kind: Pod
    metadata:
    name: writer
    spec:
    containers:
    - name: app
    image: registry.k8s.io/e2e-test-images/busybox:1.37.0-2
    command: ["sh", "-c", "date >> /data/log; cat /data/log; sleep 3600"]
    volumeMounts:
    - name: data
    mountPath: /data
    volumes:
    - name: data
    persistentVolumeClaim:
    claimName: data
    EOF
    kubectl apply -f writer.yaml && kubectl wait --for=condition=Ready pod/writer --timeout=120s
    kubectl delete pod writer
    kubectl apply -f writer.yaml && kubectl wait --for=condition=Ready pod/writer --timeout=120s
    kubectl logs writer

What you should see: The claim stays Pending until the first pod uses it: kind’s standard class uses WaitForFirstConsumer. The second pod prints two dates, so the file survived the first pod being deleted.

Clean up:

Terminal window
rm -f writer.yaml
kubectl config set-context --current --namespace=default
kubectl delete namespace kcna-storage

On this site


Domain and competency names are from the CNCF KCNA curriculum (current curriculum (unversioned)), cncf/curriculum, licensed CC BY 4.0. Summaries, demos, and exercises are original to this site.