CKS
Free CKS practice questions
10 questions from our CKS practice tests, each with the correct answer and a written explanation. Read them with the answers shown, or switch to quiz mode and answer first.
Question 1 of 10, Cluster Setup
After applying a default-deny egress policy in the 'shop' namespace, the application pods can no longer resolve service names. The cluster DNS pods run in kube-system with the label k8s-app=kube-dns. Which additional egress rule restores name resolution while keeping all other egress blocked?
- AAllow egress to pods labelled k8s-app=kube-dns in the namespace labelled kubernetes.io/metadata.name=kube-system, on UDP and TCP port 53 Correct answer
- BAllow egress to any pod in any namespace on UDP port 53 only, using an empty namespaceSelector with no podSelector restriction
- CAllow egress to the kube-dns Service ClusterIP using an ipBlock rule, because NetworkPolicy evaluates traffic before kube-proxy translation
- DAllow ingress from pods labelled k8s-app=kube-dns into the 'shop' namespace on UDP port 53 so DNS replies can return to the pods
Answer and explanation: Combining namespaceSelector and podSelector in one peer narrows egress to the DNS pods, and DNS needs both UDP and TCP 53 (TCP for large responses). An empty namespaceSelector on port 53 permits any pod in the cluster to be reached on that port, which is broader than needed and omits TCP. NetworkPolicy is generally enforced after Service translation, so an ipBlock for the ClusterIP is unreliable. Replies to allowed connections are permitted automatically, so an ingress rule is not the fix.
Question 2 of 10, Cluster Setup
Workloads in a cloud-hosted cluster must not be able to query the instance metadata endpoint at 169.254.169.254, but they still need general internet egress. Which NetworkPolicy egress rule meets this requirement?
- AA podSelector matching the metadata agent pods combined with policyTypes Ingress only
- BA namespaceSelector that excludes kube-system together with an ipBlock of 0.0.0.0/0
- CAn ipBlock with cidr 169.254.169.254/32 placed in a separate deny-type egress rule
- DAn ipBlock with cidr 0.0.0.0/0 and an except entry of 169.254.169.254/32 Correct answer
Answer and explanation: Standard NetworkPolicy is allow-only, so the way to block one address while permitting the rest is an ipBlock of 0.0.0.0/0 with an except entry for the metadata IP. There is no deny rule type in the core NetworkPolicy API. Excluding kube-system by namespace does nothing for an external link-local address. Metadata is served by the cloud host, not pods, and an Ingress-only policy does not restrict egress at all.
Question 3 of 10, Cluster Hardening
A security review finds that the kube-apiserver accepts unauthenticated requests as system:anonymous, and a ClusterRoleBinding grants that user read access to pods. Which change fixes the root cause on a kubeadm cluster with the LEAST impact on health probes?
- ASet --insecure-port=0 so unauthenticated clients cannot reach the HTTP endpoint
- BRemove NodeRestriction from --enable-admission-plugins so anonymous requests are rejected before RBAC authorization runs
- CDelete the ClusterRoleBinding granting access to system:anonymous, keeping default health and discovery access Correct answer
- DSet --authorization-mode=AlwaysAllow on the API server so that all requests must first pass authentication before reaching RBAC
Answer and explanation: Anonymous requests only obtain what RBAC grants them, so deleting the binding that gives system:anonymous pod access removes the exposure while leaving default health endpoints usable; --anonymous-auth=false is a stronger option but can break unauthenticated probes. AlwaysAllow disables authorization entirely and is the opposite of hardening. NodeRestriction is an admission plugin for kubelet writes and has no role in rejecting anonymous reads. The insecure port has been removed from modern API servers and is unrelated to anonymous authentication on the secure port.
Question 4 of 10, System Hardening
On a cloud provider, pods could reach the instance metadata service and obtain the node's IAM credentials. Besides network policy, which host-level change limits what a stolen credential can do?
- AStore the node IAM access keys in a Kubernetes Secret so the metadata service can be disabled entirely
- BGive the node's IAM role only the permissions the kubelet and CNI need, and use workload identity for pod access Correct answer
- CGive every pod its own copy of the node IAM role through the metadata service so activity can be traced to individual workloads
- DGrant the node IAM role administrator access so failures caused by missing permissions cannot occur
Answer and explanation: Least privilege for the node role limits the damage of a leaked credential, and workload identity gives pods narrowly scoped credentials. Sharing the node role with pods spreads broad access. Administrator access maximises blast radius. Static access keys in a Secret are long-lived and easier to leak than metadata-issued temporary credentials.
Question 5 of 10, Minimize Microservice Vulnerabilities
In OPA Gatekeeper, a team wrote Rego logic that requires an 'owner' label. What must they create so this logic is enforced on Namespaces?
- AA ConfigMap with the Rego in the gatekeeper-system namespace labelled as a policy for Namespaces
- BA ValidatingAdmissionPolicy containing the Rego, and a binding that selects the Namespace resource
- CA ConstraintTemplate containing the Rego, and a Constraint of the generated kind matching Namespaces Correct answer
- DA MutatingWebhookConfiguration whose rules call an OPA server that has the Rego file mounted into its pod
Answer and explanation: Gatekeeper defines a new constraint kind from a ConstraintTemplate holding the Rego, and a Constraint of that kind sets the scope and parameters. ValidatingAdmissionPolicy uses CEL, not Rego. Gatekeeper does not load policies from labelled ConfigMaps (that was the older kube-mgmt pattern). Gatekeeper manages its own webhook; a hand-made mutating webhook is not how constraints are enforced.
Question 6 of 10, Minimize Microservice Vulnerabilities
A multi-tenant cluster runs untrusted customer code. The team wants stronger kernel isolation than standard runc containers for those workloads only, without changing other pods. Which approach fits?
- AAdd the SYS_ADMIN capability drop to the untrusted pods and label their namespace with the privileged Pod Security level
- BEnable the restricted Pod Security Standard cluster-wide so every container runs with a separate guest kernel provided by the runtime
- CInstall gVisor on the nodes, create a RuntimeClass for its runsc handler, and set runtimeClassName on untrusted pods Correct answer
- DSet hostUsers: false on every pod so each container gets its own kernel via user namespaces
Answer and explanation: RuntimeClass lets selected pods run on a sandbox runtime like gVisor (runsc) or Kata Containers, which provide an extra kernel boundary, while other pods keep runc. Pod Security Standards constrain pod settings but do not change the kernel boundary. User namespaces remap UIDs but containers still share the host kernel, and applying it cluster-wide changes other pods. Dropping one capability and labelling the namespace privileged weakens rather than strengthens isolation.
Question 7 of 10, Supply Chain Security
Developers want feedback on risky settings in their Kubernetes manifests, such as privileged containers or missing resource limits, before the YAML is merged. Which tool performs this static analysis?
- Akube-bench, which compares node configuration with the CIS Kubernetes Benchmark
- Betcdctl, which reads stored objects and reports on their security configuration
- CFalco, which matches syscalls from running containers against detection rules
- Dkubesec, which scores manifests and lists critical and advisory security findings Correct answer
Answer and explanation: kubesec analyses resource definitions and gives a risk score with findings like privileged or missing limits. kube-bench checks node and control plane configuration, not app manifests. Falco detects behaviour of running workloads. etcdctl is a datastore client and does not evaluate security posture.
Question 8 of 10, Supply Chain Security
Gatekeeper is installed. Pods should only use images from 'registry.corp/'. Which Gatekeeper library approach is typical?
- ACreate a Gatekeeper Config with a sync entry for Pods that lists the allowed registry prefix
- BInstall the K8sPSPPrivilegedContainer template and set its parameter to the corporate registry name prefix
- CInstall the K8sAllowedRepos ConstraintTemplate and create a Constraint with repos: ['registry.corp/'] Correct answer
- DCreate a ConstraintTemplate with an empty Rego body and rely on the Constraint's match selector
Answer and explanation: The Gatekeeper policy library includes K8sAllowedRepos, whose Constraint takes a list of allowed repository prefixes. The privileged container template checks privileged settings. The Config sync section replicates data into OPA's cache. An empty Rego body never produces violations.
Question 9 of 10, Monitoring, Logging and Runtime Security
Audit logs are dominated by events from the system:nodes group and from watch requests on endpoints. How can the policy reduce noise without losing user activity?
- AAdd early rules with level None for the system:nodes group and for watch on endpoints, before broader rules Correct answer
- BChange the global level to Metadata for all requests so node events are logged with smaller payloads
- CSet omitStages to ResponseComplete for every rule so that only the RequestReceived event is logged
- DAdd a final rule with level None for all users, since earlier rules have already logged the important events
Answer and explanation: Because the first matching rule applies, early None rules for known noisy sources drop them while later rules still log user actions. A final None rule only affects requests that matched nothing earlier, so it does not drop the node noise. Metadata still logs every node event. Omitting ResponseComplete loses status information and does not reduce event count.
Question 10 of 10, Monitoring, Logging and Runtime Security
A pod has been deleted, but the container logs are needed for an investigation. Where might they still be found on the node shortly after deletion, if not yet garbage collected?
- AIn the ReplicaSet's events listing the deleted pod
- BIn the pod's object in etcd, under the status field
- CUnder /var/log/pods and /var/log/containers on the node Correct answer
- DIn the kube-apiserver's audit log at Metadata level
Answer and explanation: The kubelet writes container logs under /var/log/pods, with symlinks in /var/log/containers, and they may persist briefly after deletion; shipping logs centrally avoids depending on this. etcd stores pod status, not logs. Audit logs record API requests. Events do not include container output.