Skip to content

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-resources lists every type the cluster serves, including custom ones. kubectl explain works on CRDs that publish a schema.

Read

Demo: Learn an unfamiliar CRD from the cluster itself

  1. 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.io
    kubectl api-resources --api-group=gateway.networking.k8s.io
  2. Read its schema without opening a browser.

    Terminal window
    kubectl explain httproute.spec
    kubectl explain httproute.spec.rules.backendRefs
    kubectl explain gateway.spec.listeners --recursive | head -30
  3. Use it, and read what its controller wrote back.

    Terminal window
    kubectl get gatewayclass -o wide
    kubectl 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

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace ckad-access
    kubectl config set-context --current --namespace=ckad-access
  2. Authentication and authorization: who you are, and what you may do.

    Terminal window
    kubectl auth whoami
    kubectl create serviceaccount app
    kubectl auth can-i create deployments --as=system:serviceaccount:ckad-access:app
  3. Admission: a ValidatingAdmissionPolicy that caps replicas at 3 in this namespace.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: admissionregistration.k8s.io/v1
    kind: ValidatingAdmissionPolicy
    metadata:
    name: max-replicas
    spec:
    failurePolicy: Fail
    matchConstraints:
    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/v1
    kind: ValidatingAdmissionPolicyBinding
    metadata:
    name: max-replicas-ckad
    spec:
    policyName: max-replicas
    validationActions: ["Deny"]
    matchResources:
    namespaceSelector:
    matchLabels:
    kubernetes.io/metadata.name: ckad-access
    EOF
    sleep 3
    kubectl create deployment ok --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 --replicas=3 -- /agnhost pause
    kubectl 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:

Terminal window
kubectl delete validatingadmissionpolicybinding max-replicas-ckad
kubectl delete validatingadmissionpolicy max-replicas
kubectl config set-context --current --namespace=default
kubectl delete namespace ckad-access

On this site

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

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace ckad-quota
    kubectl config set-context --current --namespace=ckad-quota
  2. 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=2Gi
    kubectl describe quota team
  3. A pod without resources, then one with them.

    Terminal window
    kubectl run bare --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pause
    kubectl 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:

Terminal window
kubectl config set-context --current --namespace=default
kubectl delete namespace ckad-quota

On this site

Know

  • Set CPU and memory requests on every container; memory limits equal to requests avoid surprise OOM kills.

Read

Demo: Three QoS classes

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace ckad-qos
    kubectl config set-context --current --namespace=ckad-qos
  2. Same image, three resource shapes.

    Terminal window
    kubectl run besteffort --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pause
    kubectl 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:

Terminal window
kubectl config set-context --current --namespace=default
kubectl delete namespace ckad-qos

On this site

Know

  • Create from literals, files, or env files. Consume as env, envFrom, or a volume.

Read

Demo: From a file, as env, and immutable

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace ckad-cm
    kubectl config set-context --current --namespace=ckad-cm
  2. Create a ConfigMap from a file and load every key as environment variables.

    Terminal window
    printf 'COLOR=blue\nSIZE=large\n' > app.env
    kubectl create configmap app --from-env-file=app.env
    kubectl 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
  3. Mark a ConfigMap immutable and try to change it.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: frozen
    immutable: true
    data:
    mode: stable
    EOF
    kubectl 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:

Terminal window
rm -f app.env
kubectl config set-context --current --namespace=default
kubectl delete namespace ckad-cm

On this site

Know

  • Types include Opaque, kubernetes.io/tls, and kubernetes.io/dockerconfigjson. Values are base64, not encrypted.

Read

Demo: Generic, TLS, and registry Secrets

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace ckad-secrets
    kubectl config set-context --current --namespace=ckad-secrets
  2. 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.key
    kubectl create secret docker-registry regcred --docker-server=registry.example --docker-username=me --docker-password=not-real
    kubectl get secrets -o custom-columns=NAME:.metadata.name,TYPE:.type
  3. Mount one with tight file permissions.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: v1
    kind: Pod
    metadata:
    name: reader
    spec:
    containers:
    - name: app
    image: registry.k8s.io/e2e-test-images/busybox:1.37.0-2
    command: ["sh", "-c", "ls -l /secrets/; cat /secrets/username; echo; sleep 3600"]
    volumeMounts:
    - name: db
    mountPath: /secrets
    readOnly: true
    volumes:
    - name: db
    secret:
    secretName: db
    defaultMode: 0400
    EOF
    kubectl 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:

Terminal window
rm -f tls.crt tls.key
kubectl config set-context --current --namespace=default
kubectl delete namespace ckad-secrets

Practise

  • Create a docker-registry Secret and use it as an imagePullSecret.

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

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace ckad-sa
    kubectl config set-context --current --namespace=ckad-sa
  2. Every pod gets the default service 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 3600
    kubectl wait --for=condition=Ready pod/who --timeout=60s
    kubectl get pod who -o jsonpath='{.spec.serviceAccountName}{"\n"}'
    kubectl exec who -- ls /var/run/secrets/kubernetes.io/serviceaccount/
  3. 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
  4. Give a dedicated service account just enough, and turn off the token where it isn’t needed.

    Terminal window
    kubectl create serviceaccount lister
    kubectl create role list-pods --verb=list --resource=pods
    kubectl create rolebinding lister --role=list-pods --serviceaccount=ckad-sa:lister
    kubectl run probe2 --rm -i --restart=Never --image=registry.k8s.io/kubectl:v1.37.2 --overrides='{"spec":{"serviceAccountName":"lister"}}' -- get pods
    kubectl run notoken --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 --overrides='{"spec":{"automountServiceAccountToken":false}}' -- sleep 3600
    kubectl wait --for=condition=Ready pod/notoken --timeout=60s
    kubectl 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:

Terminal window
kubectl config set-context --current --namespace=default
kubectl delete namespace ckad-sa

On 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

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace ckad-secctx
    kubectl config set-context --current --namespace=ckad-secctx
  2. A locked-down pod with a writable /tmp.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: v1
    kind: Pod
    metadata:
    name: locked
    spec:
    securityContext:
    runAsUser: 10001
    runAsGroup: 10001
    fsGroup: 10001
    containers:
    - name: app
    image: registry.k8s.io/e2e-test-images/busybox:1.37.0-2
    command: ["sleep", "3600"]
    securityContext:
    allowPrivilegeEscalation: false
    readOnlyRootFilesystem: true
    capabilities:
    drop: ["ALL"]
    volumeMounts:
    - name: tmp
    mountPath: /tmp
    volumes:
    - name: tmp
    emptyDir: {}
    EOF
    kubectl wait --for=condition=Ready pod/locked --timeout=60s
  3. Test each control from inside.

    Terminal window
    kubectl exec locked -- id
    kubectl exec locked -- sh -c 'touch /usr/x' || true
    kubectl 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:

Terminal window
kubectl config set-context --current --namespace=default
kubectl delete namespace ckad-secctx

Practise

  • Make a pod pass the restricted Pod 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.