·5 min read

Passing the CKA exam

Tips and personal experience

Passing the CKA was a real milestone for me. It wasn't easy, but it pushed me to understand Kubernetes a level deeper than "it works in our cluster". Below are tasks I got in the exam, how I solved them, and a few things I'd tell anyone sitting it next.

One warning first: the CKA curriculum was updated in February 2025 (Helm, Kustomize, Gateway API and CRDs/operators were added). The tasks here are still core material, but check the current curriculum before you build your study plan around my list.

Tasks I got in the exam

Everything is hands-on. You get a terminal, a set of clusters, and a list of tasks. These are the ones I remember.

1. Add an init container to a pod

Task: Add an init container to the pod hungry-bear that creates an empty file /workdir/calm.txt. If the file isn't detected, the pod should exit.

Init containers run to completion before the main containers start, so they're the natural place for setup like this. The trick is the shared emptyDir: both containers mount it, the init container writes the file, the main container checks for it. See the init containers docs.

apiVersion: v1
kind: Pod
metadata:
  name: hungry-bear
spec:
  volumes:
  - name: workdir
    emptyDir: {}
  containers:
  - name: checker
    image: alpine
    command: ["/bin/sh", "-c", "if [ -f /workdir/calm.txt ]; then sleep 10000; else exit 1; fi"]
    volumeMounts:
    - name: workdir
      mountPath: /workdir
  initContainers:
  - name: create
    image: alpine
    command: ["/bin/sh", "-c", "touch /workdir/calm.txt"]
    volumeMounts:
    - name: workdir
      mountPath: /workdir

You can't add an init container to a running pod. Dump it with kubectl get pod hungry-bear -o yaml > hungry-bear.yaml, edit, then delete and recreate:

kubectl replace --force -f hungry-bear.yaml

2. Upgrade the control plane

Task: Upgrade the control plane and node components on the master node from 1.30.0 to 1.30.1. Don't upgrade etcd.

The order matters, and it's easy to get wrong under pressure: upgrade kubeadm first, run kubeadm upgrade apply, then drain, then upgrade kubelet and kubectl, restart kubelet, uncordon. Follow the kubeadm upgrade docs, they're allowed in the exam.

# on the control plane node
sudo apt-mark unhold kubeadm
sudo apt-get update && sudo apt-get install -y kubeadm=1.30.1-1.1
sudo apt-mark hold kubeadm
sudo kubeadm upgrade plan
sudo kubeadm upgrade apply v1.30.1 --etcd-upgrade=false
 
kubectl drain k8s-master --ignore-daemonsets --delete-emptydir-data
 
sudo apt-mark unhold kubelet kubectl
sudo apt-get install -y kubelet=1.30.1-1.1 kubectl=1.30.1-1.1
sudo apt-mark hold kubelet kubectl
sudo systemctl daemon-reload
sudo systemctl restart kubelet
 
kubectl uncordon k8s-master

Two gotchas:

  • The package version suffix depends on the repo. The new pkgs.k8s.io repos use 1.30.1-1.1, the old (frozen) apt.kubernetes.io used 1.30.1-00. Don't guess, run apt-cache madison kubeadm and copy the exact string.
  • --delete-local-data was removed from kubectl drain. Use --delete-emptydir-data.

3. Create a secret and use it in pods

Task: Create a secret named super-secret with the password bob and use it in two pods: one as a file mount, one as an environment variable. See Secrets.

kubectl create secret generic super-secret --from-literal=password=bob

As a file mount (you get /secrets/password):

apiVersion: v1
kind: Pod
metadata:
  name: pod-secrets-via-file
spec:
  containers:
  - name: redis
    image: redis
    volumeMounts:
    - name: secret-volume
      mountPath: /secrets
  volumes:
  - name: secret-volume
    secret:
      secretName: super-secret

As an environment variable:

apiVersion: v1
kind: Pod
metadata:
  name: pod-secrets-via-env
spec:
  containers:
  - name: redis
    image: redis
    env:
    - name: CONFIDENTIAL
      valueFrom:
        secretKeyRef:
          name: super-secret
          key: password

