Swap file - how to check usage and expand it
SWAP FILE
When setting up Kubernetes nodes, it's typically not recommended to use swap files or partitions. This is because swap can disrupt Kubernetes' resource management and scheduling processes. However, if you really need to enable swap, you can change the kubelet settings by adding the --fail-swap-on=false
flag. Keep in mind, though, that this is generally not advised for production environments.
Adding swap space
Adding swap space on Arch Linux can be done in two ways:
by creating a swap file or by setting up a swap partition.
Creating a Swap File
You can create a swap file of the desired size using the dd command. For example, to create a 4GB swap file, you can use:
Set Permissions
For security, set the swap file's permissions so that only root can read and write to it:
Format the file to a swap format using the mkswap command:
Activate the Swap File Turn on the swap file with the swapon command:
Make the Swap File Permanent
To ensure the swap file is used on system boot, add it to your /etc/fstab file.
Add the following line at the end of the file:
Check the Swap Status
You can verify that the swap is active by using:
Adjusting Swappiness
The "swappiness" parameter controls how often your system uses swap space. It's a value between 0 and 100. a lower value makes the kernel try to avoid swapping whenever possible, while a higher value allows more aggressive swapping.
To temporarily change the swappiness value:
To make this change permanent, add the following line to your /etc/sysctl.conf file:
To check swappiness
Last
This approach of using a swap file is flexible and simple for most use cases. If you prefer a swap partition due to performance considerations or personal preference, the process involves using a partitioning tool like fdisk or gparted to create the swap partition, and then using mkswap and swapon to initialize and enable it, similarly to how the swap file is set up.