CKS: Cluster Setup
15% of the CKS exam, 5 competencies. Back to the CKS overview.
Each competency lists what to know and the official documentation to read, then a demo you can run. Demos run on the demo lab, a throwaway kind cluster on your own machine; set it up once before you start.
Use Network security policies to restrict cluster level access
Section titled “Use Network security policies to restrict cluster level access”Know
- Default-deny per namespace, explicit allows, and blocking egress to the cloud metadata address (169.254.169.254) unless needed.
Read
Demo: Default deny, DNS allowed, metadata blocked
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace cks-netpolkubectl config set-context --current --namespace=cks-netpol -
Lock the namespace down in both directions, allow DNS, and allow web traffic out except the metadata address.
Terminal window kubectl apply -f - <<'EOF'apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata:name: default-deny-allspec:podSelector: {}policyTypes: ["Ingress", "Egress"]---apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata:name: allow-dnsspec:podSelector: {}policyTypes: ["Egress"]egress:- to:- namespaceSelector:matchLabels:kubernetes.io/metadata.name: kube-systempodSelector:matchLabels:k8s-app: kube-dnsports:- {protocol: UDP, port: 53}- {protocol: TCP, port: 53}---apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata:name: allow-https-outspec:podSelector:matchLabels:egress: internetpolicyTypes: ["Egress"]egress:- to:- ipBlock:cidr: 0.0.0.0/0except: ["169.254.169.254/32", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]ports:- {protocol: TCP, port: 443}EOF -
Test from a pod with and without the label.
Terminal window kubectl run locked --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- sleep 3600kubectl run outbound --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 --labels=egress=internet -- sleep 3600kubectl wait --for=condition=Ready pod/locked pod/outbound --timeout=60sfor p in locked outbound; do echo "$p:"; kubectl exec $p -- sh -c 'nslookup registry.k8s.io >/dev/null && echo dns ok; nc -zv -w 3 registry.k8s.io 443'; donekubectl exec outbound -- sh -c 'nc -zv -w 3 kubernetes.default.svc.cluster.local 443' || true
What you should see: Both pods resolve names. Only outbound opens port 443 on the internet, and even it can’t reach the API server’s service IP, because private ranges are excluded. Policies are additive allows; the deny comes from being selected by any policy at all.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace cks-netpolPractise
- Write a policy that denies all egress except DNS and one internal Service.
On this site
Use CIS benchmark to review the security configuration of Kubernetes components (etcd, kubelet, kubedns, kubeapi)
Section titled “Use CIS benchmark to review the security configuration of Kubernetes components (etcd, kubelet, kubedns, kubeapi)”Know
- Run kube-bench, read the failed checks, and fix them in the static pod manifests or kubelet configuration.
Read
Demo: Run kube-bench on the control plane
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace cks-ciskubectl config set-context --current --namespace=cks-cis -
Use the job manifest from the pinned kube-bench release, with its image pinned too.
Terminal window curl -sLO https://raw.githubusercontent.com/aquasecurity/kube-bench/v0.16.0/job-master.yamlsed -i 's|aquasec/kube-bench:latest|aquasec/kube-bench:v0.16.0|' job-master.yamlgrep image: job-master.yamlkubectl apply -f job-master.yamlkubectl wait --for=condition=complete job/kube-bench-master --timeout=180s -
Read the summary and the failures.
Terminal window kubectl logs job/kube-bench-master | grep -E '^\[FAIL\]' | head -15kubectl logs job/kube-bench-master | grep -A6 '== Summary' -
Each failure comes with a remediation. Read one and find the setting it refers to.
Terminal window kubectl logs job/kube-bench-master | grep -A4 -E '^1\.2\.[0-9]+ ' | head -20docker exec kind-control-plane grep -E -- '--(profiling|audit-log-path)' /etc/kubernetes/manifests/kube-apiserver.yaml || echo "flag not set"
What you should see: A list of PASS, FAIL, and WARN results by benchmark section, with a summary at the end. On a default kind cluster expect failures such as no audit logging and profiling left on. Each remediation names the flag and the manifest to edit. Not every failure applies to your environment; record the ones you accept and why.
Note: The kube-bench image comes from Docker Hub, not registry.k8s.io.
Clean up:
rm -f job-master.yamlkubectl config set-context --current --namespace=defaultkubectl delete namespace cks-cisPractise
- Run kube-bench on a control plane node and fix two failing checks.
Properly set up Ingress objects with TLS
Section titled “Properly set up Ingress objects with TLS”Know
- Reference a
kubernetes.io/tlsSecret in the Ingresstlssection; the host must match the certificate.
Read
Demo: Serve an Ingress over HTTPS with your own certificate
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace cks-tlskubectl config set-context --current --namespace=cks-tls -
Create a certificate for the host and store it as a TLS Secret.
Terminal window openssl req -x509 -newkey rsa:2048 -nodes -days 1 -keyout tls.key -out tls.crt -subj '/CN=secure.example' -addext 'subjectAltName=DNS:secure.example'kubectl create secret tls secure-tls --cert=tls.crt --key=tls.key -
An Ingress that uses it.
Terminal window kubectl create deployment web --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- /agnhost netexec --http-port=8080kubectl expose deployment web --port=80 --target-port=8080kubectl apply -f - <<'EOF'apiVersion: networking.k8s.io/v1kind: Ingressmetadata:name: securespec:ingressClassName: cloud-provider-kindtls:- hosts: ["secure.example"]secretName: secure-tlsrules:- host: secure.examplehttp:paths:- path: /pathType: Prefixbackend:service:name: webport:number: 80EOFkubectl get ingress secure -w # wait for an ADDRESS, then Ctrl-C -
Connect with the right name and check what certificate is served.
Terminal window IP=$(kubectl get ingress secure -o jsonpath='{.status.loadBalancer.ingress[0].ip}')docker cp tls.crt kind-control-plane:/tmp/secure.crtdocker exec kind-control-plane curl -s --cacert /tmp/secure.crt --resolve secure.example:443:$IP https://secure.example/hostname; echodocker exec kind-control-plane curl -sv --cacert /tmp/secure.crt --resolve secure.example:443:$IP https://secure.example/ 2>&1 | grep -E 'subject:|SSL connection'
What you should see: curl verifies the certificate against your CA file and returns a pod name. The verbose output shows subject: CN=secure.example. If the host in tls.hosts doesn’t match the certificate’s names, clients fail verification. In production, cert-manager issues and renews these Secrets for you.
Clean up:
rm -f tls.key tls.crtkubectl config set-context --current --namespace=defaultkubectl delete namespace cks-tlsPractise
- Create a self-signed certificate, store it as a TLS Secret, and serve an Ingress over HTTPS.
Protect node metadata and endpoints
Section titled “Protect node metadata and endpoints”Know
- Block pod access to cloud metadata endpoints and to the kubelet API with NetworkPolicies and kubelet authentication settings.
Read
Demo: Lock down the kubelet and keep pods away from it
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace cks-nodeprotectkubectl config set-context --current --namespace=cks-nodeprotect -
Confirm the kubelet’s API needs authentication and its read-only port is off.
Terminal window kubectl get --raw /api/v1/nodes/kind-worker/proxy/configz | jq '.kubeletconfig | {anonymous: .authentication.anonymous.enabled, webhookAuthn: .authentication.webhook.enabled, authz: .authorization.mode, readOnlyPort}'docker exec kind-control-plane curl -s -o /dev/null -w '%{http_code}\n' http://kind-worker:10255/pods || true -
Block pods from reaching node addresses at all.
Terminal window kubectl get nodes -o jsonpath='{range .items[*]}{.status.addresses[0].address}{"\n"}{end}'kubectl apply -f - <<'EOF'apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata:name: no-node-accessspec:podSelector: {}policyTypes: ["Egress"]egress:- to:- ipBlock:cidr: 0.0.0.0/0except: ["172.18.0.0/16", "169.254.169.254/32"]EOFkubectl run probe --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- sleep 3600 && kubectl wait --for=condition=Ready pod/probe --timeout=60skubectl exec probe -- sh -c 'nc -zv -w 2 kind-worker 10250' || echo blocked
What you should see: anonymous is false, authorization is Webhook, and the read-only port 10255 doesn’t answer. After the policy the probe can’t reach the kubelet port. The node addresses on kind usually sit in 172.18.0.0/16 (the Docker kind network); check the printed IPs and adjust the CIDR to match your nodes.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace cks-nodeprotectVerify platform binaries before deploying
Section titled “Verify platform binaries before deploying”Know
- Compare binary checksums or signatures against the published release artifacts before installing.
Read
Demo: Check kubectl by checksum and by signature
-
Download a release binary with its checksum and signature files, and check the checksum.
Terminal window URL=https://dl.k8s.io/release/v1.37.2/bin/linux/amd64for f in kubectl kubectl.sha256 kubectl.sig kubectl.cert; do curl -sSfL --retry 3 "$URL/$f" -o "$f"; doneecho "$(cat kubectl.sha256) kubectl" | sha256sum --check -
Verify the signature with cosign (v3.1.4), using the identity the Kubernetes release process signs with.
Terminal window cosign verify-blob kubectl \--signature kubectl.sig \--certificate kubectl.cert \--certificate-identity krel-staging@k8s-releng-prod.iam.gserviceaccount.com \--certificate-oidc-issuer https://accounts.google.com -
Tamper with the binary and check again.
Terminal window echo x >> kubectlecho "$(cat kubectl.sha256) kubectl" | sha256sum --check
What you should see: The checksum line says kubectl: OK and cosign prints Verified OK (cosign v3 also warns that --signature and --certificate are deprecated in favour of bundles; the commands are the ones in the official Kubernetes docs). After tampering the checksum fails. A checksum from the same server only proves the download wasn’t corrupted; the signature proves who built it.
Clean up:
rm -f kubectl kubectl.sha256 kubectl.sig kubectl.certPractise
- Verify a downloaded
kubectlagainst its published SHA-256 checksum.
Domain and competency names are from the CNCF CKS curriculum (v1.37), cncf/curriculum, licensed CC BY 4.0. Summaries, demos, and exercises are original to this site.