Mock Exam 2 - Questions
Timed Exam
Set a timer for 2 hours before starting. Do not look at the solutions until the timer expires. Use only kubernetes.io documentation as a reference.
Exam Instructions
- This exam contains 17 questions totaling 100 points
- Passing score: 67 points
- Each question specifies the cluster context to switch to
- This exam focuses on areas where candidates commonly fail and includes tricky edge cases
- Flag difficult questions and return to them after completing easier ones
Question 1
| Weight | 6% |
| Difficulty | Medium |
| Domain | Cluster Setup |
| Cluster | kubectl config use-context cluster1 |
Scenario
The database namespace requires strict network segmentation. The security team has reported that pods in this namespace can still reach the Kubernetes API server and external internet endpoints.
Tasks
- Create a NetworkPolicy named
strict-db-isolationin thedatabasenamespace that applies to all pods with labeltier: databaseand:- Denies ALL egress traffic by default
- Allows egress only to pods with label
tier: databasewithin the same namespace on port3306(TCP) - Allows egress to pods with label
app: monitoringin themonitoringnamespace on port9090(TCP) - Allows DNS resolution (port
53TCP and UDP) to thekube-systemnamespace only
- Create a NetworkPolicy named
db-ingress-controlin thedatabasenamespace that:- Applies to pods with label
tier: database - Allows ingress only from pods with label
tier: applicationin thebackendnamespace on port3306 - Allows ingress from pods with label
app: monitoringin themonitoringnamespace on port9090
- Applies to pods with label
- Verify that the policies are correctly applied
Tricky Part
The DNS egress rule must target the kube-system namespace specifically, not allow DNS to any destination. This prevents data exfiltration via DNS tunneling.
Question 2
| Weight | 7% |
| Difficulty | Hard |
| Domain | Cluster Setup |
| Cluster | ssh cluster1-controlplane |
Scenario
The cluster's TLS certificates need to be inspected and potentially renewed. The security audit has flagged that some certificates may be close to expiry and the API server's certificate Subject Alternative Names (SANs) may be incomplete.
Tasks
- SSH into
cluster1-controlplane - Check the expiration dates of all Kubernetes certificates using
kubeadm certs check-expiration - Inspect the API server certificate and list all Subject Alternative Names (SANs):
openssl x509 -in /etc/kubernetes/pki/apiserver.crt -noout -text | grep -A1 "Subject Alternative Name" - If any certificate expires within 30 days, renew it using
kubeadm certs renew - Verify the etcd server certificate is using TLS by checking the etcd static pod manifest for the correct
--cert-fileand--key-fileflags - Verify the API server is configured to communicate with etcd using TLS by checking
--etcd-certfile,--etcd-keyfile, and--etcd-cafile
Question 3
| Weight | 5% |
| Difficulty | Medium |
| Domain | Cluster Setup |
| Cluster | ssh cluster2-controlplane |
Scenario
The Kubernetes dashboard has been deployed on cluster2 with insecure settings. You need to secure it.
Tasks
- The Kubernetes dashboard is deployed in the
kubernetes-dashboardnamespace. Verify it is running - Ensure the dashboard deployment does NOT use
--enable-skip-loginargument - Ensure the dashboard deployment does NOT use
--enable-insecure-loginargument - Ensure the dashboard Service is of type
ClusterIP(notNodePortorLoadBalancer) - Create a read-only ServiceAccount named
dashboard-viewerin thekubernetes-dashboardnamespace - Create a ClusterRole named
dashboard-view-onlythat allows onlyget,list,watchon all resources - Bind the ClusterRole to the ServiceAccount
Question 4
| Weight | 7% |
| Difficulty | Hard |
| Domain | Cluster Hardening |
| Cluster | kubectl config use-context cluster1 |
Scenario
A security audit has discovered several dangerous RBAC configurations across the cluster. You need to identify and fix them.
Tasks
- Find all ClusterRoleBindings that grant the
cluster-adminClusterRole and list them. Remove any bindings that are NOT forsystem:mastersgroup orsystem:adminuser or ServiceAccounts inkube-system - There is a ClusterRole named
debug-rolethat grantscreateonpods/exec. This is a dangerous permission. Modify the ClusterRole to removepods/execandpods/attachfrom its permissions - Find any Role or ClusterRole that grants
escalate,bind, orimpersonateverbs and save the output to/tmp/dangerous-rbac.txt - The ServiceAccount
ci-pipelinein thecicdnamespace has a long-lived token secret. Create a time-bound token for this ServiceAccount with a 1-hour expiration instead and save it to/tmp/ci-token.txt
Question 5
| Weight | 6% |
| Difficulty | Medium |
| Domain | Cluster Hardening |
| Cluster | ssh cluster1-controlplane |
Scenario
The API server on cluster1 needs additional hardening. Several flags are misconfigured or missing.
Tasks
- SSH into
cluster1-controlplaneand inspect the API server manifest - Ensure the following configurations are in place:
--anonymous-auth=false--insecure-port=0(or flag is absent, as it is deprecated)--kubelet-certificate-authorityis set to the correct CA file path--enable-admission-pluginsincludesNodeRestriction--authorization-modeincludesNode,RBAC(and does NOT includeAlwaysAllow)--request-timeoutis set to300s
- Verify the API server restarts successfully
- Verify you can still access the cluster with
kubectl get nodes
Question 6
| Weight | 7% |
| Difficulty | Hard |
| Domain | System Hardening |
| Cluster | ssh cluster1-node01 |
Scenario
A seccomp profile needs to be applied to an existing workload, and an AppArmor profile needs to be configured on a different pod. Both are running on cluster1-node01.
Tasks
- SSH into
cluster1-node01 - Create a seccomp profile at
/var/lib/kubelet/seccomp/profiles/strict-net.jsonthat:- Default action:
SCMP_ACT_ERRNO - Allows all syscalls from the
RuntimeDefaultset - Additionally blocks:
socket,connect,accept,bind,listen(deny networking syscalls)
- Default action:
- There is an existing AppArmor profile at
/etc/apparmor.d/k8s-deny-write. Load it if it is not already loaded - Switch context to
cluster1and update the podsecure-apiin therestrictednamespace to use thestrict-netseccomp profile - Update the pod
secure-writerin therestrictednamespace to use thek8s-deny-writeAppArmor profile - Verify both pods are running after the changes
Question 7
| Weight | 5% |
| Difficulty | Medium |
| Domain | System Hardening |
| Cluster | ssh cluster2-controlplane |
Scenario
The worker nodes in cluster2 have excessive access permissions. Users should not be able to SSH directly into worker nodes, and unnecessary kernel modules should be disabled.
Tasks
- SSH into
cluster2-controlplaneand verify that the nodecluster2-node01is accessible - On
cluster2-node01, configure the following:- Disable the
ip_forwardsysctl ONLY for containers (do not affect the host -- check if/etc/sysctl.d/has container-specific settings) - Blacklist the following kernel modules by creating
/etc/modprobe.d/k8s-hardening.conf:dccp,sctp,rds,tipc - Remove the
tcpdumpandstracepackages if installed
- Disable the
- Verify the kernel module blacklist is in effect
Question 8
| Weight | 5% |
| Difficulty | Medium |
| Domain | System Hardening |
| Cluster | ssh cluster1-controlplane |
Scenario
Unnecessary privileges have been granted at the OS level on the control plane node. You need to reduce the attack surface.
Tasks
- SSH into
cluster1-controlplane - Find all SUID binaries on the system and save the list to
/tmp/suid-binaries.txt - Find all world-writable directories and save the list to
/tmp/world-writable-dirs.txt - Remove the SUID bit from
/usr/bin/newgrpand/usr/bin/chfn(these are not needed for Kubernetes operations) - Verify the Kubernetes control plane components are still functioning after your changes
Question 9
| Weight | 7% |
| Difficulty | Hard |
| Domain | Minimize Microservice Vulnerabilities |
| Cluster | kubectl config use-context cluster1 |
Scenario
The e-commerce namespace runs multiple microservices. The security team requires that ALL pods in this namespace meet strict security requirements. Some existing pods violate these requirements.
Tasks
- Label the
e-commercenamespace to enforce thebaselinePod Security Standard (enforce mode) - Also set
restrictedinwarnandauditmodes for the namespace - Identify all pods in the
e-commercenamespace that would violate therestrictedstandard using a dry-run approach - The
checkout-servicedeployment ine-commerceis running withprivileged: true. Fix it by:- Removing the
privileged: trueflag - Adding
runAsNonRoot: truewithrunAsUser: 1000 - Dropping all capabilities and only adding
NET_BIND_SERVICE - Adding
readOnlyRootFilesystem: truewith emptyDir volumes for/tmpand/var/run - Setting
allowPrivilegeEscalation: false - Adding
seccompProfilewith typeRuntimeDefault
- Removing the
- Verify the deployment rolls out successfully
Question 10
| Weight | 6% |
| Difficulty | Medium |
| Domain | Minimize Microservice Vulnerabilities |
| Cluster | kubectl config use-context cluster2 |
Scenario
The application team needs to implement container sandboxing using RuntimeClass for high-security workloads in the sandbox namespace.
Tasks
- A container runtime
runsc(gVisor) is already configured on the nodes with handler namerunsc - Create a
RuntimeClassnamedgvisorthat uses therunschandler - Update the
payment-processordeployment in thesandboxnamespace to use thegvisorRuntimeClass - Verify the deployment is running with the correct RuntimeClass
- Create a second
RuntimeClassnamedkatawith handlerkata-runtimeand set scheduling to only run on nodes with labelruntime: kata - Save the RuntimeClass YAML to
/tmp/kata-runtimeclass.yaml
Question 11
| Weight | 7% |
| Difficulty | Hard |
| Domain | Minimize Microservice Vulnerabilities |
| Cluster | kubectl config use-context cluster1 |
Scenario
Secrets management needs to be overhauled. Several secrets in the banking namespace are improperly managed.
Tasks
- A secret named
api-keysin thebankingnamespace contains a keystripe-keywith valuesk_live_abc123. Verify this secret exists - The secret is currently of type
Opaque. Create a new secret namedapi-keys-v2of typeOpaquewith the same data, but ensure the podpayment-gatewayinbankingmounts this new secret as a volume at/etc/secretswithdefaultMode: 0400(read-only for owner) - Update the
payment-gatewaypod to:- Mount the secret volume with
readOnly: true - Set the container's security context to
runAsUser: 1000andrunAsGroup: 1000 - Remove any environment variables that reference the old
api-keyssecret
- Mount the secret volume with
- Delete the old
api-keyssecret after confirming the new configuration works - SSH into the control plane and verify that secrets are encrypted at rest (check if
--encryption-provider-configis set on the API server)
Question 12
| Weight | 6% |
| Difficulty | Medium |
| Domain | Minimize Microservice Vulnerabilities |
| Cluster | kubectl config use-context cluster2 |
Scenario
An OPA Gatekeeper policy is needed to enforce that all containers must use images from approved registries only.
Tasks
- Create a
ConstraintTemplatenamedk8sallowedreposthat:- Takes a parameter
reposwhich is a list of allowed repository prefixes - Checks that all container images (including init containers) start with one of the allowed prefixes
- Returns a violation message that includes the container name and the disallowed image
- Takes a parameter
- Create a
Constraintnamedallowed-reposusing the template that:- Applies to
Podresources in all namespaces exceptkube-systemandgatekeeper-system - Allows only these repositories:
docker.io/library/,gcr.io/company-project/,registry.internal.company.com/
- Applies to
- Verify by attempting to create a pod with an image from
quay.io/malicious/image-- it should be rejected - Verify a pod with image
docker.io/library/nginx:1.25is accepted
Question 13
| Weight | 7% |
| Difficulty | Hard |
| Domain | Supply Chain Security |
| Cluster | kubectl config use-context cluster1 |
Scenario
Multiple images in the production namespace need vulnerability assessment and remediation. You also need to set up continuous scanning.
Tasks
- Use
trivyto scan the following images and save CRITICAL vulnerabilities only:python:3.8-slim-> save to/tmp/python-scan.txtnode:16-alpine-> save to/tmp/node-scan.txtpostgres:13-> save to/tmp/postgres-scan.txt
- The
analytics-apideployment inproductionusespython:3.8-slim. Find the image with the fewest CRITICAL vulnerabilities from these options and update the deployment:python:3.11-slimpython:3.12-alpinecgr.dev/chainguard/python:latest
- Scan the chosen image and save the results to
/tmp/analytics-scan-fixed.txt - Use
kubesecto scan theanalytics-apideployment manifest and save the output to/tmp/kubesec-analytics.txt
Question 14
| Weight | 5% |
| Difficulty | Medium |
| Domain | Supply Chain Security |
| Cluster | kubectl config use-context cluster1 |
Scenario
Static analysis has identified security concerns in several pod specifications. You need to use kubesec to assess and improve them.
Tasks
- Export the pod specification of
data-pipelinein theetlnamespace to/tmp/data-pipeline.yaml - Run
kubesec scanon the exported file and save the result to/tmp/kubesec-data-pipeline.txt - Based on the
kubesecrecommendations, modify the pod specification to achieve a score of at least 8 by adding:runAsNonRoot: truereadOnlyRootFilesystem: truerunAsUser > 10000capabilities.drop: ["ALL"]- Resource limits (CPU and memory)
- A
ServiceAccountthat is notdefault
- Save the improved manifest to
/tmp/data-pipeline-hardened.yaml - Run
kubesec scanon the hardened manifest and save the result to/tmp/kubesec-data-pipeline-hardened.txtto confirm the improved score
Question 15
| Weight | 4% |
| Difficulty | Easy |
| Domain | Supply Chain Security |
| Cluster | kubectl config use-context cluster2 |
Scenario
An allowlist for container image registries needs to be enforced at the admission level using a simple validation webhook.
Tasks
- There is an existing
ValidatingWebhookConfigurationnamedimage-registry-validatorin the cluster. Inspect it - The webhook is currently configured to
Ignorefailures. Change thefailurePolicytoFailso that if the webhook is unavailable, pod creation is blocked - Ensure the webhook matches on
CREATEoperations forpodsonly - The webhook should NOT apply to the
kube-systemnamespace. Add anamespaceSelectorthat excludes namespaces with the labelkubernetes.io/metadata.name: kube-system - Verify the webhook configuration is valid by describing it
Question 16
| Weight | 5% |
| Difficulty | Hard |
| Domain | Monitoring, Logging & Runtime Security |
| Cluster | kubectl config use-context cluster1 |
Scenario
Suspicious activity has been detected in the cluster. You need to use audit logs and Falco to investigate and respond.
Tasks
- Audit logging is already enabled on
cluster1. SSH into the control plane and examine the audit logs at/var/log/kubernetes/audit/audit.log - Find all audit events where secrets were accessed (verb:
get,list, orwatch) in the last 100 lines of the log and save them to/tmp/secret-access-audit.txt - Identify any requests from non-system users (users not starting with
system:) that accessed secrets in thekube-systemnamespace and save them to/tmp/suspicious-secret-access.txt - Check Falco alerts for any container that has:
- Spawned a reverse shell
- Modified files under
/etc - Made unexpected network connections
- Save all suspicious Falco findings to
/tmp/falco-findings.txt - If any compromised pods are identified, delete them and create a NetworkPolicy in their namespace to prevent further data exfiltration (deny all egress except DNS)
Question 17
| Weight | 5% |
| Difficulty | Medium |
| Domain | Monitoring, Logging & Runtime Security |
| Cluster | kubectl config use-context cluster2 |
Scenario
Several containers in the cluster need to be made immutable. Additionally, you need to detect any containers that are not immutable.
Tasks
- The
web-frontenddeployment in thepublicnamespace has containers that can write to their root filesystem. Make the containers immutable by:- Setting
readOnlyRootFilesystem: true - Adding emptyDir volumes for
/tmp,/var/cache/nginx, and/var/run - Setting
allowPrivilegeEscalation: false
- Setting
- The
logging-agentDaemonSet in themonitoringnamespace needs to write to/var/log. Configure it with:readOnlyRootFilesystem: true- An emptyDir volume for
/tmp - A hostPath volume for
/var/logmounted asreadOnly: false(the agent needs to write logs)
- Write a script at
/tmp/find-mutable-containers.shthat finds all pods across all namespaces wherereadOnlyRootFilesystemis NOT set totrueand outputs the namespace, pod name, and container name - Run the script and save the output to
/tmp/mutable-containers.txt
Scoring Summary
| Question | Domain | Weight | Difficulty |
|---|---|---|---|
| Q1 | Cluster Setup | 6% | Medium |
| Q2 | Cluster Setup | 7% | Hard |
| Q3 | Cluster Setup | 5% | Medium |
| Q4 | Cluster Hardening | 7% | Hard |
| Q5 | Cluster Hardening | 6% | Medium |
| Q6 | System Hardening | 7% | Hard |
| Q7 | System Hardening | 5% | Medium |
| Q8 | System Hardening | 5% | Medium |
| Q9 | Microservice Vulnerabilities | 7% | Hard |
| Q10 | Microservice Vulnerabilities | 6% | Medium |
| Q11 | Microservice Vulnerabilities | 7% | Hard |
| Q12 | Microservice Vulnerabilities | 6% | Medium |
| Q13 | Supply Chain Security | 7% | Hard |
| Q14 | Supply Chain Security | 5% | Medium |
| Q15 | Supply Chain Security | 4% | Easy |
| Q16 | Monitoring & Runtime | 5% | Hard |
| Q17 | Monitoring & Runtime | 5% | Medium |
| Total | 100% |
After Completing the Exam
- Score yourself honestly
- Compare your results with Mock Exam 1 -- did you improve?
- If you scored above 80% on both exams, you are likely ready for the real CKS exam
- Schedule the exam within 1-2 weeks while the material is fresh