Last active
August 20, 2026 09:06
-
-
Save DoumanAsh/b9703856890e46ebdd20c7a1db612f16 to your computer and use it in GitHub Desktop.
Daemon set to fix bad default setting for SWAP. This will reduce chances of Swap memory being used, while not disabling it completely. You want it when your nodes have sufficiently memory hungry workloads which will lead to Linux allocate more Swap than necessary, causing kswapd0 to be busy and eating your CPU, starving the node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apiVersion: v1 | |
| kind: ServiceAccount | |
| metadata: | |
| name: eks-swap-fixer-oneshot | |
| namespace: kube-system | |
| --- | |
| apiVersion: rbac.authorization.k8s.io/v1 | |
| kind: ClusterRole | |
| metadata: | |
| name: eks-swap-fixer-oneshot | |
| rules: | |
| - apiGroups: [""] | |
| resources: ["nodes"] | |
| verbs: ["get", "patch"] | |
| --- | |
| apiVersion: rbac.authorization.k8s.io/v1 | |
| kind: ClusterRoleBinding | |
| metadata: | |
| name: eks-swap-fixer-oneshot | |
| roleRef: | |
| apiGroup: rbac.authorization.k8s.io | |
| kind: ClusterRole | |
| name: eks-swap-fixer-oneshot | |
| subjects: | |
| - kind: ServiceAccount | |
| name: eks-swap-fixer-oneshot | |
| namespace: kube-system | |
| --- | |
| apiVersion: apps/v1 | |
| kind: DaemonSet | |
| metadata: | |
| name: eks-swap-fixer-oneshot | |
| namespace: kube-system | |
| spec: | |
| selector: | |
| matchLabels: | |
| app: eks-swap-fixer-oneshot | |
| template: | |
| metadata: | |
| labels: | |
| app: eks-swap-fixer-oneshot | |
| spec: | |
| serviceAccountName: eks-swap-fixer-oneshot | |
| hostNetwork: true | |
| tolerations: | |
| - operator: Exists | |
| # Do not schedule on nodes that are already configured with current version | |
| affinity: | |
| nodeAffinity: | |
| requiredDuringSchedulingIgnoredDuringExecution: | |
| nodeSelectorTerms: | |
| - matchExpressions: | |
| - key: eks-swap-configured | |
| operator: DoesNotExist | |
| - matchExpressions: | |
| - key: eks-swap-configured | |
| operator: NotIn | |
| values: | |
| - "v1" | |
| initContainers: | |
| - name: sysctl-init | |
| image: public.ecr.aws/docker/library/busybox:stable-musl | |
| securityContext: | |
| privileged: true | |
| command: ["/bin/sh", "-c"] | |
| args: | |
| - | | |
| set -e | |
| echo "Applying vm.swappiness=60 on $NODE_NAME/$(hostname)..." | |
| sysctl -w vm.swappiness=60 | |
| containers: | |
| - name: apply-node-labeler | |
| image: registry.k8s.io/kubectl:v1.34.9 | |
| args: | |
| - label | |
| - node | |
| - "$(NODE_NAME)" | |
| - eks-swap-configured=v1 | |
| - --overwrite | |
| env: | |
| - name: NODE_NAME | |
| valueFrom: | |
| fieldRef: | |
| fieldPath: spec.nodeName | |
| resources: | |
| requests: | |
| cpu: 10m | |
| memory: 16Mi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment