kubernetesmemory

How to add swap memory in kubernetes pods?


I need to add swap memory in kubernates pod. so that if any pods exceeds the available RAM then it can use the swap memory from hard disk. is that possible in kubernates?


Solution

  • The official Kubernetes prerequisites says that:

    Swap disabled. You MUST disable swap in order for the kubelet to work properly.

    You are supposed to use cpu/memory limits for deployments. Kubelet is not designed to handle swap situations. If memory swapping is allowed to occur on a host system, it can lead to performance and stability issues within Kubernetes.

    However there is a way to disable swap while installing kubeadm:

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

    sudo systemctl daemon-reload

    kubeadm init --ignore-preflight-errors=Swap

    Bear in mind however that it is not a recommended way.