Skip to content

CKA: Cluster Architecture, Installation and Configuration

25% of the CKA exam, 8 competencies. Back to the CKA 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.

Know

  • Roles and ClusterRoles define verbs on resources; RoleBindings and ClusterRoleBindings grant them. kubectl auth can-i --as tests the result.

Read

Demo: A read-only user for one namespace

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

    Terminal window
    kubectl create namespace cka-rbac
    kubectl config set-context --current --namespace=cka-rbac
  2. Create a service account, a Role that can only read pods, and a RoleBinding.

    Terminal window
    kubectl create serviceaccount viewer
    kubectl create role pod-reader --verb=get,list,watch --resource=pods,pods/log
    kubectl create rolebinding viewer-reads-pods --role=pod-reader --serviceaccount=cka-rbac:viewer
  3. Check what it can do without logging in as it.

    Terminal window
    kubectl auth can-i list pods --as=system:serviceaccount:cka-rbac:viewer
    kubectl auth can-i delete pods --as=system:serviceaccount:cka-rbac:viewer
    kubectl auth can-i list pods -n default --as=system:serviceaccount:cka-rbac:viewer
    kubectl auth can-i --list --as=system:serviceaccount:cka-rbac:viewer
  4. Now use its token from a kubeconfig of its own, so your admin certificate isn’t sent along.

    Terminal window
    kubectl config view --minify --raw -o jsonpath='{.clusters[0].cluster.certificate-authority-data}' | base64 -d > ca.crt
    SERVER=$(kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}')
    kubectl config set-cluster lab --server="$SERVER" --certificate-authority=ca.crt --embed-certs=true --kubeconfig=viewer.kubeconfig
    kubectl config set-credentials viewer --token="$(kubectl create token viewer --duration=10m)" --kubeconfig=viewer.kubeconfig
    kubectl config set-context viewer --cluster=lab --user=viewer --namespace=cka-rbac --kubeconfig=viewer.kubeconfig
    kubectl --kubeconfig=viewer.kubeconfig --context=viewer get pods
    kubectl --kubeconfig=viewer.kubeconfig --context=viewer delete pod anything

What you should see: Only list in its own namespace is allowed. With the viewer’s kubeconfig, get pods works and delete fails with pods "anything" is forbidden: User "system:serviceaccount:cka-rbac:viewer" cannot delete resource "pods". Don’t pass --token on top of the admin kubeconfig to test this: the admin client certificate is still sent and authenticates you as admin.

Clean up:

Terminal window
rm -f ca.crt viewer.kubeconfig
kubectl config set-context --current --namespace=default
kubectl delete namespace cka-rbac

Practise

  • Create a ServiceAccount that can only list pods in one namespace and prove it with kubectl auth can-i.

On this site

Prepare underlying infrastructure for installing a Kubernetes cluster

Section titled “Prepare underlying infrastructure for installing a Kubernetes cluster”

Know

  • Each node needs a container runtime with a matching cgroup driver, swap handled per the kubelet configuration, the required kernel modules and sysctls, and open ports between nodes.

Read

Demo: Check a node the way kubeadm does

  1. A kind node is a container, but it has what a real node needs. Look at each prerequisite.

    Terminal window
    docker exec kind-worker sh -c 'swapon --show; echo "swap lines above (none expected)"'
    docker exec kind-worker cat /proc/sys/net/ipv4/ip_forward
    docker exec kind-worker stat -fc %T /sys/fs/cgroup
    docker exec kind-worker grep -i SystemdCgroup /etc/containerd/config.toml
    docker exec kind-worker grep -i cgroupDriver /var/lib/kubelet/config.yaml
  2. List the images a control plane needs, as you would before an air-gapped install.

    Terminal window
    docker exec kind-control-plane kubeadm config images list

What you should see: No swap, IP forwarding is 1, cgroups are cgroup2fs, and containerd and the kubelet agree on the systemd cgroup driver. Those are the checks you do by hand on a VM before kubeadm init; a mismatched cgroup driver is a classic cause of a kubelet that won’t stay up.

Note: kind shares the host kernel, so kernel modules and sysctls come from your machine. On real VMs you set them yourself; follow the kubeadm install page linked above.

Create and manage Kubernetes clusters using kubeadm

Section titled “Create and manage Kubernetes clusters using kubeadm”

Know

  • kubeadm init bootstraps the control plane; kubeadm join adds nodes with a token and CA hash. A CNI must be installed before nodes become Ready.

Read

Demo: Read what kubeadm built

  1. kind uses kubeadm under the hood. Look at the configuration it used and the files it wrote.

    Terminal window
    kubectl get configmap kubeadm-config -n kube-system -o jsonpath='{.data.ClusterConfiguration}'
    docker exec kind-control-plane ls /etc/kubernetes /etc/kubernetes/pki
  2. Check certificate expiry and print a join command.

    Terminal window
    docker exec kind-control-plane kubeadm certs check-expiration
    docker exec kind-control-plane kubeadm token create --print-join-command
    docker exec kind-control-plane kubeadm token list

