Kubernetes Memory Issue Due to No Swap - CloudCommandos/JohnChan GitHub Wiki
Issue:
By default, Kubelet requires swap to be disabled. This will result in fatal errors when the VM is running other services whose RAM usage are not restricted. This may result in memory shortage that forces the VM to reboot.
Solution:
If your K8s cluster is setup using kubeadm, create the file /etc/default/kubelet
with the content:
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
Or if the above method is deprecated, edit /var/lib/kubelet/config.yaml
's failSwapOn option:
...
failSwapOn: false
...
If your K8s cluster is setup using your own bootstrapping method, put the --fail-swap-on=false
flag as part of the config in the /etc/systemd/system/kubelet.service
file as such:
cat <<EOF | tee kubelet.service
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/kubernetes/kubernetes
After=containerd.service
Requires=containerd.service
[Service]
ExecStart=/usr/local/bin/kubelet \\
--config=/var/lib/kubelet/kubelet-config.yaml \\
--container-runtime=remote \\
--container-runtime-endpoint=unix:///var/run/containerd/containerd.sock \\
--image-pull-progress-deadline=2m \\
--kubeconfig=/var/lib/kubelet/kubeconfig \\
--network-plugin=cni \\
--register-node=true \\
--fail-swap-on=false \\
--v=2
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
Also enable swap on boot-up by editing `/etc/fstab' accordingly. This is not covered here.
Then restart kubelet:
systemctl daemon-reload
systemctl restart kubelet.service