6 min read
Kubernetes node swap is a workload policy, not a sizing strategy
Swap changes the failure mode
Swap is tempting when a node runs out of physical memory: move less-active pages to disk and avoid killing a process immediately. That can be a useful trade. It is not extra memory with the same performance characteristics. If an application needs pages that have been swapped out, it has to wait for them to come back. A workload that stays alive may therefore become slow in a way that is harder to predict than a clear limit breach.
That distinction is the point of the Kubernetes blog post on scaling workloads with node swap. It discusses swap in the context of growing memory demands from agentic workloads and describes using fast local storage for dormant agent state. I would treat that as a workload-specific option, not a general argument to raise node density. The useful question is not simply whether swap prevents an out-of-memory event. It is whether the application remains useful while some of its memory is slower to access.
A memory limit and swap also express different operational expectations. Kubernetes documents that container memory limits are enforced reactively by the kernel, which may terminate a container when memory pressure is detected. Swap can change what happens before a process is killed, but it does not make a workload’s memory use smaller or guarantee acceptable response times. The Kubernetes resource-management documentation is clear about the reactive nature of memory limits; my architectural concern is that adding swap can make the path to failure less obvious without removing the underlying pressure.
So I would not describe swap as “more capacity.” I would describe it as permission for selected workloads to trade some memory-pressure failures for a risk of degraded, potentially erratic performance. That trade belongs in the workload’s policy and service expectations.
Choose workloads by their tolerance for delay
I would start with workloads whose usefulness does not depend on consistently fast access to every resident page. Background jobs that can slow down and catch up later may be candidates. So might a workload with genuinely dormant state that can tolerate a pause when that state becomes active again. Those are hypotheses to test, not categories I would enable by default.
I would be much more cautious with latency-sensitive request paths, interactive applications, and stateful services where a pause affects other work or violates a response-time expectation. For these workloads, a process that is technically alive but intermittently stalled may be worse than a restart or a clear failure. I would also ask what happens when several containers on the same node need their swapped-out memory at once. A policy that seems acceptable for one quiet process may create contention when the node is busy.
Kubernetes exposes swap behavior through kubelet configuration. The current Kubernetes swap-behavior documentation describes NoSwap as the default for Pod workloads and LimitedSwap as allowing them to use swap. An illustrative configuration fragment is:
failSwapOn: false
memorySwap:
swapBehavior: LimitedSwap
This shows the policy choice; it is not a complete deployment recipe. I would check the documentation for the Kubernetes and node configuration in use before applying it. More importantly, I would not enable LimitedSwap across a mixed-purpose node pool just because one background workload could benefit. If two workloads have different tolerance for stalls, they should not inherit the same swap policy by accident.
Observe the behavior, not just the setting
A successful rollout is not proof that swap is harmless. I would define what trouble looks like before testing: rising request latency, longer job completion times, growing swap use, memory pressure, restarts, or evictions. The Kubernetes swap-management documentation describes observing swap use at node and container level. I would pair those signals with the application’s own measures of useful work and responsiveness; node-level numbers alone cannot tell me whether the workload is still meeting its purpose.
I would also keep the failure signals visible. The Kubernetes node-pressure eviction documentation describes how kubelet uses resource signals and thresholds when deciding whether to evict Pods. Swap does not make those mechanisms irrelevant. A pilot should watch whether pressure is being postponed, whether the node is still reclaiming or evicting workloads, and which Pods are affected. If users see slower responses before the platform reports an obvious failure, that is important evidence—not a reason to declare the test successful because the process survived.
For a pilot, I would use an isolated node pool and a workload with a clear owner and a measurable tolerance for delay. I would compare the same workload with swap unavailable and with the proposed policy, under representative load and memory pressure. I would set stop conditions in advance: for example, revert if the workload breaches its own latency or completion-time objective, or if swap activity coincides with pressure or instability elsewhere on the node. I would avoid packing unrelated workloads onto the test nodes, because that makes it harder to tell whether the outcome belongs to the candidate workload or its neighbors.
The point of the comparison is not to prove that swap can keep more Pods running. It is to learn whether the workload delivers acceptable service while using it, and what the node and its other workloads experience in the process. If the test only records fewer restarts, it has measured survival, not success.
Keep capacity planning honest
Swap can make apparent headroom look larger, but scheduled memory requests and actual working-set needs still matter. I would not lower requests, raise density, or defer node sizing on the strength of swap space alone. Those changes can let the scheduler place more work on a node without making the physical-memory constraint disappear. The result may be a cluster that accepts more workload and then pays for it in unpredictable latency.
My default would remain NoSwap for general-purpose nodes. I would opt into LimitedSwap only for workloads whose owners accept the performance trade, whose behavior I can observe, and whose placement is separated enough to contain the experiment. If the workload needs prompt access to its memory to meet its service expectation, I would size memory for that need rather than use swap to disguise a shortfall.
That is why I see node swap as a workload policy. It can soften one kind of failure, but the cost is a less deterministic path under pressure. A careful pilot can establish whether that cost is acceptable; it cannot turn the extra apparent capacity into free capacity.
Drafted with AI assistance, reviewed and edited by Ali.