Part of the official requirements for Kubernetes is to disable swap space completely before attempting to launch Kubernetes. In some recent patch notes, Kubernetes has begun implementing support for swap space in some scenarios, but it is not fully supported. The official reason for not supporting swap space is because it is hard to predict how a pod might utilize memory when swap is enabled.
If you are looking to install Kubernetes and get started with using it, you will need to ensure that swap space is turned off in your Linux system, both for the master node and all worker nodes in the Kubernetes cluster. In this tutorial, we will show you how to permanently disable swap space on a Linux system to make it ready for Kubernetes.
In this tutorial you will learn:
- How to temporarily disable swap space
- How to permanently disable swap space
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to Disable Swap Space in Linux
Running the following command will disable swap temporarily. This will keep swap disabled until a system reboot.
$ sudo swapoff -a
To disable swap permanently, we need to comment out the corresponding line in the
$ sudo nano /etc/fstab
Comment out the swap line by adding a
# pound sign in front of it.
Even more simply, we can use the sed command to add a
# character to any line that contains the word “swap” inside of our system’s
$ sudo sed -i '/ swap / s/^/#/' /etc/fstab
In this tutorial, we saw how to disable swap space on a Linux system in order to accommodate Kubernetes. Since Kubernetes requires that swap space be disabled, we must be sure to fulfill this crucial step before attempting to get our cluster up and running.