Skip to content

Commit ba07b03

Browse files
committed
Improve swap management concept
- Mention Linux swap behavior - Mention Windows swap behavior - Hyperlink to the tutorial for setup advice
1 parent af80bbb commit ba07b03

File tree

4 files changed

+76
-47
lines changed

4 files changed

+76
-47
lines changed

content/en/docs/concepts/cluster-administration/swap-memory-management.md

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,17 @@ It also helps prevent Pods from being terminated during memory pressure spikes,
1515
shields nodes from system-level memory spikes that might compromise its stability,
1616
allows for more flexible memory management on the node, and much more.
1717

18-
<!-- body -->
19-
20-
## How to use it?
21-
22-
### Prerequisites
23-
24-
- Swap must be enabled and provisioned on the node.
25-
- The node must run a Linux operating system.
26-
- The node must use cgroup v2. Kubernetes does not support swap on cgroup v1 nodes.
18+
To learn about configuring swap in your cluster, read
19+
[Configuring swap memory on Kubernetes nodes](/docs/tutorials/cluster-management/provision-swap-memory/).
2720

28-
## Enabling swap for Kubernetes Workloads
29-
30-
To allow Kubernetes workloads to use swap,
31-
you must disable the kubelet's default behavior of failing when swap is detected,
32-
and specify memory-swap behavior as `LimitedSwap`:
33-
34-
**Update kubelet configuration:**
35-
```yaml
36-
# this fragment goes into the kubelet's configuration file
37-
failSwapOn: false
38-
memorySwap:
39-
swapBehavior: LimitedSwap
40-
```
41-
42-
The available choices for `swapBehavior` are:
43-
- `NoSwap` (default): Kubernetes workloads cannot use swap. However, processes
44-
outside of Kubernetes' scope, like system daemons (such as kubelet itself!) can utilize swap.
45-
This behavior is beneficial for protecting the node from system-level memory spikes,
46-
but it does not safeguard the workloads themselves from such spikes.
47-
- `LimitedSwap`: Kubernetes workloads can utilize swap memory.
48-
The amount of swap available to a Pod is determined automatically.
49-
For more details, see the [section below](#how-is-the-swap-limit-being-determined-with-limitedswap).
50-
51-
If configuration for `memorySwap` is not specified,
52-
by default the kubelet will apply the same behaviour as the `NoSwap` setting.
53-
54-
Bear in mind that the following pods would be excluded from swap access
55-
(see more info in the [section below](#how-is-the-swap-limit-being-determined-with-limitedswap)):
56-
- Pods that are not classified as Burstable QoS.
57-
- Pods of High-priority.
58-
- Containers with memory limit that equals to memory request.
21+
<!-- body -->
5922

60-
{{< note >}}
23+
## Operating system support
6124

62-
Kubernetes only supports swap for Linux nodes.
63-
64-
{{< /note >}}
25+
* Linux nodes support swap; you need to configure each node to enable it.
26+
By default, the kubelet will **not** start on a Linux node that has swap enabled.
27+
* Windows nodes require swap space.
28+
By default, the kubelet does **not** start on a Windows node that has swap disabled.
6529

6630
## How does it work?
6731

@@ -79,6 +43,31 @@ Swap configuration on a node is exposed to a cluster admin via the
7943
As a cluster administrator, you can specify the node's behaviour in the
8044
presence of swap memory by setting `memorySwap.swapBehavior`.
8145

46+
### Swap behaviors
47+
48+
You need to pick a [swap behavior](/docs/reference/node/swap-behavior/) to
49+
use. Different nodes in your cluster can use different swap behaviors.
50+
51+
The swap behaviors you can choose for Linux nodes are:
52+
53+
`NoSwap` (default)
54+
: Workloads running as Pods on this node do not and cannot use swap.
55+
56+
`LimitedSwap`
57+
: Kubernetes workloads can utilize swap memory.
58+
59+
{{< note >}}
60+
If you choose the NoSwap behavior, and you configure the kubelet to tolerate
61+
swap space (`failSwapOn: false`), then your workloads don't use any swap.
62+
63+
However, processes outside of Kubernetes-managed containers, such as systemi
64+
services (and even the kubelet itself!) **can** utilize swap.
65+
{{< /note >}}
66+
67+
You can read [configuring swap memory on Kubernetes nodes](/docs/tutorials/cluster-management/provision-swap-memory/) to learn about enabling swap for your cluster.
68+
69+
### Container runtime integration
70+
8271
The kubelet uses the container runtime API, and directs the container runtime to
8372
apply specific configuration (for example, in the cgroup v2 case, `memory.swap.max`) in a manner that will
8473
enable the desired swap configuration for a container. For runtimes that use control groups, or cgroups,
@@ -357,7 +346,7 @@ For modern performance needs, a device such as a Solid State Drive (SSD) is prob
357346
as its low-latency electronic access minimizes the slowdown.
358347

359348

360-
## Swap Behavior Details
349+
## Swap behavior details
361350

362351
### How is the swap limit being determined with LimitedSwap?
363352

@@ -398,6 +387,8 @@ Containers configured in this manner will not have access to swap memory.
398387

399388
## {{% heading "whatsnext" %}}
400389

390+
- To learn about managing swap on Linux nodes, read
391+
[configuring swap memory on Kubernetes nodes](/docs/tutorials/configuration/provision-swap-memory/).
401392
- You can check out a [blog post about Kubernetes and swap](/blog/2025/03/25/swap-linux-improvements/)
402-
- For more information, please see the original KEP, [KEP-2400](https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/2400-node-swap),
393+
- For background information, please see the original KEP, [KEP-2400](https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/2400-node-swap),
403394
and its [design](https://github.com/kubernetes/enhancements/blob/master/keps/sig-node/2400-node-swap/README.md).

content/en/docs/reference/node/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ This section contains the following reference topics about nodes:
1717

1818
* [Node `.status` information](/docs/reference/node/node-status/)
1919

20+
* [Linux Node Swap Behaviors](/docs/reference/node/swap-behavior/)
21+
2022
* [Seccomp information](/docs/reference/node/seccomp/)
2123

2224
You can also read node reference details from elsewhere in the
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
content_type: "reference"
3+
title: Linux Node Swap Behaviors
4+
weight: 110
5+
---
6+
7+
To allow Kubernetes workloads to use swap, on a Linux node,
8+
you must disable the kubelet's default behavior of failing when swap is detected,
9+
and specify memory-swap behavior as `LimitedSwap`:
10+
11+
The available choices for swap behavior are:
12+
13+
`NoSwap`
14+
: (default) Workloads running as Pods on this node do not and cannot use swap. However, processes
15+
outside of Kubernetes' scope, such as system daemons (including the kubelet itself!) **can** utilize swap.
16+
This behavior is beneficial for protecting the node from system-level memory spikes,
17+
but it does not safeguard the workloads themselves from such spikes.
18+
19+
`LimitedSwap`
20+
: Kubernetes workloads can utilize swap memory. The amount of swap available to a Pod is determined automatically.
21+
22+
To learn more, read [swap memory management](/docs/concepts/cluster-administration/swap-memory-management/).

content/en/docs/tutorials/cluster-management/provision-swap-memory.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,14 @@ In a similar way, using systemd allows your server to leave swap active until ku
119119

120120
### Set up kubelet configuration
121121

122-
After enabling swap on the node, kubelet needs to be configured in the following way:
122+
After enabling swap on the node, kubelet needs to be configured to use it.
123+
You need to select a [swap behavior](/docs/reference/node/swap-behavior/)
124+
for this node. You'll configure _LimitedSwap_ behavior for this tutorial.
125+
126+
Find and edit the kubelet configuration file, and:
127+
128+
- set `failSwapOn` to false
129+
- set `memorySwap.swapBehavior` to LimitedSwap
123130

124131
```yaml
125132
# this fragment goes into the kubelet's configuration file
@@ -129,3 +136,10 @@ After enabling swap on the node, kubelet needs to be configured in the following
129136
```
130137
131138
In order for these configurations to take effect, kubelet needs to be restarted.
139+
Typically you do that by running:
140+
```shell
141+
systemctl restart kubelet.service
142+
```
143+
144+
You should find that the kubelet is now healthy, and that you can run Pods
145+
that use swap memory as needed.

0 commit comments

Comments
 (0)