Why Swap on Kubernetes Isn't the Same as Swap on Linux-and What You Should Do Instead
Briefly

When dealing with memory management, Kubernetes functions differently than traditional Linux systems. Enabling swap in Kubernetes does not effectively mitigate OOMKills and evictions due to strict enforcement of cgroup limits. Instead, when a Kubernetes node is under memory pressure, the kubelet will begin to evict pods based on their Quality of Service (QoS) class, and these decisions are reliant on available memory as calculated from cgroupfs, not the availability of swap space. Effective management strategies need to adapt to these constraints to prevent instability and additional costs.
In Kubernetes, enabling swap doesn't solve OOMKills or pod evictions because cgroup limits are strictly enforced, making traditional solutions ineffective.
Kubernetes prioritizes predictable scheduling and behavior, which is why swap is disabled by default. Enabling it can still result in pods being OOMKilled.
When a node exceeds memory limits, Kubernetes evicts pods based on QoS class, focusing on memory available rather than swap. This leads to unexpected evictions.
Memory.available is derived from cgroupfs in Kubernetes for accurate accounting; therefore, swap usage doesn't influence how Kubernetes manages memory pressure.
Read at Medium
[
|
]