What you should see: The ClusterConfiguration uses kubeadm.k8s.io/v1beta4. Certificates are valid for one year and the CA for ten. The join command contains a bootstrap token that expires after 24 hours, plus the CA hash a new node uses to trust the control plane.

Note: To practise kubeadm init and join end to end, use two or three VMs and the official “Creating a cluster with kubeadm” page; kind can’t show the install itself.

Practise

  • Build a two-node cluster with kubeadm on VMs and install a CNI.

Manage the lifecycle of Kubernetes clusters

Section titled “Manage the lifecycle of Kubernetes clusters”

Know

  • Upgrade one minor version at a time: control plane first (kubeadm upgrade plan, apply), then drain, upgrade, and uncordon each node. Back up etcd before you start.

Read

Demo: Plan an upgrade and back up etcd

  1. See what an upgrade would do. On a real control plane you would follow this with kubeadm upgrade apply.

    Terminal window
    docker exec kind-control-plane kubeadm upgrade plan 2>&1 | tail -20
    kubectl version
  2. Take an etcd snapshot. The etcd image has no shell, so call etcdctl directly.

    Terminal window
    kubectl -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 \
    snapshot save /var/lib/etcd/demo-snapshot.db
    docker exec kind-control-plane ls -lh /var/lib/etcd/demo-snapshot.db
    kubectl -n kube-system exec etcd-kind-control-plane -- etcdutl snapshot status /var/lib/etcd/demo-snapshot.db -w table
  3. The node side of an upgrade: drain, upgrade the kubelet, uncordon. Practise the drain part here.

    Terminal window
    kubectl drain kind-worker --ignore-daemonsets --delete-emptydir-data
    kubectl get nodes
    kubectl uncordon kind-worker

What you should see: upgrade plan lists component versions and what it could move to (it needs internet access to look up versions). The snapshot status table shows a hash, revision, and key count. The snapshot is written to /var/lib/etcd, which is a host path, so it survives the etcd container restarting.

Clean up:

Terminal window
docker exec kind-control-plane rm -f /var/lib/etcd/demo-snapshot.db

Practise

  • Take an etcd snapshot with etcdctl snapshot save and restore it to a new data directory.

On this site

Implement and configure a highly-available control plane

Section titled “Implement and configure a highly-available control plane”

Know

  • Multiple control plane nodes behind a load balancer for the API server, with stacked or external etcd. etcd needs an odd number of members for quorum.

Read

Demo: A three-node control plane on kind

  1. Create a separate cluster with three control plane nodes.

    Terminal window
    cat > ha.yaml <<'EOF'
    kind: Cluster
    apiVersion: kind.x-k8s.io/v1alpha4
    nodes:
    - role: control-plane
    - role: control-plane
    - role: control-plane
    - role: worker
    EOF
    kind create cluster --name ha --config ha.yaml --image kindest/node:v1.37.0@sha256:a1ed56cfb0e7b93589bdf97c8cd566405a265939e3620fc4f5de89adff580ae5
    kubectl --context kind-ha get nodes
  2. See the load balancer in front of the API servers, and the stacked etcd members.

    Terminal window
    docker ps --filter name=ha-external-load-balancer --format '{{.Names}} {{.Ports}}'
    kubectl --context kind-ha get pods -n kube-system -l component=etcd -o wide
    kubectl --context kind-ha -n kube-system exec etcd-ha-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 \
    member list -w table
  3. Stop one control plane node and keep working.

    Terminal window
    docker stop ha-control-plane2
    kubectl --context kind-ha create deployment survive --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- /agnhost pause
    kubectl --context kind-ha get deployment survive

What you should see: Three etcd members, one per control plane node (stacked topology), behind a load balancer container. With one node stopped, etcd still has quorum (2 of 3) and the API keeps working. Stop a second one and writes fail: that is why HA needs an odd number, at least three.

Clean up:

Terminal window
kind delete cluster --name ha && rm -f ha.yaml
kubectl config use-context kind-kind

Use Helm and Kustomize to install cluster components

Section titled “Use Helm and Kustomize to install cluster components”

Know

  • Helm installs charts with values (helm install, upgrade, rollback). Kustomize layers overlays on base YAML and is built into kubectl apply -k.

Read

