You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/concepts/cluster-administration/swap-memory-management.md
+37-46Lines changed: 37 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,53 +15,17 @@ It also helps prevent Pods from being terminated during memory pressure spikes,
15
15
shields nodes from system-level memory spikes that might compromise its stability,
16
16
allows for more flexible memory management on the node, and much more.
17
17
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/).
27
20
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 -->
59
22
60
-
{{< note >}}
23
+
## Operating system support
61
24
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.
65
29
66
30
## How does it work?
67
31
@@ -79,6 +43,31 @@ Swap configuration on a node is exposed to a cluster admin via the
79
43
As a cluster administrator, you can specify the node's behaviour in the
80
44
presence of swap memory by setting `memorySwap.swapBehavior`.
81
45
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
+
82
71
The kubelet uses the container runtime API, and directs the container runtime to
83
72
apply specific configuration (for example, in the cgroup v2 case, `memory.swap.max`) in a manner that will
84
73
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
357
346
as its low-latency electronic access minimizes the slowdown.
358
347
359
348
360
-
## Swap Behavior Details
349
+
## Swap behavior details
361
350
362
351
### How is the swap limit being determined with LimitedSwap?
363
352
@@ -398,6 +387,8 @@ Containers configured in this manner will not have access to swap memory.
398
387
399
388
## {{% heading "whatsnext" %}}
400
389
390
+
- To learn about managing swap on Linux nodes, read
391
+
[configuring swap memory on Kubernetes nodes](/docs/tutorials/configuration/provision-swap-memory/).
401
392
- 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),
403
394
and its [design](https://github.com/kubernetes/enhancements/blob/master/keps/sig-node/2400-node-swap/README.md).
0 commit comments