返回综合榜
云计算与基础设施Kubernetes Blog

利用节点 Swap 扩展 Kubernetes 工作负载

Kubernetes 官方博客发布了基准测试,表明在 v1.34 中已正式可用(GA)的节点 Swap 功能,在由高速 NVMe 本地 SSD 支撑时,可以显著提升 Pod 密度。作者在三种工作负载上测得最高 3 倍的密度提升,且延迟代价通常很小或几乎没有。

在 Linux 内核 CI 构建中,Swap 将容器内存限制降低了 50%(从 600 MB 降到 300 MB)且没有性能损失,但进一步压缩到 200 MB 会使执行时间增加 40% 以上。对于无头 Chrome 沙箱,gVisor Pod 从每节点 80 个提升到 160 个,Kata Containers 微虚拟机从 40 个提升到 50 个,普通 runc 容器则从 512 个提升到 768 个。在分析 MovieLens 20M 数据集的隔离 Python 沙箱场景中,并发会话从 80 个增长到 240 个。在峰值密度下,延迟增加主要来自 CPU 争用而非 Swap I/O。

过去 Kubernetes 不推荐使用 Swap,原因是 cgroup v1 无法单独统计 Swap,且向机械硬盘换页速度慢。新特性依赖 cgroup v2 的独立 Swap 统计,而 NVMe 的低延迟使 Swap 可以作为内存尖峰的缓冲,而非活跃内存的替代品。

使用方法是在 KubeletConfiguration 中设置 failSwapOn 为 false,并将 memorySwap.swapBehavior 设为 LimitedSwap,同时搭配云厂商的高速本地磁盘(例如 GKE 在 Local SSD 配置上的 Node Memory Swap),并让工作负载采用内存限制高于请求的 Burstable QoS。作者认为该方案尤其适合需要大内存占用但长时间空闲的智能体 AI 工作负载。

Scaling Kubernetes Workloads with Node Swap

Kubernetes has published benchmarks showing that node swap, which reached General Availability in v1.34, can substantially raise pod density when backed by fast NVMe Local SSDs. Across three workloads the authors measured density gains of up to 3x, often with little or no latency cost.

In a Linux kernel CI build, swap cut the container memory limit by 50% (600 MB to 300 MB) with no slowdown, though pushing to 200 MB increased execution time by over 40%. For headless Chrome sandboxes, swap raised gVisor pods from 80 to 160 and Kata Containers microVMs from 40 to 50 per node, while plain runc went from 512 to 768 pods. For isolated Python sandboxes analyzing the MovieLens 20M dataset, capacity grew from 80 to 240 concurrent sessions. At peak density the added latency comes mainly from CPU contention rather than swap I/O.

Historically swap was discouraged in Kubernetes because cgroup v1 could not account for swap separately and paging to spinning disks was slow. The new support relies on cgroup v2's independent swap accounting, and NVMe latency is low enough that swap can act as a shock absorber for memory spikes rather than a replacement for active RAM.

To use it, set failSwapOn to false and memorySwap.swapBehavior to LimitedSwap in the KubeletConfiguration, pair it with a cloud provider's fast local disk (for example GKE Node Memory Swap on Local SSD profiles), and run workloads with Burstable QoS where memory limits exceed requests. The authors position this as especially useful for agentic AI workloads that need large memory footprints but sit idle for long periods.

Kubernetesnode swappod densityNVMe SSDagentic AIbenchmarkcgroup v2gVisor
综合8
质量91
猎物热度0
时效0
信息来源1 个来源,主来源:Kubernetes Blog

猎鹰不保存原文正文。标题与摘要用于快速发现信息,事实细节请以来源原文为准。

查看来源