<p>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?</p>

<p>The <a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#before-you-begin" rel="nofollow noreferrer">official Kubernetes prerequisites</a> says that:</p>
<blockquote>
<p>Swap disabled. You MUST disable swap in order for the kubelet to work
properly.</p>
</blockquote>
<p>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.</p>
<p>However there is a way to disable swap while installing <code>kubeadm</code>:</p>
<ul>
<li>Create a file in <code>/etc/systemd/system/kubelet.service.d/20-allow-swap.conf</code> with the following content:</li>
</ul>
<p><code>[Service] Environment=&quot;KUBELET_EXTRA_ARGS=--fail-swap-on=false&quot;</code></p>
<ul>
<li>Execute:</li>
</ul>
<p><code>sudo systemctl daemon-reload</code></p>
<ul>
<li>Run <code>kubeadm</code> with flag <code>--ignore-preflight-errors=Swap</code>:</li>
</ul>
<p><code>kubeadm init --ignore-preflight-errors=Swap</code></p>
<p>Bear in mind however that it is not a recommended way.</p>
