The CKS exam has no multiple choice. You get 2 hours and 15 to 20 tasks to complete on live clusters, and you need 67% to pass. Many tasks mean editing the API server or a node directly, where one typo takes the control plane down. So practise them on a cluster before you open the solution.

These come from the CKPrep CKS pack's topic drills. In the pack, each one is set up on real local clusters and VMs, timed and graded check by check. Names like cks-alt-control-plane refer to the practice clusters it builds.

On exam day you'd have roughly 6 to 8 minutes per task.

Question 1 · Cluster Setup 15% Default-deny NetworkPolicies with exact exceptions

Namespace orchard runs three workloads, each behind a Service of the same name on port 80: web, api and db. Right now every Pod in the cluster can reach all of them.

Using NetworkPolicies in namespace orchard:

  1. Create a policy named deny-all that selects every Pod and denies all ingress and all egress.
  2. Add whatever further policies are needed so that Pods labelled app=web can reach api on TCP port 80 by Service name.

Nothing else may be opened: web must not reach db, and Pods from other namespaces must not reach api.

Show the solution

Search the docs for Network Policies and copy the default-deny example.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: {name: deny-all, namespace: orchard}
spec:
  podSelector: {}
  policyTypes: [Ingress, Egress]

Then allow three flows: egress web → api:80, ingress api ← web:80, and egress web → kube-dns:53 (UDP and TCP).

kubectl -n orchard run t --rm -it --image=curlimages/curl:8.11.1 -l app=web --restart=Never -- curl -m 5 http://api/

Pitfall: with default-deny egress, forgetting DNS makes the Service name fail even though the port rule is right. Policies are additive, so an allow rule next to deny-all is enough.

Question 2 · Cluster Hardening 15% Cut a ServiceAccount down to least privilege

ServiceAccount report-bot in namespace ledgerops is bound to Role report-bot, which currently grants everything in the namespace.

The bot only ever reads Pods and ConfigMaps. Change Role report-bot so that it allows exactly get, list and watch on pods and configmaps. Keep the existing RoleBinding.

Show the solution
kubectl -n ledgerops create role report-bot --verb=get,list,watch --resource=pods,configmaps \
  --dry-run=client -o yaml | kubectl apply -f -
SA=system:serviceaccount:ledgerops:report-bot
kubectl auth can-i --list --as $SA -n ledgerops

Pitfall: a Role's roleRef can't change, but its rules can, so the binding stays. Wildcards also cover resources added later, including subresources such as pods/exec.

Question 3 · Cluster Hardening 15% Remove anonymous access to the API server

Someone granted unauthenticated clients access to cluster data through a ClusterRoleBinding.

  1. Find the ClusterRoleBinding that gives the group system:unauthenticated access to Secrets. Write its name to ~/ckprep-answers/anon-binding.txt.
  2. Delete that binding. Don't delete the ClusterRole it references, and don't touch the built-in system:public-info-viewer binding: anonymous clients must still be able to read /version.
Show the solution
kubectl get clusterrolebindings -o json | jq -r '.items[] | select(any(.subjects[]?; .name=="system:unauthenticated" or .name=="system:anonymous")) | "\(.metadata.name) -> \(.roleRef.name)"'
kubectl describe clusterrole dashboard-data
echo dashboard-preview > ~/ckprep-answers/anon-binding.txt
kubectl delete clusterrolebinding dashboard-preview
kubectl auth can-i get secrets -A --as=system:anonymous --as-group=system:unauthenticated   # no

Pitfall: system:public-info-viewer also targets system:unauthenticated, so filter by what each role grants before deleting anything.

Question 4 · System Hardening 10% Run a Pod under a seccomp profile

Every worker node of cluster main already has a seccomp profile at /var/lib/kubelet/seccomp/profiles/deny-chmod.json.

Pod notes in namespace sandbox-a must run under that profile. Recreate it with the profile applied through its securityContext, keeping its name, namespace, image and command.

Inside the container chmod must then fail with "Operation not permitted", while ordinary commands keep working.

Show the solution
kubectl -n sandbox-a get pod notes -o yaml > notes.yaml
vim notes.yaml
spec:
  securityContext:
    seccompProfile:
      type: Localhost
      localhostProfile: profiles/deny-chmod.json   # relative to /var/lib/kubelet/seccomp
kubectl replace --force -f notes.yaml
kubectl -n sandbox-a exec notes -- sh -c 'touch /tmp/t; chmod 600 /tmp/t'   # Operation not permitted

Pitfall: localhostProfile is relative to the kubelet's seccomp root. An absolute path, or a node without the file, leaves the Pod in CreateContainerError.

Question 5 · Minimize Microservice Vulnerabilities 20% Make a namespace comply with the restricted Pod Security Standard

Namespace payments must comply with the restricted Pod Security Standard.

  1. Update Deployment gateway so that its Pods satisfy the restricted profile and run as UID 1000. Keep the image and command.
  2. Label the namespace so that the restricted level is enforced at version latest.

After this, the Deployment must be fully ready, and creating a privileged Pod in payments must be rejected.

Show the solution
kubectl -n payments edit deploy gateway
spec:
  template:
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
        seccompProfile: {type: RuntimeDefault}
      containers:
      - name: gateway
        securityContext:
          allowPrivilegeEscalation: false
          capabilities: {drop: ["ALL"]}
kubectl -n payments rollout status deploy gateway
kubectl label --overwrite ns payments pod-security.kubernetes.io/enforce=restricted pod-security.kubernetes.io/enforce-version=latest

