KCSA: Kubernetes Cluster Component Security
22% of the KCSA exam, 11 competencies. Back to the KCSA 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.
API Server
Section titled “API Server”Know
- The only component that talks to etcd. Protect it with TLS, authentication, authorization, admission, and audit logging; never expose it anonymously.
Read
Demo: What the API server answers to strangers
-
Call the API server with no credentials from the control plane node.
Terminal window docker exec kind-control-plane curl -sk https://127.0.0.1:6443/version | head -5docker exec kind-control-plane curl -sk https://127.0.0.1:6443/api/v1/namespaces/kube-system/secrets -
See which bindings allow anonymous requests at all.
Terminal window kubectl get clusterrolebinding system:public-info-viewer -o jsonpath='{.subjects}{"\n"}'kubectl describe clusterrole system:public-info-viewer
What you should see: /version answers anonymously; listing secrets returns 403 User "system:anonymous" cannot list resource "secrets". Anonymous access is on, but RBAC only gives system:unauthenticated the health and version endpoints. If someone binds a broad role to system:anonymous or system:unauthenticated, the cluster is open to anyone who can reach port 6443.
On this site
Controller Manager
Section titled “Controller Manager”Know
- Runs with powerful credentials; secure its kubeconfig and use per-controller service account credentials.
Read
Demo: Local-only ports and per-controller identities
-
Read the flags that matter for security.
Terminal window docker exec kind-control-plane grep -E -- '--(bind-address|use-service-account-credentials|service-account-private-key-file|root-ca-file)' /etc/kubernetes/manifests/kube-controller-manager.yaml -
Health is public, metrics are not.
Terminal window docker exec kind-control-plane curl -sk https://127.0.0.1:10257/healthz; echodocker exec kind-control-plane curl -sk -o /dev/null -w '%{http_code}\n' https://127.0.0.1:10257/metrics -
Each controller runs as its own service account.
Terminal window kubectl get serviceaccounts -n kube-system | grep -E 'controller|deployment|replicaset' | head
What you should see: The controller manager binds to 127.0.0.1 only. /healthz returns ok while /metrics returns 403 to an anonymous caller. With --use-service-account-credentials=true, a compromised controller has only its own controller’s permissions.
Scheduler
Section titled “Scheduler”Know
- A compromised scheduler can place pods anywhere; restrict access to its configuration and bind it to localhost.
Read
Demo: Same pattern as the controller manager
-
Read its flags and probe its port.
Terminal window docker exec kind-control-plane grep -E -- '--(bind-address|kubeconfig|authentication-kubeconfig|authorization-kubeconfig)' /etc/kubernetes/manifests/kube-scheduler.yamldocker exec kind-control-plane curl -sk https://127.0.0.1:10259/livez; echodocker exec kind-control-plane curl -sk -o /dev/null -w '%{http_code}\n' https://127.0.0.1:10259/metrics -
What the scheduler is allowed to do.
Terminal window kubectl auth can-i --list --as=system:kube-scheduler | head -20
What you should see: Bound to 127.0.0.1, public health endpoint, protected metrics. Its own identity, system:kube-scheduler, can bind pods to nodes but can’t read Secrets. Someone who can change the scheduler can still decide where every pod runs, so its manifest and kubeconfig need the same protection as the API server’s.
Kubelet
Section titled “Kubelet”Know
- Disable anonymous access, use webhook authorization, and restrict its API. The Node authorizer and NodeRestriction admission limit what a kubelet can change.
Read
Demo: Call the kubelet API with and without credentials
-
Anonymous calls to the kubelet are refused.
Terminal window docker exec kind-control-plane curl -sk -o /dev/null -w '%{http_code}\n' https://kind-worker:10250/pods -
Read the kubelet’s live configuration through the API server.
Terminal window kubectl get --raw /api/v1/nodes/kind-worker/proxy/configz | jq '.kubeletconfig | {authentication, authorization, readOnlyPort}' -
Who may proxy to kubelets: that permission is as strong as exec.
Terminal window kubectl auth can-i get nodes/proxy --as=system:serviceaccount:default:defaultkubectl get clusterroles -o json | jq -r '.items[] | select(any(.rules[]?; (.resources // []) | index("nodes/proxy"))) | .metadata.name'
What you should see: The kubelet returns 401 to an anonymous caller: anonymous.enabled is false and authorization is Webhook, so the API server decides. readOnlyPort is 0 (off). Any role that grants nodes/proxy lets its holder talk to kubelets directly; audit those roles.
Container Runtime
Section titled “Container Runtime”Know
- The runtime enforces namespaces, cgroups, seccomp, and AppArmor. Keep it patched; sandboxed runtimes add a stronger boundary.
Read
Demo: The runtime socket and runtime classes
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-runtimekubectl config set-context --current --namespace=kcsa-runtime -
Whoever can reach this socket controls every container on the node.
Terminal window docker exec kind-worker ls -l /run/containerd/containerd.sockdocker exec kind-worker crictl info | jq '.config.containerd.runtimes // .config | keys' 2>/dev/null | head -
Ask for a runtime the node doesn’t have.
Terminal window kubectl apply -f - <<'EOF'apiVersion: node.k8s.io/v1kind: RuntimeClassmetadata:name: gvisorhandler: runscEOFkubectl run sandboxed --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 --overrides='{"spec":{"runtimeClassName":"gvisor"}}' -- sleep 3600sleep 15; kubectl describe pod sandboxed | sed -n '/Events:/,$p'
What you should see: The socket is owned by root with mode srw-rw----. Mounting it into a pod (a hostPath to /run/containerd/containerd.sock) hands that pod the node. The gvisor pod fails to start with an event saying no runtime is configured for runsc: a RuntimeClass only selects a handler, and each node must have that handler installed.
Clean up:
kubectl delete runtimeclass gvisorkubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-runtimeKubeProxy
Section titled “KubeProxy”Know
- Programs node networking for Services; its metrics and health endpoints should not be exposed outside the node.
Read
Demo: What kube-proxy writes on every node
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-kubeproxykubectl config set-context --current --namespace=kcsa-kubeproxy -
Find its mode and its identity.
Terminal window kubectl get configmap kube-proxy -n kube-system -o jsonpath='{.data.config\.conf}' | grep -E '^mode|metricsBindAddress|healthzBindAddress'kubectl get daemonset kube-proxy -n kube-system -o jsonpath='{.spec.template.spec.serviceAccountName}{"\n"}' -
Create a Service and find its rules on a node.
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=8080IP=$(kubectl get service web -o jsonpath='{.spec.clusterIP}')docker exec kind-worker sh -c "iptables-save -t nat | grep $IP"
What you should see: kind runs kube-proxy in iptables mode by default. The Service’s cluster IP appears in the node’s NAT table, pointing at a chain that load-balances to pod IPs. kube-proxy runs privileged with host networking; anyone who can change its ConfigMap or DaemonSet can redirect Service traffic on every node.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-kubeproxyKnow
- The unit of isolation: security context, service account, volumes, and host access settings decide its blast radius.
Read
Demo: Privileged versus unprivileged, from inside
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-podkubectl config set-context --current --namespace=kcsa-pod -
Compare what two pods can see.
Terminal window kubectl run plain --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- sleep 3600kubectl run priv --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 --overrides='{"spec":{"containers":[{"name":"priv","image":"registry.k8s.io/e2e-test-images/busybox:1.37.0-2","command":["sleep","3600"],"securityContext":{"privileged":true}}]}}'kubectl wait --for=condition=Ready pod/plain pod/priv --timeout=60sfor p in plain priv; do echo "$p: $(kubectl exec $p -- sh -c 'ls /dev | wc -l') devices, $(kubectl exec $p -- grep CapEff /proc/1/status)"; done -
A privileged pod can mount the node’s disk.
Terminal window kubectl exec priv -- sh -c 'ls /dev | grep -E "^(sd|vd|nvme|xvd)" | head -3'
What you should see: The plain pod sees a handful of devices and a limited capability set; the privileged one sees the node’s devices with every capability (000001ffffffffff). Privileged is root on the node in all but name, which is why baseline and restricted both forbid it.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-podKnow
- Holds all cluster state, including Secrets. Use TLS between members and clients, restrict network access, and encrypt Secrets at rest.
Read
Demo: Client certificates and plain-text Secrets
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-etcdkubectl config set-context --current --namespace=kcsa-etcd -
etcd refuses clients without a certificate signed by its CA.
Terminal window docker exec kind-control-plane curl -s --cacert /etc/kubernetes/pki/etcd/ca.crt https://127.0.0.1:2379/version; echo "exit code $?"docker exec kind-control-plane curl -s --cacert /etc/kubernetes/pki/etcd/ca.crt \--cert /etc/kubernetes/pki/etcd/healthcheck-client.crt --key /etc/kubernetes/pki/etcd/healthcheck-client.key \https://127.0.0.1:2379/version; echo -
Read a Secret straight out of etcd.
Terminal window kubectl create secret generic plain --from-literal=password=VisibleInEtcdkubectl -n kube-system exec etcd-kind-control-plane -- etcdctl --endpoints=https://127.0.0.1:2379 \--cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key \get /registry/secrets/kcsa-etcd/plain | grep -a -o VisibleInEtcd
What you should see: Without a client certificate the TLS handshake fails. With one, /version answers. The Secret value comes back as plain text from etcd, because kind (like kubeadm) doesn’t enable encryption at rest by default. Anyone with etcd access or a copy of its disk or backups has every Secret; the CKS secrets demo turns encryption on.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-etcdOn this site
Container Networking
Section titled “Container Networking”Know
- Flat pod networking means any pod can reach any pod until NetworkPolicies say otherwise.
Read
Demo: Pods can reach more than you think
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-cnikubectl config set-context --current --namespace=kcsa-cni -
From an ordinary pod, reach the kubelet port on a node and a pod in another namespace.
Terminal window kubectl run probe --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pausekubectl create namespace kcsa-otherkubectl create deployment target -n kcsa-other --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- /agnhost netexec --http-port=8080kubectl expose deployment target -n kcsa-other --port=8080kubectl rollout status deployment/target -n kcsa-otherNODEIP=$(kubectl get node kind-worker -o jsonpath='{.status.addresses[0].address}')kubectl exec probe -- sh -c "nc -zv -w 2 $NODEIP 10250; wget -qO- -T 3 http://target.kcsa-other:8080/hostname; echo" -
Default-deny egress for the namespace, except DNS.
Terminal window kubectl apply -f - <<'EOF'apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata:name: egress-dns-onlyspec: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}EOFkubectl exec probe -- sh -c "nc -zv -w 2 $NODEIP 10250; wget -qO- -T 3 http://target.kcsa-other:8080/hostname; echo"
What you should see: Before the policy, the pod opens the kubelet port and reads from a pod in another namespace: the default network is flat and open. After it, both fail while DNS still resolves. Default-deny plus explicit allows is the baseline every namespace should start from.
Clean up:
kubectl delete namespace kcsa-otherkubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-cniOn this site
Client Security
Section titled “Client Security”Know
- Kubeconfig files are credentials. Prefer short-lived tokens from an identity provider over long-lived client certificates.
Read
Demo: What is inside your kubeconfig
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-clientkubectl config set-context --current --namespace=kcsa-client -
Decode the client certificate kubectl uses.
Terminal window kubectl config view --minify --raw -o jsonpath='{.users[0].user.client-certificate-data}' | base64 -d \| openssl x509 -noout -subject -issuer -enddate -
Check what that identity can do, then make a scoped kubeconfig instead.
Terminal window kubectl auth whoamikubectl create serviceaccount ci-readerkubectl create rolebinding ci-reader --clusterrole=view --serviceaccount=kcsa-client:ci-readerkubectl create token ci-reader --duration=1h | cut -c1-40; echo '...'
What you should see: The subject is CN=kubernetes-admin, O=kubeadm:cluster-admins with a one-year expiry, and the private key sits next to it in the file. Anyone who copies that file is cluster-admin until the certificate expires; client certificates can’t be revoked. Short-lived, scoped tokens (like the one-hour ci-reader token) are the safer thing to hand out.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-clientStorage
Section titled “Storage”Know
- Encrypt volumes at rest, restrict hostPath, and treat PV reclaim policy as a data-disposal decision.
Read
Demo: A hostPath mount reaches the node
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-storagekubectl config set-context --current --namespace=kcsa-storage -
Mount the node’s root filesystem read-only and read the cluster CA key.
Terminal window kubectl label namespace kcsa-storage pod-security.kubernetes.io/warn=baselinekubectl apply -f - <<'EOF'apiVersion: v1kind: Podmetadata:name: hostpathspec:nodeName: kind-control-planetolerations:- operator: Existscontainers:- name: appimage: registry.k8s.io/e2e-test-images/busybox:1.37.0-2command: ["sleep", "3600"]volumeMounts:- name: hostmountPath: /hostreadOnly: truevolumes:- name: hosthostPath:path: /EOFkubectl wait --for=condition=Ready pod/hostpath --timeout=60skubectl exec hostpath -- ls -l /host/etc/kubernetes/pki/ca.key
What you should see: apply prints a warning that the pod would violate the baseline policy (hostPath volumes), but warn mode still lets it in, and the pod can read the cluster CA private key. Read-only doesn’t help: reading is the damage. This is why baseline forbids hostPath; use enforce, not only warn.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-storageDomain and competency names are from the CNCF KCSA curriculum (current curriculum (unversioned)), cncf/curriculum, licensed CC BY 4.0. Summaries, demos, and exercises are original to this site.