Kubernetes Security (CKS): interview questions
The question you are most likely to get for each topic, a model answer, and what else comes up.
How would you harden a new Kubernetes cluster before production? Mid
Turn on audit logging with a Policy that keeps Secrets at Metadata, encrypt Secrets at rest (a kms provider in production), run kube-bench and fix the control plane FAILs such as --profiling, verify the binaries you install, block pods from the metadata endpoint, enforce Pod Security restricted plus AppArmor or seccomp for sensitive workloads, sandbox untrusted ones with gVisor, scan and sign images and enforce the signature at admission, and watch the runtime with Falco - defence in depth, each layer assuming the one before it can fail.
Also asked: What does the Kubernetes audit log record, and what does it not see? · How do you prove Secrets are encrypted in etcd? · What is the difference between scanning and signing an image?
What are the layers of Kubernetes security? Mid
Workloads (Pod Security, securityContext, RBAC), the API server (authentication, RBAC, audit logging), etcd (encryption at rest), nodes and components (CIS benchmark checks, verified binaries, AppArmor, seccomp, the metadata endpoint), images (scanning, signing, admission control) and runtime (detection with Falco). It is defence in depth: each layer assumes the one before it failed, so one gap does not hand over the cluster.
Also asked: What does defence in depth mean for a cluster? · Which CKS domain carries the most weight? · How is the CKS exam run?
Learn it: 23.1 The CKS map: what a cluster attacker goes after
How do you find out what a compromised ServiceAccount did in the cluster? Mid
From the API server audit log. With auditing on - an audit Policy, --audit-policy-file and --audit-log-path, and hostPath mounts for both - every request is an event with the user, verb, resource, namespace, name and response code, logged at Metadata or above. You grep the log for that ServiceAccount's username and list what it read or changed, then revoke its access.
Also asked: What are the audit levels and which should Secrets get? · What does omitStages do? · Why would an audit flag have no effect?
Are Kubernetes Secrets encrypted? Mid
Not by default - they are base64-encoded and stored in etcd as they are. With an EncryptionConfiguration passed to the apiserver through --encryption-provider-config plus a mount, the first provider (aescbc, or kms in production) encrypts every new write; existing Secrets need rewriting with kubectl replace, and you verify with etcdctl get, where the value starts with k8s:enc:.
Also asked: Why does the provider order matter? · How do you rotate the encryption key? · Why prefer a kms provider in production?
Learn it: 23.4 Encryption at rest: Secrets in etcd
How do you make sure a Kubernetes binary you download is genuine? Mid
Download it and its .sha256 from dl.k8s.io, build the hash-and-name line with echo "$(cat kubelet.sha256) kubelet" and pipe it to sha256sum --check: kubelet: OK means it matches the release build. FAILED means delete it and fetch it again from the release, and find out where the bad copy came from.
Also asked: Why is a checksum from the same mirror worthless? · What exit code does sha256sum --check give on a mismatch? · Which binaries matter most on a node?
Learn it: 23.7 Verify a Kubernetes binary before you trust it
How do you stop pods from stealing the node's cloud credentials? Mid
Block the instance metadata endpoint at http://169.254.169.254 with an egress NetworkPolicy: podSelector {}, policyTypes Egress, one rule allowing 0.0.0.0/0 except 169.254.169.254/32. Then test from inside a pod that the request times out. Longer term, give pods their own cloud identity (IRSA, Pod Identity, workload identity) so the node role can stay minimal.
Also asked: What does the metadata endpoint hand out? · Why use except instead of denying all egress? · How do per-pod cloud identities change the risk?
Learn it: 23.9 Keep pods away from the node's cloud credentials
How would you firewall the nodes of a kubeadm cluster? Mid
Start from the Kubernetes "Ports and Protocols" page: 6443 on the control plane, 10250 on every node from the control plane, 2379-2380 only between apiservers and etcd, NodePorts if used, plus the CNI (179/tcp for Calico BGP) and SSH from the admin network. With ufw: sudo ufw default deny incoming, one allow from ... to any port ... proto tcp per need, SSH before sudo ufw enable, then prove it with a reboot - established connections hide gaps. NodePorts bypass ufw, so filter them in front of the nodes.
Also asked: Why does ufw not filter NodePort traffic? · What is the difference between a host firewall and a NetworkPolicy? · Why should you test a node firewall with a reboot?
Learn it: 23.11 A firewall on the nodes: what a kubeadm node must accept, and what ufw cannot see
How do you check a cluster against a security baseline? Mid
Run kube-bench on each node type: it runs the CIS Kubernetes Benchmark and prints PASS or FAIL for automated checks and WARN for manual ones, each with a remediation - for example 1.2.15 says set --profiling=false in the apiserver manifest. Fix the manifests, let the kubelet restart the static pods, then re-run with --check to prove the FAILs now pass.
Also asked: What is the difference between FAIL and WARN in kube-bench? · Why is profiling a security concern? · How would you run the benchmark continuously?
Learn it: 23.13 kube-bench: the CIS benchmark as a checklist
How would you stop a container from writing to its filesystem even as root? Mid
Load an AppArmor profile with a deny /** w, rule on the nodes (apparmor_parser -q, check with aa-status) and run the pod with securityContext.appArmorProfile type Localhost naming it; the kernel refuses the writes with Permission denied. A read-only root filesystem is the simpler first step; AppArmor also covers mounted paths and other actions.
Also asked: What happens when a Localhost profile is missing on the node? · How do you distribute profiles to all nodes? · How is AppArmor different from seccomp?
Learn it: 23.15 AppArmor: confine what a container may touch
What is seccomp and how do you use it in Kubernetes? Mid
A kernel filter on system calls. securityContext.seccompProfile type RuntimeDefault uses the runtime's filter; type Localhost with localhostProfile reads your JSON profile from /var/lib/kubelet/seccomp on the node, where SCMP_ACT_ERRNO rules make blocked calls fail with Operation not permitted. The file must exist on every node the pod can run on, or the container is not created.
Also asked: What happens when a Localhost seccomp profile is missing? · Why start with RuntimeDefault? · How is seccomp different from AppArmor?
How would you run untrusted code in a Kubernetes cluster more safely? Mid
In a sandboxed runtime: create a RuntimeClass with handler runsc for gVisor (or a Kata handler), make sure the nodes have that runtime configured in containerd and pin the pods to them with the RuntimeClass's scheduling.nodeSelector, then set runtimeClassName on the pod and prove it from inside - uname -r shows gVisor's 4.4.0 instead of the node kernel.
Also asked: What is the difference between gVisor and Kata Containers? · What happens if the node lacks the runtime? · Which workloads would you not sandbox, and why?
Learn it: 23.19 Sandboxed containers: RuntimeClass and gVisor
How do you make sure only trusted images run in a cluster? Mid
Scan images in CI with trivy image and fail on HIGH and CRITICAL, keep an SBOM with syft, sign the images that pass with cosign (by digest), and enforce the signature at admission with a Kyverno ImageValidatingPolicy in Deny mode, so an unsigned or foreign image is rejected however it was deployed.
Also asked: What is the difference between scanning and signing? · Why start a new policy in Audit mode? · What would you do with an SBOM during a new CVE?
Learn it: 23.21 Supply chain: scan, sign, and enforce at admission
How would you stop insecure Kubernetes manifests from being merged? Mid
Run static analysis in the pipeline on every manifest and rendered chart: kube-linter lint fails the job on any finding such as a privileged container or an image without a tag, and kubesec scan scores each object and fails on a score of 0 or less, with the critical findings listed first. Fix the manifest, rescan, and keep admission policies in the cluster as the second gate for anything that bypasses CI.
Also asked: What is the difference between kubesec and KubeLinter? · Why is a positive kubesec score not enough? · Where in a pipeline would you run these scanners?
Learn it: 23.23 Static analysis: kubesec and kube-linter before you apply
How would you enforce that every Deployment has a team label without installing anything? Mid
With a ValidatingAdmissionPolicy on apps deployments (CREATE, UPDATE) whose CEL is has(object.metadata.labels) && has(object.metadata.labels.team) && object.metadata.labels.team != '', plus a ValidatingAdmissionPolicyBinding with validationActions [Deny] and a namespaceSelector for the namespaces it should cover. Then prove it by creating a Deployment without the label and watching it fail.
Also asked: Why does a missing field matter in CEL? · What do Warn and Audit actions do? · When is a webhook-based policy engine still the better choice?
Learn it: 23.25 ValidatingAdmissionPolicy: admission rules in CEL, built in
How do you add a new admission policy without breaking production? Mid
Roll it out in Audit first: the policy admits everything and the PolicyReports list each resource that would fail. Fix the violators, for example pin the image tags, check that kubectl get polr shows no FAIL left, then switch validationActions to Deny and prove it with a request that must be refused. Mutation can set the safe default so fewer requests fail at all.
Also asked: How do Kyverno and ValidatingAdmissionPolicy differ? · What does a MutatingPolicy change, and when does it run? · How would you migrate a Kyverno ClusterPolicy to the new API?
Learn it: 23.27 Kyverno 1.19: validate, mutate, and read the PolicyReports
A Falco alert says a shell was spawned in a production container. What do you do? Mid
Read the alert for the pod, namespace and command, keep the evidence (the alert, the pod YAML, the node), contain the pod with a deny-all NetworkPolicy or by scaling it to zero, remove it, then search the API audit log for the exec request to learn which identity opened the shell, fix that access and rotate the credentials it could reach. Falco tells you what happened; the audit log tells you who.
Also asked: What can Falco see that the audit log cannot? · How do you contain a compromised pod without losing evidence? · How would you write a custom Falco rule?
Learn it: 23.31 Runtime detection with Falco
How do you prepare for a hands-on exam like the CKS? Mid
By doing the tasks, not reading about them: practise each kind of task until the steps are automatic, under a time limit, on fresh names every time. On the exam, go to the task's host first, use ssh for node work, verify every task before moving on, and flag anything that takes longer than about 10 minutes.
Also asked: Which CKS domain is the hardest for you, and why? · How do you verify a security control actually works? · How do you decide what to skip under time pressure?
Learn it: 23.34 The CKS exam: how the tasks run, and the drills
Practise these answers with flashcards and labs Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.