Kubernetes Blog
Follow
Scaling Kubernetes Workloads with Node Swap
Kubernetes clusters often face memory limitations before CPU constraints, a problem exacerbated by new agentic AI workloads. These AI workloads require significant memory to initiate and run untrusted code, then remain idle. This idle memory is costly and limits the number of pods a node can host. Swap memory, especially when backed by fast NVMe SSDs, can address this by paging out dormant memory. Kubernetes support for swap, now generally available, allows nodes to host more pods. Benchmarking across CI/CD builds, sandboxed browsers, and Python runtimes demonstrated density gains of up to three times with minimal latency impact. Historically, swap was avoided due to memory accounting issues and slow disk latencies. However, cgroup v2 and fast NVMe SSDs resolve these concerns, making swap a viable solution. Traditional workloads like kernel builds can tolerate reduced memory limits when swap is enabled. High-density agent workloads, such as headless browsers, see significant pod density increases with swap. Sandboxed Python runtimes also benefit from swap, enabling three times more concurrent sessions. Enabling node swap involves configuring the kubelet and using cloud provider local disks. Workloads with Burstable QoS can leverage swap for dynamic memory balancing. Ultimately, fast swap offloads idle memory states, increasing pod density and node utilization for agentic workloads.