KCSA: Kubernetes Security Fundamentals
22% of the KCSA exam, 7 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.
Pod Security Standards
Section titled “Pod Security Standards”Know
- Three profiles: privileged, baseline, restricted.
Read
Demo: Check existing pods against a stricter level before you enforce it
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-psskubectl config set-context --current --namespace=kcsa-pss -
Some pods that meet
baselinebut notrestricted.Terminal window kubectl create deployment web --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 --replicas=2 -- /agnhost netexec --http-port=8080kubectl rollout status deployment/web -
Dry-run the label change: the API server evaluates every existing pod.
Terminal window kubectl label --dry-run=server --overwrite namespace kcsa-pss pod-security.kubernetes.io/enforce=baselinekubectl label --dry-run=server --overwrite namespace kcsa-pss pod-security.kubernetes.io/enforce=restricted
What you should see: baseline passes silently. restricted prints warnings naming each existing pod and what it is missing (allowPrivilegeEscalation != false, unrestricted capabilities, runAsNonRoot != true, seccompProfile). The dry run changes nothing, so it is the safe first step before tightening a namespace in production.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-pssPod Security Admissions
Section titled “Pod Security Admissions”Know
- Namespace labels set
enforce,audit, andwarnmodes per profile.
Read
Demo: Enforce, warn, and audit at different levels
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-psakubectl config set-context --current --namespace=kcsa-psa -
Enforce
baseline, warn and audit atrestricted, and pin the enforce version.Terminal window kubectl label namespace kcsa-psa \pod-security.kubernetes.io/enforce=baseline \pod-security.kubernetes.io/enforce-version=v1.37 \pod-security.kubernetes.io/warn=restricted \pod-security.kubernetes.io/audit=restrictedkubectl get namespace kcsa-psa --show-labels -
A pod that passes
baselinebut notrestricted, and one that fails both.Terminal window kubectl run ok-ish --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pausekubectl run bad --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 --overrides='{"spec":{"hostNetwork":true}}' -- pausekubectl get pods
What you should see: ok-ish is created with a warning listing what restricted would require. bad is rejected outright for host namespaces. Running warn and audit one level above enforce shows you what would break before you raise enforcement. Pinning enforce-version keeps the rules from changing under you when the cluster is upgraded.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-psaOn this site
Authentication
Section titled “Authentication”Know
- X.509 client certificates, bearer tokens, OIDC, and webhook authentication. Kubernetes has no user objects; identities come from outside.
Read
Demo: Issue a user certificate through the API
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-authnkubectl config set-context --current --namespace=kcsa-authn -
Generate a key and a certificate signing request for user
janein groupdevs.Terminal window openssl genrsa -out jane.key 2048openssl req -new -key jane.key -out jane.csr -subj "/CN=jane/O=devs"kubectl apply -f - <<EOFapiVersion: certificates.k8s.io/v1kind: CertificateSigningRequestmetadata:name: janespec:request: $(base64 < jane.csr | tr -d '\n')signerName: kubernetes.io/kube-apiserver-clientexpirationSeconds: 3600usages: ["client auth"]EOFkubectl certificate approve janekubectl get csr jane -o jsonpath='{.status.certificate}' | base64 -d > jane.crtopenssl x509 -in jane.crt -noout -subject -enddate -
Log in as jane. Authenticated, but not yet authorized.
Terminal window kubectl config set-credentials jane --client-certificate=jane.crt --client-key=jane.key --embed-certs=truekubectl config set-context jane --cluster=kind-kind --user=jane --namespace=kcsa-authnkubectl --context=jane auth whoamikubectl --context=jane get pods
What you should see: auth whoami reports jane in group devs: the API server trusts any certificate its CA signed. get pods is forbidden until you add a RoleBinding. The certificate lasts one hour because of expirationSeconds; there is no way to revoke it earlier, which is why short lifetimes matter.
Clean up:
kubectl delete csr janekubectl config delete-context jane; kubectl config delete-user janerm -f jane.key jane.csr jane.crtkubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-authnSecrets
Section titled “Secrets”Know
- Base64 is not encryption. Enable encryption at rest, limit
get/liston Secrets, and prefer external secret stores.
Read
Demo: The list verb reveals Secret values
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-secretskubectl config set-context --current --namespace=kcsa-secrets -
A role that may only list Secrets, not get them.
Terminal window kubectl create secret generic api-key --from-literal=key=TopSecretValuekubectl create serviceaccount listerkubectl create role list-secrets --verb=list --resource=secretskubectl create rolebinding lister --role=list-secrets --serviceaccount=kcsa-secrets:listerkubectl auth can-i get secret/api-key --as=system:serviceaccount:kcsa-secrets:lister -
List them as that account and read the output.
Terminal window kubectl get secrets -o jsonpath='{.items[?(@.metadata.name=="api-key")].data.key}' --as=system:serviceaccount:kcsa-secrets:lister | base64 -d; echo
What you should see: can-i get says no, yet the list response contains the full Secret data and the value decodes to TopSecretValue. list and watch on Secrets are as sensitive as get. Grant none of them unless the workload truly needs them.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-secretsOn this site
Isolation and Segmentation
Section titled “Isolation and Segmentation”Know
- Namespaces plus RBAC, NetworkPolicies, quotas, and dedicated nodes for sensitive workloads.
Read
Demo: A tenant namespace in four objects
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-tenantkubectl config set-context --current --namespace=kcsa-tenant -
Pod Security, a quota, a default limit, and default-deny networking.
Terminal window kubectl label namespace kcsa-tenant pod-security.kubernetes.io/enforce=restrictedkubectl create quota tenant --hard=pods=10,requests.cpu=2,requests.memory=2Gi,limits.cpu=4,limits.memory=4Gikubectl apply -f - <<'EOF'apiVersion: v1kind: LimitRangemetadata:name: tenant-defaultsspec:limits:- type: Containerdefault: {cpu: 250m, memory: 256Mi}defaultRequest: {cpu: 100m, memory: 128Mi}---apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata:name: default-denyspec:podSelector: {}policyTypes: ["Ingress", "Egress"]EOFkubectl get quota,limitrange,networkpolicy -
Grant the tenant team edit rights in its namespace only.
Terminal window kubectl create rolebinding tenant-edit --clusterrole=edit --group=tenant-akubectl auth can-i create deployments -n kcsa-tenant --as=someone --as-group=tenant-akubectl auth can-i create deployments -n default --as=someone --as-group=tenant-a
What you should see: Namespaces separate names; the four objects are what turn one into a boundary. The tenant group can deploy in its namespace and not in default. Namespaces still share nodes and the kernel, so for hostile tenants add node pools or sandboxed runtimes.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-tenantAudit Logging
Section titled “Audit Logging”Know
- An audit policy decides which requests are logged and at what level (None, Metadata, Request, RequestResponse).
Read
Demo: use the CKS demo for “Use Kubernetes audit logs to monitor access”. It creates a kind cluster with an audit policy and queries the log with jq.
Network Policy
Section titled “Network Policy”Know
- Default-deny plus explicit allows; enforcement depends on the CNI.
Read
Demo: use the CKA demo for “Define and enforce Network Policies”. It sets a default deny and allows a single client, then tests both.
Domain 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.