CKAD: Application Environment, Configuration and Security
25% of the CKAD exam, 8 competencies. Back to the CKAD 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.
Discover and use resources that extend Kubernetes (CRD, Operators)
Section titled “Discover and use resources that extend Kubernetes (CRD, Operators)”Know
kubectl api-resourceslists every type the cluster serves, including custom ones.kubectl explainworks on CRDs that publish a schema.
Read
Demo: Learn an unfamiliar CRD from the cluster itself
-
The Gateway API is a set of CRDs installed in the lab. Find what they add.
Terminal window kubectl get crd | grep gateway.networking.k8s.iokubectl api-resources --api-group=gateway.networking.k8s.io -
Read its schema without opening a browser.
Terminal window kubectl explain httproute.speckubectl explain httproute.spec.rules.backendRefskubectl explain gateway.spec.listeners --recursive | head -30 -
Use it, and read what its controller wrote back.
Terminal window kubectl get gatewayclass -o widekubectl get gatewayclass cloud-provider-kind -o jsonpath='{.status.conditions[*].type}{"\n"}'
What you should see: api-resources lists kinds, short names, and whether they are namespaced. explain works on CRDs exactly as on built-in types because the CRD carries an OpenAPI schema. status is written by the controller (here, cloud-provider-kind): a CRD without a running controller accepts objects and does nothing with them.
Understand authentication, authorization and admission control
Section titled “Understand authentication, authorization and admission control”Know
- Every request is authenticated, authorized (RBAC), and admitted (mutating then validating). Admission can change or reject objects.
Read
Demo: Authenticated, authorized, then admitted
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace ckad-accesskubectl config set-context --current --namespace=ckad-access -
Authentication and authorization: who you are, and what you may do.
Terminal window kubectl auth whoamikubectl create serviceaccount appkubectl auth can-i create deployments --as=system:serviceaccount:ckad-access:app -
Admission: a ValidatingAdmissionPolicy that caps replicas at 3 in this namespace.
Terminal window kubectl apply -f - <<'EOF'apiVersion: admissionregistration.k8s.io/v1kind: ValidatingAdmissionPolicymetadata:name: max-replicasspec:failurePolicy: FailmatchConstraints:resourceRules:- apiGroups: ["apps"]apiVersions: ["v1"]operations: ["CREATE", "UPDATE"]resources: ["deployments"]validations:- expression: "object.spec.replicas <= 3"message: "deployments here may have at most 3 replicas"---apiVersion: admissionregistration.k8s.io/v1kind: ValidatingAdmissionPolicyBindingmetadata:name: max-replicas-ckadspec:policyName: max-replicasvalidationActions: ["Deny"]matchResources:namespaceSelector:matchLabels:kubernetes.io/metadata.name: ckad-accessEOFsleep 3kubectl create deployment ok --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 --replicas=3 -- /agnhost pausekubectl create deployment toomany --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 --replicas=5 -- /agnhost pause
What you should see: The service account can’t create deployments: authenticated, but not authorized. As admin you can, but toomany is still rejected with the policy’s message: admission runs after authorization and applies to everyone, including cluster admins.
Clean up:
kubectl delete validatingadmissionpolicybinding max-replicas-ckadkubectl delete validatingadmissionpolicy max-replicaskubectl config set-context --current --namespace=defaultkubectl delete namespace ckad-accessOn this site
Understand requests, limits, quotas
Section titled “Understand requests, limits, quotas”Know
- Requests reserve, limits cap. A ResourceQuota caps a namespace total; LimitRange sets per-pod defaults and bounds.
Read
Demo: A quota that requires requests
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace ckad-quotakubectl config set-context --current --namespace=ckad-quota -
Set a quota on CPU and memory requests and limits.
Terminal window kubectl create quota team --hard=requests.cpu=1,requests.memory=1Gi,limits.cpu=2,limits.memory=2Gikubectl describe quota team -
A pod without resources, then one with them.
Terminal window kubectl run bare --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pausekubectl run sized --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 --overrides='{"spec":{"containers":[{"name":"sized","image":"registry.k8s.io/e2e-test-images/agnhost:2.66.1","args":["pause"],"resources":{"requests":{"cpu":"250m","memory":"128Mi"},"limits":{"cpu":"500m","memory":"256Mi"}}}]}}'kubectl describe quota team
What you should see: bare is rejected with failed quota: team: must specify limits.cpu for: bare; limits.memory for: bare; requests.cpu .... Once a quota covers a resource, every pod must state it. A LimitRange with defaults fixes this for pods that don’t.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace ckad-quotaOn this site
Define resource requirements
Section titled “Define resource requirements”Know
- Set CPU and memory requests on every container; memory limits equal to requests avoid surprise OOM kills.
Read
Demo: Three QoS classes
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace ckad-qoskubectl config set-context --current --namespace=ckad-qos -
Same image, three resource shapes.
Terminal window kubectl run besteffort --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pausekubectl run burstable --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 --overrides='{"spec":{"containers":[{"name":"burstable","image":"registry.k8s.io/e2e-test-images/agnhost:2.66.1","args":["pause"],"resources":{"requests":{"memory":"64Mi"}}}]}}'kubectl run guaranteed --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 --overrides='{"spec":{"containers":[{"name":"guaranteed","image":"registry.k8s.io/e2e-test-images/agnhost:2.66.1","args":["pause"],"resources":{"requests":{"cpu":"100m","memory":"64Mi"},"limits":{"cpu":"100m","memory":"64Mi"}}}]}}'kubectl get pods -o custom-columns=NAME:.metadata.name,QOS:.status.qosClass
What you should see: BestEffort, Burstable, Guaranteed. Under memory pressure the kubelet evicts BestEffort first and Guaranteed last. Requests decide scheduling; limits decide throttling (CPU) and OOM kills (memory).
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace ckad-qosOn this site
Understand ConfigMaps
Section titled “Understand ConfigMaps”Know
- Create from literals, files, or env files. Consume as env, envFrom, or a volume.
Read
Demo: From a file, as env, and immutable
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace ckad-cmkubectl config set-context --current --namespace=ckad-cm -
Create a ConfigMap from a file and load every key as environment variables.
Terminal window printf 'COLOR=blue\nSIZE=large\n' > app.envkubectl create configmap app --from-env-file=app.envkubectl run show --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 --restart=Never --overrides='{"spec":{"containers":[{"name":"show","image":"registry.k8s.io/e2e-test-images/busybox:1.37.0-2","command":["sh","-c","env | grep -E \"COLOR|SIZE\""],"envFrom":[{"configMapRef":{"name":"app"}}]}]}}'sleep 10; kubectl logs show -
Mark a ConfigMap immutable and try to change it.
Terminal window kubectl apply -f - <<'EOF'apiVersion: v1kind: ConfigMapmetadata:name: frozenimmutable: truedata:mode: stableEOFkubectl patch configmap frozen -p '{"data":{"mode":"changed"}}'
What you should see: The pod prints both keys. The patch fails with field is immutable when immutable is set. Immutable ConfigMaps can only be deleted and recreated, which protects against accidental changes and saves the kubelet from watching them.
Clean up:
rm -f app.envkubectl config set-context --current --namespace=defaultkubectl delete namespace ckad-cmOn this site
Create & consume Secrets
Section titled “Create & consume Secrets”Know
- Types include Opaque, kubernetes.io/tls, and kubernetes.io/dockerconfigjson. Values are base64, not encrypted.
Read
Demo: Generic, TLS, and registry Secrets
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace ckad-secretskubectl config set-context --current --namespace=ckad-secrets -
Create the three common types.
Terminal window kubectl create secret generic db --from-literal=username=app --from-literal=password='p@ss'openssl req -x509 -newkey rsa:2048 -nodes -keyout tls.key -out tls.crt -days 1 -subj '/CN=demo.example'kubectl create secret tls web-tls --cert=tls.crt --key=tls.keykubectl create secret docker-registry regcred --docker-server=registry.example --docker-username=me --docker-password=not-realkubectl get secrets -o custom-columns=NAME:.metadata.name,TYPE:.type -
Mount one with tight file permissions.
Terminal window kubectl apply -f - <<'EOF'apiVersion: v1kind: Podmetadata:name: readerspec:containers:- name: appimage: registry.k8s.io/e2e-test-images/busybox:1.37.0-2command: ["sh", "-c", "ls -l /secrets/; cat /secrets/username; echo; sleep 3600"]volumeMounts:- name: dbmountPath: /secretsreadOnly: truevolumes:- name: dbsecret:secretName: dbdefaultMode: 0400EOFkubectl wait --for=condition=Ready pod/reader --timeout=60s && kubectl logs reader
What you should see: Three types: Opaque, kubernetes.io/tls, and kubernetes.io/dockerconfigjson. The files are read-only links with mode 0400 (-r--------). Secrets are base64, not encrypted: protect them with RBAC and encryption at rest.
Clean up:
rm -f tls.crt tls.keykubectl config set-context --current --namespace=defaultkubectl delete namespace ckad-secretsPractise
- Create a docker-registry Secret and use it as an
imagePullSecret.
Understand ServiceAccounts
Section titled “Understand ServiceAccounts”Know
- Each pod runs as a ServiceAccount; tokens are short-lived and projected. Disable automounting when a pod never calls the API.
Read
Demo: What a pod’s identity can do
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace ckad-sakubectl config set-context --current --namespace=ckad-sa -
Every pod gets the
defaultservice account and a token unless you say otherwise.Terminal window kubectl run who --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- sleep 3600kubectl wait --for=condition=Ready pod/who --timeout=60skubectl get pod who -o jsonpath='{.spec.serviceAccountName}{"\n"}'kubectl exec who -- ls /var/run/secrets/kubernetes.io/serviceaccount/ -
Use that token from inside a pod: the kubectl image picks it up automatically.
Terminal window kubectl run probe --rm -i --restart=Never --image=registry.k8s.io/kubectl:v1.37.2 -- get pods -
Give a dedicated service account just enough, and turn off the token where it isn’t needed.
Terminal window kubectl create serviceaccount listerkubectl create role list-pods --verb=list --resource=podskubectl create rolebinding lister --role=list-pods --serviceaccount=ckad-sa:listerkubectl run probe2 --rm -i --restart=Never --image=registry.k8s.io/kubectl:v1.37.2 --overrides='{"spec":{"serviceAccountName":"lister"}}' -- get podskubectl run notoken --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 --overrides='{"spec":{"automountServiceAccountToken":false}}' -- sleep 3600kubectl wait --for=condition=Ready pod/notoken --timeout=60skubectl exec notoken -- ls /var/run/secrets/kubernetes.io/serviceaccount/ || echo "no token mounted"
What you should see: The default account’s token works (authentication succeeds) but listing pods is forbidden. The lister account can list pods and nothing else. notoken has no token at all, which is right for any pod that never talks to the API.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace ckad-saOn this site
Understand Application Security (SecurityContexts, Capabilities, etc.)
Section titled “Understand Application Security (SecurityContexts, Capabilities, etc.)”Know
runAsNonRoot,runAsUser,readOnlyRootFilesystem,allowPrivilegeEscalation: false, and dropping capabilities. Pod-level settings apply to all containers unless overridden.
Read
Demo: Run as a user, read-only, no extra capabilities
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace ckad-secctxkubectl config set-context --current --namespace=ckad-secctx -
A locked-down pod with a writable /tmp.
Terminal window kubectl apply -f - <<'EOF'apiVersion: v1kind: Podmetadata:name: lockedspec:securityContext:runAsUser: 10001runAsGroup: 10001fsGroup: 10001containers:- name: appimage: registry.k8s.io/e2e-test-images/busybox:1.37.0-2command: ["sleep", "3600"]securityContext:allowPrivilegeEscalation: falsereadOnlyRootFilesystem: truecapabilities:drop: ["ALL"]volumeMounts:- name: tmpmountPath: /tmpvolumes:- name: tmpemptyDir: {}EOFkubectl wait --for=condition=Ready pod/locked --timeout=60s -
Test each control from inside.
Terminal window kubectl exec locked -- idkubectl exec locked -- sh -c 'touch /usr/x' || truekubectl exec locked -- sh -c 'touch /tmp/x && ls -ln /tmp/x'kubectl exec locked -- grep Cap /proc/1/status
What you should see: id shows uid 10001. Writing to /usr fails with Read-only file system, while /tmp works and the file belongs to group 10001 (fsGroup). The capability masks are all zeros: the process can’t bind low ports, change file ownership, or use raw sockets.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace ckad-secctxPractise
- Make a pod pass the
restrictedPod Security Standard.
On this site
Domain and competency names are from the CNCF CKAD curriculum (v1.37), cncf/curriculum, licensed CC BY 4.0. Summaries, demos, and exercises are original to this site.