File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,15 +16,20 @@ apt-get install -y \
1616systemctl enable --now docker
1717usermod -aG docker ubuntu # takes effect on next login for 'ubuntu'
1818
19- # Add swap space (2GB) to help with memory pressure
20- fallocate -l 2G /swapfile
21- chmod 600 /swapfile
22- mkswap /swapfile
23- swapon /swapfile
24- echo ' /swapfile none swap sw 0 0' >> /etc/fstab
25-
26- # Configure swappiness (how aggressively to use swap - 10 is conservative)
27- echo ' vm.swappiness=10' >> /etc/sysctl.conf
19+ # Add swap space (2GB) to help with memory pressure (idempotent)
20+ if ! swapon --show | grep -q ' ^/swapfile' ; then
21+ SWAP_GB=2
22+ fallocate -l ${SWAP_GB} G /swapfile || dd if=/dev/zero of=/swapfile bs=1M count=$(( SWAP_GB* 1024 ))
23+ chmod 600 /swapfile
24+ mkswap /swapfile
25+ swapon /swapfile
26+ # persist across reboots
27+ grep -q ' ^/swapfile ' /etc/fstab || echo ' /swapfile none swap sw 0 0' >> /etc/fstab
28+ fi
29+ # Conservative swappiness
30+ sysctl -w vm.swappiness=10
31+ echo ' vm.swappiness=10' > /etc/sysctl.d/99-swap.conf
32+ sysctl --system > /dev/null
2833
2934# K3s (pin to stable; adjust as you like)
3035curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL=stable sh -s - --write-kubeconfig-mode 640
You can’t perform that action at this time.
0 commit comments