Controlled Swap Support for Kubernetes Nodes

Read time: 3 minutes
Abhimanyu Saharan
Abhimanyu Saharan

Kubernetes has historically disabled swap memory usage on nodes due to the unpredictability and performance degradation it can cause. But with increasing real-world needs for more flexible memory allocation, especially on constrained or specialized environments, the Kubernetes community has introduced node swap support as a gated, structured feature, now steadily progressing toward GA in Kubernetes v1.32.

This enhancement, defined in KEP-2400, lays the groundwork for controlled swap usage by Kubernetes workloads, starting with Burstable QoS pods only, using the LimitedSwap mode. This approach limits risks by excluding high-priority workloads and reserving swap access for workloads that can safely tolerate it.

Why Swap Support?

Use cases include:

  • Edge deployments and low-memory nodes where provisioning large amounts of RAM isn't feasible
  • Local development clusters with NVMe or SSD-backed swap for quick disk I/O
  • Memory-flexible applications (like Java/Node.js) that benefit from swapping infrequently used memory
  • Virtualized clusters using KubeVirt or similar stacks where memory overcommitment is common

These benefits, however, must be balanced with swap's inherent risks—reduced performance, complexity in eviction behavior, and potential exposure of sensitive data if swap isn't encrypted.

How It Works

  1. Feature Gate:NodeSwap must be enabled.
  2. Kubelet Config:--fail-swap-on=false and MemorySwap.SwapBehavior=LimitedSwap
  3. Cgroup v2 Only: Support is implemented only for systems using cgroupsv2.
  4. Only Burstable Pods: Guaranteed pods do not use swap. BestEffort pods are not allocated swap either.
  5. Eviction Manager is Swap-Aware: It calculates accessible swap as additional memory capacity.
  6. Default Mode: Swap is disabled by default (NoSwap) until explicitly configured.

Calculating Swap Limits

Each container's swap is calculated proportionally:

  • swap_limit = (container_memory_request / total_node_memory) * (total_swap - system_reserved)

    This ensures fair allocation among containers, aligned with their memory requests.

    Best Practices

    • Disable swap for system daemons to prevent performance degradation.
    • Use io.latency settings to prioritize critical services.
    • Avoid enabling swap on control plane nodes.
    • Use encrypted, dedicated swap disks for better I/O isolation and security.

    Observability & Monitoring

    • Metrics such as container_swap_usage_bytes, pod_swap_usage_bytes, and node_swap_usage_bytes are available via /metrics/resource.
    • summary API exposes swapAvailableBytes and swapUsageBytes.

    Current Status & Roadmap

    • Beta 3 adds eviction integration, stress testing lanes, and improved docs.
    • GA planned in Kubernetes v1.32 will remove the feature gate and finalize metrics and behaviors.

    Caveats

    • Only available on Linux with cgroupsv2.
    • Memory-backed volumes like Secrets and tmpfs now have swap-protection logic.
    • Performance unpredictability remains a risk, swap is not a silver bullet for memory pressure.

    Conclusion

    Kubernetes' controlled embrace of swap is a deliberate, conservative step to increase flexibility for real-world workloads while protecting critical system processes. Through precise defaults, targeted QoS class support, and robust observability, node swap support paves the way for advanced memory management scenarios while retaining Kubernetes' core tenets of stability and predictability.

    Admins can now provision swap on worker nodes and allow Burstable pods to benefit, without compromising cluster reliability.

    FAQs

    What is the current status of swap support in Kubernetes?

    Swap support is now available in LimitedSwap mode for Burstable QoS pods on cgroups v2 systems. It is controlled via the NodeSwap feature gate and is progressing toward GA in Kubernetes v1.32. By default, swap remains disabled (NoSwap) until explicitly configured.

    How do you enable swap support on a Kubernetes node?

    To enable swap:

    • Set the kubelet flag: --fail-swap-on=false
    • Enable the feature gate: --feature-gates=NodeSwap=true
    • In the kubelet config, set: MemorySwap.SwapBehavior=LimitedSwap
      Note: This only works on Linux systems using cgroups v2.
    Which pods are eligible to use swap under this configuration?

    Only Burstable QoS pods can use swap.

    • Guaranteed pods are excluded from swap usage.
    • BestEffort pods are not allocated swap either.
    What are the use cases for enabling swap in Kubernetes?

    Swap is beneficial for:

    • Edge or low-memory nodes where physical RAM is limited
    • Local development clusters using fast swap-backed storage
    • Memory-flexible apps like Java or Node.js
    • Virtualized workloads that require memory overcommit (e.g., via KubeVirt)
    What should cluster operators consider before enabling swap?
    • Use encrypted, dedicated swap devices
    • Avoid enabling swap on control plane nodes
    • Prevent system daemons from using swap
    • Monitor swap metrics (container_swap_usage_bytes, etc.)
    • Recognize that swap may introduce performance variability and should not replace proper memory provisioning

    Read Next

    Trending Posts

    Featured Posts

    Like what you read? Support my work so I can keep writing more for you.

    Subscribe to Newsletter
    Free

    Get new posts, tools, and tips delivered straight to your inbox.

    Subscribe on YouTube
    Free

    Follow along with walkthroughs and tutorials, especially on Rancher and DevOps topics.

    Supporter
    $1/month

    A small act of support goes a long way. You're helping me stay consistent and keep the content flowing.

    Learn. Build. Ship. Together

    40+
    Technical blog posts
    8+ years
    Industry experience in DevOps & Infra
    100+
    YouTube subscribers
    1500+
    Developers on the newsletter