Lesson 129 · Section 10: Cluster Installation & High Availability
Lesson 129: Prepare nodes for kubeadm: from a bare Linux machine to a ready node
Everything a machine needs before kubeadm can use it: the hardware and network checks, swap, IP forwarding, containerd with the systemd cgroup driver, and the kubelet, kubeadm and kubectl packages from pkgs.k8s.io, plus how to read the preflight errors when a step is missing. · 20 min read · 3 min video
Official competencies this lesson covers
Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.
Why it exists
kubeadm init and kubeadm join take a minute when the machine is ready, and fail in confusing ways when it is
not. kubeadm does not install a container runtime, does not change kernel settings, and does not install itself.
Every node, control plane or worker, goes through the same preparation first.
Parts:
- Linux machine (2 CPU, 2 GB, network)
- Kernel settings (no swap, ip_forward=1)
- containerd (systemd cgroups)
- kubelet, kubeadm (kubectl, held)
- kubeadm preflight (checks all of it)
Connections:
- Linux machine to Kernel settings: then
- Kernel settings to containerd: then
- containerd to kubelet, kubeadm: then
- kubelet, kubeadm to kubeadm preflight: runs
The commands in this lesson are for Ubuntu or Debian with apt, the system used in the exam. On RHEL-like systems
the steps are the same, with dnf and a .repo file instead.
What it is: the checklist
| Requirement | Why | How to check |
|---|---|---|
| 2 CPUs, 2 GB RAM (control plane) | The control plane Pods need it; preflight stops below this | nproc, free -h |
| Full network between all machines | Nodes, API server and etcd talk to each other | ping, nc -zv <ip> 6443 |
Unique hostname, MAC address and product_uuid | Node names and some CNI plugins rely on them; cloned VMs often share them | hostname, ip link, sudo cat /sys/class/dmi/id/product_uuid |
| Required ports open | 6443, 2379-2380, 10250, 10257, 10259 on control planes; 10250 and NodePorts on workers | nc -zv, firewall rules |
| Swap off (or the kubelet configured for it) | The kubelet refuses to start with swap on, by default | swapon --show prints nothing |
net.ipv4.ip_forward = 1 | Pod traffic is routed through the node | sysctl net.ipv4.ip_forward |
| A CRI runtime, running | The kubelet starts every container through it | sudo crictl info |
| Same cgroup driver in kubelet and runtime | Two cgroup managers make nodes unstable | grep SystemdCgroup /etc/containerd/config.toml |
kubelet, kubeadm, kubectl packages | kubeadm builds the cluster; the kubelet runs it | kubeadm version, kubelet --version |
How it works
Swap
The kubelet's scheduling decisions assume that memory requests are real memory. Swap breaks that assumption, so
the kubelet's default failSwapOn: true makes it refuse to start when swap is enabled. You can configure the
kubelet to tolerate swap (failSwapOn: false, and a memorySwap.swapBehavior), but the simple and usual answer is
to turn swap off:
sudo swapoff -a # now
sudo sed -i '/ swap / s/^/#/' /etc/fstab # after a reboot too
If you miss this, kubeadm init does not fail at once: the kubelet keeps crashing and kubeadm eventually gives up
waiting for the control plane, which is a much harder message to read.
IP forwarding
A Pod's packets leave through a virtual interface and are routed by the node's kernel onto the real network. Linux does not forward packets between interfaces by default:
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
EOF
sudo sysctl --system
The file makes it permanent; sysctl --system applies it now. kubeadm's preflight reads
/proc/sys/net/ipv4/ip_forward and stops if it is not 1.
The container runtime and its cgroup driver
Parts:
- systemd (init system)
- kubelet (cgroupDriver)
- containerd (SystemdCgroup)
- cgroup tree (/sys/fs/cgroup)
Connections:
- kubelet to systemd: systemd
- containerd to systemd: systemd
- systemd to cgroup tree: manages
Linux control groups (cgroups) limit and count each container's CPU and memory. On a machine started by systemd,
systemd already owns the cgroup tree. The kubelet defaults to the systemd cgroup driver (kubeadm writes
cgroupDriver: systemd into its configuration), so the runtime must use the same driver. If containerd uses
cgroupfs while the kubelet uses systemd, the node can look fine and then become unstable under memory
pressure, with Pods restarting for no visible reason.
In containerd the setting lives under the runc runtime's options in /etc/containerd/config.toml. The section
name differs between containerd versions, which is why the reliable recipe is to generate the default file and
flip the one value:
# containerd 2.x
[plugins.'io.containerd.cri.v1.runtime'.containerd.runtimes.runc.options]
SystemdCgroup = true
# containerd 1.x
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
CRI-O uses the systemd driver by default, so it needs no change.
Under the hood · Why a socket, and what crictl is for
The kubelet does not link to containerd; it speaks the CRI gRPC API over a Unix socket, by default
/var/run/containerd/containerd.sock for containerd and /var/run/crio/crio.sock for CRI-O. kubeadm finds the
socket by looking for the known paths; when a machine has more than one runtime, you choose with
--cri-socket unix:///var/run/containerd/containerd.sock.
crictl is the CRI client for humans. It talks to the same socket the kubelet uses, so sudo crictl info and
sudo crictl ps prove that the runtime works the way the kubelet will see it. The cri-tools package that provides
it is installed as a dependency of kubeadm. If it complains about the endpoint, set it once:
sudo crictl config --set runtime-endpoint=unix:///var/run/containerd/containerd.sock
The packages
Parts:
- Signing key (/etc/apt/keyrings)
- Repository line (core:/stable:/v1.37)
- apt-get install (kubelet kubeadm kubectl)
- apt-mark hold (no surprise upgrades)
- kubelet enabled (restarts until init)
Connections:
- Signing key to Repository line: trusts
- Repository line to apt-get install: serves
- apt-get install to apt-mark hold: then
- apt-mark hold to kubelet enabled: then
The Kubernetes community packages live at pkgs.k8s.io, with one repository per minor version: a machine set up
for v1.37 sees only v1.37.x packages. That is a feature, because it stops an apt-get upgrade from jumping minor
versions. On top of it, the packages are held so that even patch upgrades happen only when you choose.
After the install the kubelet is enabled and starts, but it has no configuration yet. It exits, systemd restarts it,
and this repeats every few seconds until kubeadm init or kubeadm join writes /var/lib/kubelet/config.yaml.
That loop is expected.
Using it
Example · 1. Kernel settings
On every node:
sudo swapoff -a
sudo sed -i '/ swap / s/^/#/' /etc/fstab
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
EOF
sudo sysctl --system
swapon --show # prints nothing
sysctl net.ipv4.ip_forward # net.ipv4.ip_forward = 1
Example · 2. containerd with the systemd cgroup driver
Ubuntu's own containerd package is enough for a lab; Docker's containerd.io package works the same way.
sudo apt-get update
sudo apt-get install -y containerd
sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml > /dev/null
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
sudo systemctl restart containerd
sudo systemctl enable containerd
grep SystemdCgroup /etc/containerd/config.toml
SystemdCgroup = true
If grep prints nothing, your containerd version left the option out of its default file: add
SystemdCgroup = true under the runc options section shown above, then restart containerd.
Example · 3. kubelet, kubeadm and kubectl from pkgs.k8s.io
These lines are on the docs page "Installing kubeadm"; only the version in the URL changes.
sudo apt-get install -y apt-transport-https ca-certificates curl gpg
sudo mkdir -p -m 755 /etc/apt/keyrings
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
sudo systemctl enable --now kubelet
To install an exact patch version, for example to match an existing cluster, list and pin it:
apt-cache madison kubeadm | head -n 3
sudo apt-get install -y kubelet='1.37.0-*' kubeadm='1.37.0-*' kubectl='1.37.0-*'
Check:
kubeadm version -o short # v1.37.0
kubelet --version # Kubernetes v1.37.0
systemctl status kubelet # activating (auto-restart): expected before kubeadm init
Example · 4. Let preflight check everything
kubeadm init phase preflight runs only the checks, changes nothing, and lists every problem at once:
sudo kubeadm init phase preflight
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR NumCPU]: the number of available CPUs 1 is less than the required 2
[ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1
Fix each line and run it again until it is quiet. You can also pull the control plane images in advance, which
makes kubeadm init itself faster:
sudo kubeadm config images pull
On a worker, sudo kubeadm join phase preflight does the same; it needs the join arguments, so in practice you
just run the join.
When preflight complains
| Error | Cause | Fix |
|---|---|---|
[ERROR NumCPU]: the number of available CPUs 1 is less than the required 2 | Small VM | Give it 2 CPUs (or, in a throwaway lab only, --ignore-preflight-errors=NumCPU) |
[ERROR Mem]: the system RAM (...) is less than the minimum 1700 MB | Small VM | More memory |
[ERROR FileContent--proc-sys-net-ipv4-ip_forward] | IP forwarding off | The sysctl file, then sysctl --system |
[ERROR CRI]: container runtime is not running | containerd stopped, or a wrong socket | systemctl status containerd, sudo crictl info |
[ERROR Port-6443]: Port 6443 is in use | A previous attempt is still running | sudo kubeadm reset, then try again |
[ERROR FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml] | Leftovers from an earlier init | sudo kubeadm reset |
kubeadm init hangs at [wait-control-plane] and times out | kubelet not running: swap on, or a cgroup driver mismatch | journalctl -u kubelet -n 50, then fix swap or SystemdCgroup |
Tricks
Common mistakes
- Turning swap off with
swapoff -aonly. It comes back at the next reboot, and the kubelet stops. Comment out the swap line in/etc/fstabtoo. - Leaving containerd on the cgroupfs driver. Nothing fails at first; nodes become unstable later.
- Editing
config.tomlbut not restarting containerd. The setting is read at start. - Mixing minor versions between nodes. Install the same
kubeadmandkubeletversion on every node; pin it with='1.37.0-*'when joining an existing cluster. - Forgetting
apt-mark hold. An unattended upgrade then replaces the kubelet in the middle of the week. - Running preflight-skipping flags by habit.
--ignore-preflight-errors=allturns a clear error into a broken cluster. Skip only a check you understand.
Recap
- Every node: 2 CPUs and 2 GB (control plane), unique names, open ports.
- Swap off, permanently;
net.ipv4.ip_forward = 1in/etc/sysctl.d/. - containerd with
SystemdCgroup = true, restarted; check withcrictl info. kubelet,kubeadm,kubectlfrom thepkgs.k8s.iorepository of one minor version, thenapt-mark hold.- The kubelet restarts in a loop until
kubeadm initorjoin;kubeadm init phase preflightchecks it all.
Official docs
Quiz: check what you learned
5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.
Sign in to take the quiz and keep your score.
Practise: try it on a real cluster
A hands-on lab for this lesson. You get goals, not steps: any solution that reaches them passes.
Two new machines have containerd, kubelet and kubeadm and nothing else. Build a cluster on them with kubeadm init and join, give it a pod network, and set up kubectl for your own user.
Build · Level 2 · standard · target 25 min
Discussion
Learners ask and answer questions here. Sign in to read and join the discussion.