peter (admin) -

Preparing Linux for Kubernetes
In this section, we will prepare our Linux system for Kubernetes by installing several important tools and configuring the operating system correctly.
Preparing the system before installing Kubernetes helps prevent performance problems, networking issues, and unexpected failures later.
It also ensures that the operating system, container runtime, and Kubernetes components can work together correctly.
Connecting to the Linux Server
First, connect to the Linux machine using an SSH client such as PuTTY.
Log in using your normal Linux user account.
Once you see the command prompt, the server is ready for configuration.
Before making changes, it is useful to check the operating system:
cat /etc/os-release
You can also check the kernel version:
uname -r
Installing Basic Linux Tools
The first step is to install some useful packages that we will need while configuring and troubleshooting Kubernetes.
These include:
-
curl -
wget -
git -
vim -
nano -
unzip -
tar -
jq
On a RHEL-compatible distribution such as Rocky Linux or AlmaLinux, you can install them with:
sudo dnf install -y curl wget git vim nano unzip tar jq
Depending on the Linux distribution and version, yum may also be available:
sudo yum install -y curl wget git vim nano unzip tar jq
These utilities have different purposes.
On Debian based systems
sudo apt install conntrack socat iptables curl wget vim nano unzip tar jq
curl and wget
curl and wget allow us to download files and communicate with HTTP/HTTPS services.
For example:
curl https://example.com
or:
wget https://example.com/file.tar.gz
They are particularly useful when downloading Kubernetes packages, repository configuration, scripts, and other installation files.
Git
git allows us to download and manage source-code repositories:
git clone
Many Kubernetes examples and configuration projects are distributed through Git repositories.
Vim and Nano
vim and nano are text editors.
They allow us to modify configuration files directly from the Linux terminal.
For example:
sudo nano /etc/hosts
unzip and tar
These utilities allow us to extract compressed archives.
For example:
tar -xvf archive.tar
or:
unzip archive.zip
jq
jq is a command-line JSON processor.
It is particularly useful when working with APIs and command output containing JSON.
For example:
cat data.json | jq
Why We Use sudo
Many of the commands required to prepare Kubernetes modify the operating system.
A normal Linux user generally does not have permission to install software or modify important system configuration files.
For this reason, we use:
sudo
For example:
sudo dnf install -y curl
sudo allows an authorized user to execute a command with elevated privileges.
This is preferable to operating as the root user for everything because administrative privileges are only used when they are actually required.
Installing Networking Utilities
Kubernetes relies heavily on Linux networking, so several networking packages and utilities are useful.
Depending on the distribution, these can include tools providing:
-
conntrack -
socat -
ip -
iptables
On a RHEL-compatible system, the exact package names can vary by release, but you can search for them using:
dnf search conntrack
dnf search socat
dnf search iproute
dnf search iptables
Then install the appropriate packages for your distribution.
conntrack
conntrack is related to Linux connection tracking.
The Linux kernel can keep information about active network connections and use that information when processing network traffic.
This is important in container and Kubernetes networking because many connections can exist between applications, Pods, Services, and external systems.
You can inspect connection-tracking information with commands such as:
sudo conntrack -L
socat
socat is a networking utility capable of transferring data between different types of connections.
It is useful for networking diagnostics, port forwarding, and troubleshooting communication between processes.
For example, it can listen on or forward TCP connections.
iproute
The ip command is normally provided by the iproute/iproute2 package family.
It provides important Linux networking commands such as:
ip addr
to display network interfaces and addresses.
You can inspect routing with:
ip route
These commands become extremely useful when troubleshooting Kubernetes networking.
iptables
iptables provides Linux packet-filtering and network-rule functionality.
Depending on the Kubernetes version and networking implementation, iptables may be used for networking and Service-related traffic.
You can inspect existing rules using:
sudo iptables -L
For more detailed information:
sudo iptables -L -n -v
When troubleshooting Kubernetes networking, understanding basic concepts such as IP addresses, routes, ports, firewall rules, and packet forwarding is extremely valuable.
Understanding Swap
The next important configuration is swap.
Swap is disk space that Linux can use to supplement physical RAM under certain circumstances.
For example, imagine a computer has:
Physical RAM: 4 GB
Swap: 2 GB
When memory pressure occurs, Linux may move some memory pages between RAM and swap storage.
Because disks are much slower than RAM, accessing swapped memory can have a significant performance impact.
Kubernetes and Swap
Historically, Kubernetes installations commonly required swap to be disabled because kubelet's memory management expected workloads to operate using physical memory.
Modern Kubernetes versions have introduced support for controlled swap configurations, but disabling swap remains a common and straightforward configuration for kubeadm learning clusters.
For a simple Kubernetes lab, we can therefore disable it.
Check Whether Swap Is Enabled
Before changing anything, check the current swap configuration:
swapon --show
You can also use:
free -h
For example, you might see:
total used free
Mem: 4.0Gi 1.1Gi 2.9Gi
Swap: 2.0Gi 0B 2.0Gi
This tells us that the system currently has 2 GiB of swap configured.
Disable Swap Temporarily
To immediately disable all swap:
sudo swapoff -a
Now check again:
free -h
The result should show something similar to:
Swap: 0B 0B 0B
You can also run:
swapon --show
If no swap devices are listed, swap is currently disabled.
Disable Swap Permanently
Running:
sudo swapoff -a
only disables swap for the current running system.
If swap is configured in /etc/fstab, it may become active again after the machine is restarted.
The file we need to examine is:
/etc/fstab
First, make a backup:
sudo cp /etc/fstab /etc/fstab.backup
Then open the file:
sudo nano /etc/fstab
Look for a line defining swap.
It might look similar to:
/dev/mapper/system-swap swap swap defaults 0 0
or:
/swapfile none swap sw 0 0
Comment the swap entry by adding # at the beginning:
#/swapfile none swap sw 0 0
Save the file and exit the editor.
This prevents that swap entry from automatically being activated during the next boot.
Verify the Configuration
After disabling swap, verify it with:
swapon --show
and:
free -h
You should see that no swap is currently active.
After rebooting the server, check again:
free -h
If swap still shows:
Swap: 0B
then the configuration has persisted correctly.
Why These Preparations Matter
Our Linux machine now has the basic tools required to continue configuring Kubernetes.
The preparation process can be summarized as:
Linux Server
|
+---- Install command-line tools
|
+---- Install networking utilities
|
+---- Check network configuration
|
+---- Disable swap
|
+---- Verify system configuration
|
v
Ready for the next Kubernetes setup stage
These steps provide a cleaner and more predictable environment for our Kubernetes installation.
Useful Checks Before Continuing
Before moving on, we can perform several quick checks.
Check memory:
free -h
Check CPU:
nproc
Check disk space:
df -h
Check IP addresses:
ip addr
Check routing:
ip route
Check swap:
swapon --show
Check the operating system:
cat /etc/os-release
These commands are also useful later when troubleshooting Kubernetes.
System Preparation Complete
At this point, the basic Linux system preparation is complete.
We have installed useful command-line and networking tools, examined some of the networking utilities Kubernetes relies upon, and configured swap appropriately for our Kubernetes learning environment.
Our Linux machine is now ready for the next stage of the Kubernetes installation and configuration process.
Comments (0)
There are no comments yet. Be the first to comment.
Log in or register to leave a comment. all comments are subject to admin approval