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.
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 does | Where to look |
|---|---|---|
| preflight | Checks swap, ports, runtime, sysctls, permissions | The error text; --ignore-preflight-errors only if you know why |
| certs | Cluster CA, API server, etcd and front-proxy certificates | /etc/kubernetes/pki/, kubeadm certs check-expiration |
| kubeconfig | admin, super-admin, kubelet, controller-manager, scheduler kubeconfigs | /etc/kubernetes/*.conf |
| etcd · control-plane | Static Pod manifests | /etc/kubernetes/manifests/ |
| kubelet-start | Writes the kubelet config and starts it | /var/lib/kubelet/config.yaml, journalctl -u kubelet |
| upload-config | kubeadm and kubelet settings as ConfigMaps | kubectl -n kube-system get cm kubeadm-config kubelet-config |
upload-certs (with --upload-certs) | Encrypted control plane certs, deleted after two hours | Secret kubeadm-certs in kube-system |
| mark-control-plane | Label and NoSchedule taint on the node | kubectl describe node cp-1 |
| bootstrap-token | Join token, 24h TTL by default | kubeadm token list |
| addon | CoreDNS and kube-proxy | kubectl -n kube-system get pods |
| Symptom | Likely cause | Fix |
|---|---|---|
| preflight warns about swap, or the kubelet will not start | Swap 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 1 | IP forwarding off | Set net.ipv4.ip_forward = 1 and run sysctl --system |
| Control plane Pods keep restarting after init | Kubelet and runtime cgroup drivers differ | Set SystemdCgroup = true in containerd, restart it |
| Node NotReady, CoreDNS Pending | No CNI installed | Install one Pod network add-on |
| join: token not found or expired | Token past its TTL | kubeadm token create --print-join-command |
| control plane join cannot find certs | kubeadm-certs Secret expired | kubeadm 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
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)