KCNA: Kubernetes Fundamentals
44% of the KCNA exam, 4 competencies. Back to the KCNA 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.
Kubernetes Core Concepts
Section titled “Kubernetes Core Concepts”Know
- A cluster is a control plane (API server, etcd, scheduler, controller manager) plus worker nodes running the kubelet, a container runtime, and usually kube-proxy.
- Everything is an API object with
spec(what you want) andstatus(what is). Controllers loop to make status match spec. - Pods are the smallest unit you deploy. You rarely create them directly; Deployments, StatefulSets, DaemonSets and Jobs create them for you.
- Namespaces scope names and policies. Labels and selectors are how objects find each other.
Read
Demo: Watch a controller put things back
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcna-corekubectl config set-context --current --namespace=kcna-core -
Look at the control plane. On a kubeadm-style cluster like kind, its components run as pods.
Terminal window kubectl get pods -n kube-system -o widekubectl get nodes -o wide -
Create a Deployment with two replicas, then delete one of its pods.
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/webkubectl delete $(kubectl get pods -l app=web -o name | head -1) --wait=falsekubectl get pods -l app=web -w -
Compare what you asked for with what exists.
Terminal window kubectl get deployment web -o jsonpath='{.spec.replicas} wanted, {.status.readyReplicas} ready{"\n"}'kubectl get replicaset -l app=web
What you should see: A new pod appears within seconds with a different name. Nobody ran a command to create it: the ReplicaSet controller saw fewer pods than spec.replicas and made one. That loop of comparing spec with status is how all of Kubernetes works.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcna-corePractise
- Create a kind cluster and run
kubectl get pods -n kube-systemto see the control plane components as pods. - Run
kubectl explain deployment.specand read the fields.
On this site
Administration
Section titled “Administration”Know
kubectltalks to the API server using a kubeconfig: clusters, users, and contexts.- Imperative commands (
kubectl create,run,expose) are for quick work; declarative YAML withkubectl applyis how teams manage real systems. - Access is authenticated, then authorized (usually RBAC), then passed through admission control.
Read
- Organizing cluster access using kubeconfig
- kubectl quick reference
- Controlling access to the Kubernetes API
Demo: Find out who you are and what you can do
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcna-adminkubectl config set-context --current --namespace=kcna-admin -
Read your kubeconfig: which cluster, which user, which context.
Terminal window kubectl config get-contextskubectl config view --minify -
Ask the API server who it thinks you are, then what you may do.
Terminal window kubectl auth whoamikubectl auth can-i create deploymentskubectl auth can-i '*' '*' --all-namespaces -
Do the same thing imperatively and declaratively, and compare.
Terminal window kubectl create configmap imperative --from-literal=mode=quickkubectl create configmap declarative --from-literal=mode=reviewed --dry-run=client -o yaml > cm.yamlkubectl apply -f cm.yamlkubectl get configmaps
What you should see: auth whoami shows the kubernetes-admin user in the kubeadm:cluster-admins group, and every can-i answers yes. That is normal for a lab and exactly what you never hand out in production. The second ConfigMap came from a file you could review and commit; that is the habit to build.
Clean up:
rm -f cm.yamlkubectl config set-context --current --namespace=defaultkubectl delete namespace kcna-adminPractise
- Switch between two contexts with
kubectl config use-context, then check which one is active.
On this site
Scheduling
Section titled “Scheduling”Know
- The scheduler picks a node for each new pod: it filters out nodes that cannot run it, then scores the rest.
- Requests (not limits) decide whether a pod fits. Node selectors, affinity, taints and tolerations steer placement.
- A pod that fits nowhere stays Pending with a FailedScheduling event.
Read
Demo: Make a pod unschedulable on purpose
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcna-schedkubectl config set-context --current --namespace=kcna-sched -
Ask for more CPU than any node has.
Terminal window kubectl run greedy --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 --overrides='{"spec":{"containers":[{"name":"greedy","image":"registry.k8s.io/e2e-test-images/agnhost:2.66.1","args":["pause"],"resources":{"requests":{"cpu":"64"}}}]}}'kubectl get pod greedy -
Read why the scheduler refused.
Terminal window kubectl describe pod greedy | sed -n '/Events:/,$p'kubectl events --for pod/greedy -
Now steer a pod to one node with a label and a nodeSelector.
Terminal window kubectl label node kind-worker2 demo=pickedkubectl apply -f - <<'EOF'apiVersion: v1kind: Podmetadata:name: placedspec:nodeSelector:demo: pickedcontainers:- name: appimage: registry.k8s.io/e2e-test-images/agnhost:2.66.1args: ["pause"]EOFkubectl get pod placed -o wide
What you should see: greedy stays Pending with a FailedScheduling event that says how many nodes had insufficient CPU. placed lands on kind-worker2 and nowhere else.
Clean up:
kubectl label node kind-worker2 demo-kubectl config set-context --current --namespace=defaultkubectl delete namespace kcna-schedPractise
- Ask for more CPU than your node has and read the FailedScheduling event.
On this site
Containerization
Section titled “Containerization”Know
- A container image is layered, immutable filesystem content plus metadata; a container is a running instance isolated with Linux namespaces and limited with cgroups.
- Kubernetes talks to runtimes such as containerd and CRI-O through the Container Runtime Interface (CRI). Docker Engine is no longer used directly by the kubelet.
- Images are referenced by registry, repository, and tag or digest. A digest pins exact content.
Read
Demo: Tags move, digests don’t
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcna-imageskubectl config set-context --current --namespace=kcna-images -
Run a pod by tag and read the digest the node actually pulled.
Terminal window kubectl run bytag --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- sleep 3600kubectl wait --for=condition=Ready pod/bytag --timeout=120skubectl get pod bytag -o jsonpath='{.status.containerStatuses[0].imageID}{"\n"}' -
Look at the same image from the node’s side, through the container runtime.
Terminal window docker exec kind-worker crictl images | grep busyboxdocker exec kind-worker crictl ps --name bytag -
Run a second pod pinned by that digest.
Terminal window DIGEST=$(kubectl get pod bytag -o jsonpath='{.status.containerStatuses[0].imageID}')kubectl run bydigest --image="$DIGEST" -- sleep 3600kubectl get pod bydigest -o jsonpath='{.spec.containers[0].image}{"\n"}'
What you should see: The imageID is a sha256: digest. The tag is a pointer someone can move; the digest names exact content. crictl shows the kubelet talks to containerd, not Docker. (If bytag landed on kind-worker2, run the crictl lines there.)
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcna-imagesPractise
- Pull the same image by tag and by digest and compare
kubectl get pod -o jsonpathimage IDs.
On this site
Domain and competency names are from the CNCF KCNA curriculum (current curriculum (unversioned)), cncf/curriculum, licensed CC BY 4.0. Summaries, demos, and exercises are original to this site.