Prepare a Debian Node for Kubernetes
Goal
A Debian machine ready for kubeadm init (control plane) or kubeadm join (worker): swap off, kernel networking configured, containerd with the systemd cgroup driver, and pinned Kubernetes packages. Every node gets the same preparation, run as one re-runnable script.
Prerequisites
- Debian with
sudo(a minimal install may lack it: see Troubleshooting Missing Sudo Command on Minimal Debian 13 Installations). - SSH key access and a static IP (see Set Up SSH Key Authentication and Set a Static IP Address on Debian with ifupdown).
- The Kubernetes minor version to install (here
v1.36; use a version still in support, the same on every node: see pkgs.k8s.io Has One Repository per Minor Version, So the Repository URL Is the Version Pin).
Steps
- Save the script as
prep-node.sh:#!/usr/bin/env bash set -euo pipefail K8S_MINOR="v1.36" # Tools kubeadm's pre-flight checks need, and hardware inventory sudo apt-get update sudo apt-get install -y conntrack ethtool socat apt-transport-https \ ca-certificates curl gpg lshw inxi # 1. Swap off now and after reboots (comment the fstab line, reversible) sudo swapoff -a sudo sed -i '/\sswap\s/ s/^#*/#/' /etc/fstab sudo systemctl mask swap.target # stops systemd re-activating swap it finds itself # 2. Kernel modules and forwarding for container networking printf 'overlay\nbr_netfilter\n' | sudo tee /etc/modules-load.d/k8s.conf sudo modprobe overlay sudo modprobe br_netfilter printf 'net.bridge.bridge-nf-call-iptables = 1\nnet.bridge.bridge-nf-call-ip6tables = 1\nnet.ipv4.ip_forward = 1\n' \ | sudo tee /etc/sysctl.d/k8s.conf sudo sysctl --system # 3. containerd with the systemd cgroup driver # Always write the full default: Debian's package ships a short stub without SystemdCgroup 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 # 4. Kubernetes repository and pinned packages sudo mkdir -p -m 755 /etc/apt/keyrings curl -fsSL "https://pkgs.k8s.io/core:/stable:/${K8S_MINOR}/deb/Release.key" \ | sudo gpg --yes --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:/${K8S_MINOR}/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 echo "Node ready for kubeadm init or join." - Copy and run it on each node.
-tgives the remote side a terminal, sosudocan prompt for a password (sudo refuses passwords piped in without one):scp prep-node.sh user@NODE_IP:~ ssh -t user@NODE_IP "chmod +x ~/prep-node.sh && ~/prep-node.sh"
Verify
-
cat /proc/swapslists only its header andfree -hshows0Bof swap, also after a reboot. (Over plain SSH,swaponmay be "not found": it lives in/usr/sbin.) -
systemctl is-active containerdprintsactive. -
sudo containerd config dump | grep SystemdCgroupshowstruefor every runtime. -
kubeadm versionmatches on every node.
Troubleshooting
WARNING: terminal is not fully functionalonsystemctl status:export TERM=xterm-256color(see Linux CLI Cheat Sheet).apt-get updaterejects the Kubernetes repository signature on Debian 13 (Signature Packet v3 is not considered secure): resolved for v1.36 since November 2026, with no workaround needed. If you see it, checkK8S_MINOR: an older minor's repository may still fail. Don't relax the signature policy; the history is in A Time-Boxed Security Exception: Kubernetes apt Signatures on Debian 13.kubeadmpre-flight complains aboutconntrackorethtool: they're installed in the first step; re-run the script.grep SystemdCgroupfinds nothing andconfig.tomlis only a few lines long: it's Debian's stub, not the full default. Regenerate withcontainerd config default, set the flag, restart containerd (see Debian's containerd Package Ships a Config Stub Without SystemdCgroup).- Swap is back after a reboot: systemd activated a swap partition on its own.
sudo systemctl mask swap.target.
References
- Kubernetes documentation: Installing kubeadm - packages, repository and swap requirements.
- Kubernetes documentation: Container Runtimes - kernel modules, sysctls and the systemd cgroup driver.
- kubelet Depends on containerd Through the CRI Socket - why
SystemdCgroupand the restart matter. - Debian's containerd Package Ships a Config Stub Without SystemdCgroup - the Debian-specific trap in step 3.
- pkgs.k8s.io Has One Repository per Minor Version, So the Repository URL Is the Version Pin - choosing
K8S_MINOR. - Kubernetes MOC - hub for Kubernetes notes.