Prepare a Debian Node for Kubernetes

In progress Kubernetes Linux

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

Steps

  1. 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."
    
  2. Copy and run it on each node. -t gives the remote side a terminal, so sudo can 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/swaps lists only its header and free -h shows 0B of swap, also after a reboot. (Over plain SSH, swapon may be "not found": it lives in /usr/sbin.)
  • systemctl is-active containerd prints active.
  • sudo containerd config dump | grep SystemdCgroup shows true for every runtime.
  • kubeadm version matches on every node.

Troubleshooting

  • WARNING: terminal is not fully functional on systemctl status: export TERM=xterm-256color (see Linux CLI Cheat Sheet).
  • apt-get update rejects 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, check K8S_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.
  • kubeadm pre-flight complains about conntrack or ethtool: they're installed in the first step; re-run the script.
  • grep SystemdCgroup finds nothing and config.toml is only a few lines long: it's Debian's stub, not the full default. Regenerate with containerd 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