Table of Contents

# Add Swap support to K3s Node

Configure the K3s swap

Use the drop-in manifest in directory /var/lib/rancher/k3s/agent/etc/kubelet.conf.d

Note

Drop-in configuation only supported in v1.32+

Create file /var/lib/rancher/k3s/agent/etc/kubelet.conf.d/100-k3s-swap.conf

apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
memorySwap:
  swapBehavior: LimitedSwap # the size is base on a request/limit ratio, and only apply to Qos Burstable.

Restart k3s

sudo systemctl restart k3s

Check swap usage.

# check feature gate, enabled when value is `1`
kubectl get --raw /metrics  | grep kubernetes_feature_enabled | grep Swap

# check inside the pod, the swap value would > 0
cat /sys/fs/cgroup/memory.swap.max

Reference