Error while executing and initializing kubeadm

Some Kubernetes Deployments Need Swap

Generally speaking, the official requirement is to disable swap.

Reason? not yet supported by kubernetes. IMO they ask you to disable swap to prevent issues with multi-node cluster workload shifting.

However, I have a valid use case - I'm developing an on-prem product, linux distro, included with kubeadm. no horizontal scaling by design. To survive opportunistic memory peaks and still function (but slow), I definitely need swap.


To install kubeadm with swap enabled:

  1. Create a file in /etc/systemd/system/kubelet.service.d/20-allow-swap.conf with the content:

    [Service]
    Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false"
    
  2. Run

    sudo systemctl daemon-reload
    
  3. Initialize kubeadm with flag --ignore-preflight-errors=Swap

    kubeadm init --ignore-preflight-errors=Swap
    

just disable the swap in the machine. sudo swapoff -a


sudo swapoff -a is not persistent across reboot.

You may disable swap after reboot by just commenting out (add # in front of the line) the swap entry in /etc/fstab file. It will prevent swap partition from automatically mounting after a reboot.

Steps:

  1. Open the file /etc/fstab

  2. Look for a line below

    # swap was on /dev/sda5 during installation

    UUID=e7bf7d6e-e90d-4a96-91db-7d5f282f9363 none swap sw 0 0

  3. Comment out above line with # and save it. It should look like below

    # swap was on /dev/sda5 during installation

    #UUID=e7bf7d6e-e90d-4a96-91db-7d5f282f9363 none swap sw 0 0

  4. Reboot the system or for current session execute "sudo swapoff -a" to avoid reboot.