Tip: kubectl label --dry-run=server --overwrite ns payments pod-security.kubernetes.io/enforce=restricted lists existing Pods that would violate the level. Pitfall: enforcement only blocks new Pods, so a namespace can be labelled while old non-compliant Pods still run.

Question 6 · Minimize Microservice Vulnerabilities 20% Encrypt Secrets at rest in etcd

On cluster alt, Secrets are stored unencrypted in etcd.

  1. Create an EncryptionConfiguration at /etc/kubernetes/enc/enc.yaml on cks-alt-control-plane that encrypts secrets with the aescbc provider (key name key1, a random 32-byte key), and can still read existing plain data.
  2. Configure the API server to use it.
  3. Make sure the existing Secret db-cred in namespace vaulted is now stored encrypted.

The API server must be healthy and db-cred must still return its original value.

Show the solution
./ckprep ssh cks-alt-control-plane
mkdir -p /etc/kubernetes/enc
head -c 32 /dev/urandom | base64      # the key
vim /etc/kubernetes/enc/enc.yaml
apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfiguration
resources:
- resources: [secrets]
  providers:
  - aescbc:
      keys:
      - {name: key1, secret: <base64 key>}
  - identity: {}          # reads data written before encryption

In kube-apiserver.yaml, add the flag and a hostPath mount:

- --encryption-provider-config=/etc/kubernetes/enc/enc.yaml
# volumeMounts:
- {name: enc, mountPath: /etc/kubernetes/enc, readOnly: true}
# volumes:
- {name: enc, hostPath: {path: /etc/kubernetes/enc, type: DirectoryOrCreate}}
kubectl -n vaulted get secret db-cred -o json | kubectl replace -f -   # rewrites it encrypted
ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  --cert=/etc/kubernetes/pki/apiserver-etcd-client.crt --key=/etc/kubernetes/pki/apiserver-etcd-client.key \
  get /registry/secrets/vaulted/db-cred | hexdump -C | head     # k8s:enc:aescbc:v1:key1

Pitfall: the first provider writes. With identity first nothing is encrypted. Existing Secrets stay plain until rewritten.

Question 7 · Monitoring, Logging and Runtime Security 20% Enable API server audit logging

Enable audit logging on the API server of cluster alt (cks-alt-control-plane).

  1. Create the policy /etc/kubernetes/audit/policy.yaml with these rules:
    • secrets, in any namespace: level Metadata.
    • configmaps in namespace audit-demo: level RequestResponse.
    • Everything else: not logged.
  2. Configure the API server to use it, writing to /var/log/kubernetes/audit/audit.log, keeping logs for 7 days and at most 2 rotated files.

The API server must be healthy and the log must really receive events.

Show the solution
./ckprep ssh cks-alt-control-plane
mkdir -p /etc/kubernetes/audit /var/log/kubernetes/audit
vim /etc/kubernetes/audit/policy.yaml
apiVersion: audit.k8s.io/v1
kind: Policy
rules:
- level: Metadata
  resources: [{group: "", resources: [secrets]}]
- level: RequestResponse
  namespaces: [audit-demo]
  resources: [{group: "", resources: [configmaps]}]
- level: None

In kube-apiserver.yaml:

- --audit-policy-file=/etc/kubernetes/audit/policy.yaml
- --audit-log-path=/var/log/kubernetes/audit/audit.log
- --audit-log-maxage=7
- --audit-log-maxbackup=2
# volumeMounts:
- {name: audit-policy, mountPath: /etc/kubernetes/audit, readOnly: true}
- {name: audit-log, mountPath: /var/log/kubernetes/audit}
# volumes:
- {name: audit-policy, hostPath: {path: /etc/kubernetes/audit, type: DirectoryOrCreate}}
- {name: audit-log, hostPath: {path: /var/log/kubernetes/audit, type: DirectoryOrCreate}}

Pitfall: rules match first to last, so level: None goes last. Without the two mounts the API server can't read the policy and won't start.

Question 8 · Monitoring, Logging and Runtime Security 20% Make containers immutable at runtime

Deployment static-site in namespace immutable-web runs nginx. Make its containers immutable at runtime:

  1. Set the root filesystem to read-only.
  2. Give nginx only the writable paths it needs, using emptyDir volumes: /var/cache/nginx, /var/run and /tmp.

The Deployment must stay ready and keep serving the welcome page. Writing to /usr/share/nginx/html must fail.

Show the solution
    spec:
      containers:
      - name: static-site
        image: nginx:1.27-alpine
        securityContext:
          readOnlyRootFilesystem: true
        volumeMounts:
        - {name: cache, mountPath: /var/cache/nginx}
        - {name: run, mountPath: /var/run}
        - {name: tmp, mountPath: /tmp}
      volumes:
      - {name: cache, emptyDir: {}}
      - {name: run, emptyDir: {}}
      - {name: tmp, emptyDir: {}}

Why: a read-only root stops an intruder from dropping tools or altering content, and a restart returns the container to a clean state. Pitfall: turn it on and read the logs: CrashLoopBackOff with "Read-only file system" tells you which path still needs a volume.

Want the full exam?

The CKS pack has 65 tasks like these across every domain, including 2 full two-hour mock exams, 6 drills and 2 VM labs where AppArmor, gVisor and Falco run for real, all on your own machine.

Get the CKS pack · $19.99

New to the exam? Read the CKS exam guide first: format, domains, allowed docs and a study plan.