Check both before moving on: kubectl exec pod-secrets-via-file -- cat /secrets/password and kubectl exec pod-secrets-via-env -- env | grep CONFIDENTIAL.

4. A non-persistent Redis pod

Task: Create a pod named non-persistent-redis using the redis image, with a volume named cache-control that is not persistent.

"Not persistent" means emptyDir. It lives as long as the pod and is deleted with it. See emptyDir.

apiVersion: v1
kind: Pod
metadata:
  name: non-persistent-redis
spec:
  containers:
  - name: redis
    image: redis
    volumeMounts:
    - name: cache-control
      mountPath: /data/redis
  volumes:
  - name: cache-control
    emptyDir: {}
kubectl apply -f non-persistent-redis.yaml

5. Expose a deployment and look up its DNS records

Task: Create a deployment named nginx-random, expose it via a service, and make sure the service and the pods resolve via DNS. Save the lookup results to files.

See Services and DNS for Services and Pods.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-random
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
kubectl expose deploy nginx-random --name=nginx-random --port=80 --target-port=80
kubectl run nslookup --image=busybox --rm -it --restart=Never -- nslookup nginx-random > /opt/KUNW00601/service.dns

For a pod, the record is the pod IP with dashes instead of dots, e.g. 10-244-1-5.default.pod.cluster.local. Get the IP with kubectl get pod -o wide and look that name up the same way.

6. Take an etcd snapshot

Task: Create a snapshot of the etcd instance at https://127.0.0.1:2379 and save it to /srv/data/etcd-snapshot.db.

The certificate paths are given in the task. Copy them exactly. See Backing up an etcd cluster.

ETCDCTL_API=3 etcdctl --endpoints="https://127.0.0.1:2379" \
  --cacert=/opt/KUCM00302/ca.crt \
  --cert=/opt/KUCM00302/etcd-client.crt \
  --key=/opt/KUCM00302/etcd-client.key \
  snapshot save /srv/data/etcd-snapshot.db

7. A busybox pod running sleep

Task: Create a busybox pod that runs sleep 3600.

kubectl run busybox --image=busybox --restart=Never -- /bin/sh -c "sleep 3600"

Free points. Don't overthink it.

8. ClusterRole bound to a ServiceAccount

Task: Create a ClusterRole named deployment-clusterrole that allows creating Deployments, StatefulSets and DaemonSets. Bind it to a ServiceAccount named cicd-token in the app-team1 namespace. See RBAC.

The task says "in the namespace", so it's a RoleBinding (scoped to app-team1) pointing at a ClusterRole, not a ClusterRoleBinding.

kubectl create clusterrole deployment-clusterrole --verb=create --resource=deployments,statefulsets,daemonsets
kubectl create serviceaccount cicd-token --namespace=app-team1
kubectl create rolebinding deployment-clusterrole-binding --clusterrole=deployment-clusterrole --serviceaccount=app-team1:cicd-token --namespace=app-team1

Verify it before you move on:

kubectl auth can-i create deployments --as=system:serviceaccount:app-team1:cicd-token -n app-team1

What helped me

  • Practice on real scenarios. The exam is all practical. Deploying apps, storage, troubleshooting, you need to be fast at all of it, not just know it.
  • Get fast with YAML. Don't write manifests from scratch. Generate them and edit:
    alias k=kubectl
    export do="--dry-run=client -o yaml"
    k run nginx --image=nginx $do > pod.yaml
    k create deploy web --image=nginx $do > deploy.yaml
    When you forget a field, kubectl explain pod.spec.initContainers is faster than searching the docs.
  • Switch context on every task. Each task tells you which cluster to use and gives you the kubectl config use-context command. Run it every time. Solving the right task on the wrong cluster gets you zero.
  • Manage your time. Do the tasks you're confident about first, flag the hard ones, come back later. The weight of each task is shown, so a 4% task isn't worth 15 minutes.
  • Stay calm. It's intense. Calm and methodical works better than fast and sloppy.

Resources


A note on how this was written: I used AI to help with phrasing and structure. The tone, the opinions, the war stories, the code, and everything else here are mine.