Issue#

After a reboot, a node shows NotReady, or kubeadm init/kubeadm join fails. The kubelet keeps restarting, and its logs show this error:

journalctl -u kubelet -n 20 --no-pager
"command failed" err="failed to run Kubelet: running with swap on is not supported, please disable swap or set --fail-swap-on flag to false"

Cause#

By default the kubelet runs with failSwapOn: true. It will not start if any swap device is active. Running swapoff -a fixes it only until the next reboot. After that, swap comes back from one of these sources:

  • an entry in /etc/fstab
  • a systemd .swap unit, which systemd generates automatically from the GPT swap partition type
  • zram, which is enabled by default on some distributions

Solution#

  1. Check which swap devices are active:
swapon --show
  1. Turn off swap immediately:
sudo swapoff -a
  1. Comment out the swap entries in /etc/fstab so they don't come back on boot. The .bak suffix keeps a backup copy:
sudo sed -i.bak '/\sswap\s/ s/^\([^#]\)/#\1/' /etc/fstab grep swap /etc/fstab
  1. List the swap units that systemd manages, then mask any that are still active. Use the unit names from your own output:
systemctl --type swap --all sudo systemctl mask dev-sda3.swap
  1. If swap comes from zram, disable that too. Use whichever command matches your setup:
# systemd zram-generator (Fedora, Ubuntu 24.04+ with zram) sudo systemctl mask systemd-zram-setup@zram0.service # Debian/Ubuntu zram-tools sudo systemctl disable --now zramswap.service
  1. Restart the kubelet:
sudo systemctl restart kubelet

Tip: If you need to keep swap, recent Kubernetes versions on cgroup v2 support it through the NodeSwap feature. Add the settings below to /var/lib/kubelet/config.yaml and restart the kubelet. With LimitedSwap, only Burstable pods can use swap.

failSwapOn: false memorySwap: swapBehavior: LimitedSwap

Verify#

Confirm that no swap is active. The first command should print nothing, and the Swap: line should show 0B:

swapon --show free -h | grep -i swap

Confirm that the kubelet is running and the node is Ready:

systemctl is-active kubelet kubectl get nodes

Reboot the node once and run swapon --show again. If it still prints nothing, the fix is permanent.