Demo: The same component two ways

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

    Terminal window
    kubectl create namespace cka-kustomize
    kubectl config set-context --current --namespace=cka-kustomize
  2. Helm: inspect a chart before installing it. (The lab setup already installed metrics-server this way.)

    Terminal window
    helm list -A
    helm get values metrics-server -n kube-system
    helm show values metrics-server/metrics-server --version 3.14.0 | head -30
    helm template metrics-server metrics-server/metrics-server --version 3.14.0 -n kube-system | grep -c '^kind:'
  3. Kustomize: patch upstream YAML without editing it.

    Terminal window
    mkdir -p kz && cat > kz/kustomization.yaml <<'EOF'
    apiVersion: kustomize.config.k8s.io/v1beta1
    kind: Kustomization
    namespace: cka-kustomize
    resources:
    - deploy.yaml
    labels:
    - pairs:
    team: platform
    includeSelectors: false
    patches:
    - target:
    kind: Deployment
    name: web
    patch: |-
    - op: replace
    path: /spec/replicas
    value: 3
    EOF
    cat > kz/deploy.yaml <<'EOF'
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: web
    spec:
    replicas: 1
    selector:
    matchLabels:
    app: web
    template:
    metadata:
    labels:
    app: web
    spec:
    containers:
    - name: app
    image: registry.k8s.io/e2e-test-images/agnhost:2.66.1
    args: ["netexec", "--http-port=8080"]
    EOF
    kubectl kustomize kz/
    kubectl apply -k kz/
    kubectl get deployment web --show-labels

What you should see: helm template renders every object the chart would create, without a cluster. kubectl kustomize prints the patched YAML: 3 replicas and a team: platform label, while deploy.yaml still says 1. Kustomize is built into kubectl; Helm is a separate binary.

Clean up:

Terminal window
rm -rf kz
kubectl config set-context --current --namespace=default
kubectl delete namespace cka-kustomize

Practise

  • Install a chart with a custom values file, then render the same chart with helm template and compare.

Understand extension interfaces (CNI, CSI, CRI, etc.)

Section titled “Understand extension interfaces (CNI, CSI, CRI, etc.)”

Know

  • CRI connects the kubelet to runtimes, CNI configures pod networking, CSI connects storage. Each is a plugin contract, so implementations are swappable.

Read

Demo: Find each interface on a running node

  1. CRI: the kubelet talks to containerd over a socket.

    Terminal window
    docker exec kind-worker sh -c 'grep -h -i runtime /var/lib/kubelet/config.yaml /var/lib/kubelet/kubeadm-flags.env'
    docker exec kind-worker crictl version
  2. CNI: plugin binaries and configuration live in well-known directories.

    Terminal window
    docker exec kind-worker ls /opt/cni/bin
    docker exec kind-worker sh -c 'cat /etc/cni/net.d/*'
  3. CSI: which drivers are registered, and what provisions volumes in kind.

    Terminal window
    kubectl get csidrivers
    kubectl get storageclass -o custom-columns=NAME:.metadata.name,PROVISIONER:.provisioner

What you should see: containerd answers on the CRI socket, kindnet’s config sits in /etc/cni/net.d, and there are no CSI drivers: kind’s standard class uses the local-path provisioner, which isn’t a CSI driver. On a cloud cluster kubectl get csidrivers lists the cloud’s disk and file drivers.

Understand CRDs, install and configure operators

Section titled “Understand CRDs, install and configure operators”

Know

  • A CustomResourceDefinition adds a new API type; an operator is a controller that manages applications through custom resources.

Read

Demo: Add a resource type and use it

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

    Terminal window
    kubectl create namespace cka-crd
    kubectl config set-context --current --namespace=cka-crd
  2. Create a CustomResourceDefinition.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: apiextensions.k8s.io/v1
    kind: CustomResourceDefinition
    metadata:
    name: backups.demo.brokeninprod.com
    spec:
    group: demo.brokeninprod.com
    scope: Namespaced
    names:
    plural: backups
    singular: backup
    kind: Backup
    shortNames: ["bk"]
    versions:
    - name: v1
    served: true
    storage: true
    schema:
    openAPIV3Schema:
    type: object
    properties:
    spec:
    type: object
    required: ["schedule"]
    properties:
    schedule:
    type: string
    retainDays:
    type: integer
    minimum: 1
    EOF
    kubectl get crd backups.demo.brokeninprod.com
  3. Create objects of the new kind, including an invalid one.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: demo.brokeninprod.com/v1
    kind: Backup
    metadata:
    name: nightly
    spec:
    schedule: "0 2 * * *"
    retainDays: 7
    EOF
    kubectl get bk
    kubectl explain backup.spec
    kubectl apply -f - <<'EOF'
    # expected to fail: schedule is missing and retainDays is below the minimum
    apiVersion: demo.brokeninprod.com/v1
    kind: Backup
    metadata:
    name: broken
    spec:
    retainDays: 0
    EOF

What you should see: kubectl get bk works like any built-in type and explain reads your schema. The invalid object is rejected with errors for the missing schedule and retainDays below 1. A CRD only stores data; an operator is the controller that watches these objects and acts on them.

Clean up:

Terminal window
kubectl delete crd backups.demo.brokeninprod.com
kubectl config set-context --current --namespace=default
kubectl delete namespace cka-crd

Practise

  • Install an operator from its manifests and list the CRDs it added with kubectl get crd.

On this site


Domain and competency names are from the CNCF CKA curriculum (v1.37), cncf/curriculum, licensed CC BY 4.0. Summaries, demos, and exercises are original to this site.