Skip to main content
Cluster operationsLesson 4 of 16

Building a cluster with kubeadm (CKA)

This covers "Prepare underlying infrastructure for installing a Kubernetes cluster" and "Create and manage Kubernetes clusters using kubeadm" in the CKA Cluster Architecture, Installation and Configuration domain. We turn two empty Linux machines into a v1.37 cluster and watch what each step writes to disk and to the cluster.

Moving an existing cluster to a new version is in Upgrading a cluster with kubeadm (CKA), and what happens when the certificates kubeadm creates expire is in Cluster Certificate Expiry.

cp-1 status—
CoreDNS—
Join token—
Command just runssh cp-1
Control plane node · cp-1Worker node · worker-1Operatorssh · sudoLoad balancercontrol-plane-endpointpkgs.k8s.iopackage repoNode prepswap · modules · sysctlcontainerdsystemd cgroup driverkubeletnode agentCNI Podse.g. Calicokubeadm initphasesControl planestatic Podsetcdstatic PodCoreDNSaddonBootstrap tokenTTL 24hkubeletworker-1App Podworker-1ssh
RequestResponse / reportWatchAppears in a later step

What you will learn

  • What a node needs before kubeadm runs: swap, modules, sysctl, runtime
  • Why the kubelet and the runtime must share the systemd cgroup driver
  • What the kubeadm init phases write, in order
  • Why Nodes are NotReady and CoreDNS is Pending until a CNI is installed
  • How kubeadm join trusts the control plane, and what to do when the token expires
  • An HA control plane with --control-plane-endpoint and --upload-certs

What each phase leaves behind​

Phase (kubeadm init)What it doesWhere to look
preflightChecks swap, ports, runtime, sysctls, permissionsThe error text; --ignore-preflight-errors only if you know why
certsCluster CA, API server, etcd and front-proxy certificates/etc/kubernetes/pki/, kubeadm certs check-expiration
kubeconfigadmin, super-admin, kubelet, controller-manager, scheduler kubeconfigs/etc/kubernetes/*.conf
etcd · control-planeStatic Pod manifests/etc/kubernetes/manifests/
kubelet-startWrites the kubelet config and starts it/var/lib/kubelet/config.yaml, journalctl -u kubelet
upload-configkubeadm and kubelet settings as ConfigMapskubectl -n kube-system get cm kubeadm-config kubelet-config
upload-certs (with --upload-certs)Encrypted control plane certs, deleted after two hoursSecret kubeadm-certs in kube-system
mark-control-planeLabel and NoSchedule taint on the nodekubectl describe node cp-1
bootstrap-tokenJoin token, 24h TTL by defaultkubeadm token list
addonCoreDNS and kube-proxykubectl -n kube-system get pods
SymptomLikely causeFix
preflight warns about swap, or the kubelet will not startSwap is on and failSwapOn is true (default)swapoff -a and remove it from /etc/fstab, or set failSwapOn: false
preflight: /proc/sys/net/ipv4/ip_forward is not 1IP forwarding offSet net.ipv4.ip_forward = 1 and run sysctl --system
Control plane Pods keep restarting after initKubelet and runtime cgroup drivers differSet SystemdCgroup = true in containerd, restart it
Node NotReady, CoreDNS PendingNo CNI installedInstall one Pod network add-on
join: token not found or expiredToken past its TTLkubeadm token create --print-join-command
control plane join cannot find certskubeadm-certs Secret expiredkubeadm init phase upload-certs --upload-certs

Try it yourself​

# On every node: prep
sudo swapoff -a # also remove swap from /etc/fstab
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
EOF
sudo sysctl --system && sysctl net.ipv4.ip_forward # should print 1
containerd config default | sudo tee /etc/containerd/config.toml >/dev/null
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml # check the key exists in your version
sudo systemctl restart containerd

# On every node: packages from pkgs.k8s.io (v1.37)
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.37/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.37/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update && sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

# On cp-1: init (CIDR depends on your CNI)
sudo kubeadm init --pod-network-cidr 192.168.0.0/16
mkdir -p $HOME/.kube && sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config && sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get nodes # NotReady until a CNI is installed
ls /etc/kubernetes/manifests # etcd, kube-apiserver, ...

# Later: a fresh join command, and tokens
sudo kubeadm token create --print-join-command
sudo kubeadm token list

Check yourself

  1. Right after kubeadm init, kubectl get nodes shows cp-1 NotReady and CoreDNS is Pending. What is the next step?
  2. Control plane Pods restart over and over right after init. The kubelet uses the systemd cgroup driver. What should you check first?
  3. Two days after init, the saved kubeadm join command fails. What is the fix?

Further reading: Installing kubeadm · Container runtimes · Creating a cluster with kubeadm · kubeadm init · HA topology with kubeadm · Upgrading a cluster with kubeadm (CKA) · Control Plane HA and etcd Quorum · Node NotReady and component failures (CKA)