How to Install Kubernetes on All Linux Distros

Kubernetes is container orchestration software that allows us to deploy, manage, and scale containerized applications across any number of node systems. It is a powerful and open source technology which makes it far more efficient to run applications at scale, and supersedes the traditional way of running applications directly on the operating system or in a virtual machine. A Kubernetes cluster also introduces self healing, load balancing, and a way to manage hundreds or thousands of containerized application from a single command prompt.

In this tutorial, we will learn how to install Kubernetes on all major Linux distributions. This is not as straightforward as installing most applications, since the official repositories usually do not contain all of the needed software. It is also essential to install Docker (or some other containerization layer), disable swap, and configure some other settings. We will walk you through everything below.

In this tutorial you will learn:

  • How to install Kubernetes (kubeadm) on all major Linux distros
  • How to install Docker and kubectl
  • How to disable swap space
  • How to start and enable Docker and kubelet services
How to Install Kubernetes on All Linux Distros
How to Install Kubernetes on All Linux Distros
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software Kubernetes, kubectl, Docker
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Kubernetes Installation Types




It is not so simple to give straightforward instructions on installing Kubernetes on a Linux system, because there are many different ways to run it. There are at least four different technologies that we can use to get started with Kubernetes:

  • Kubeadm
  • Minikube
  • Kind
  • K3s

Each one has their own niche, pros, and cons. The one we will be focusing on in this tutorial is Kubeadm, since it is a production ready implementation of Kubernetes. It is not very suitable for absolute beginners, so if you have trouble getting it running, you can fall back on a simpler technology like Minikube.

The other option we have is choosing a containerization technology. Kubernetes will need one in order to run. We can choose from container runtimes such as:

  • Docker
  • containerd
  • CRI-O

Docker is by far the most popular choice when it comes to a container runtime for Kubernetes, so it is the one we will be focusing on in this tutorial.

We will also install separate technologies like kubectl separately.

Install Kubernetes (kubeadm) on Linux

Choose your Linux distribution in the sections below and then follow the corresponding instructions.

Debian and Ubuntu

This section is for Linux distributions like Debian Linux, Ubuntu Linux, and any of their many derivative distributions.

  1. First, disable swap:
    $ sudo swapoff -a
    

    You will also need to edit /etc/fstab and comment the swap line to disable it on future reboots.

  2. Start by installing the following prerequisite packages:
    $ sudo apt update
    $ sudo apt install docker.io apt-transport-https ca-certificates curl
    
  3. Add your current user to the Docker group:


    $ sudo usermod -a -G docker $USER
    
  4. Once Docker has finished installing, use the following commmands to start the service and to make sure it starts automatically after each reboot:
    $ sudo systemctl start docker
    $ sudo systemctl enable docker
    
  5. Download the following signing key:
    $ sudo curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
    
  6. Add the Kubernetes software repository to your system:
    $ echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
    
  7. Then, install the tools kubelet, kubeadm, and kubectl:
    $ sudo apt update
    $ sudo apt install kubelet kubeadm kubectl
    
  8. Optionally, we can mark the Kubernetes packages to not be updated by apt until we manually try to update them. This ensures that your cluster never gets interrupted by updates and that a new version will not break your current setup.
    $ sudo apt-mark hold kubelet kubeadm kubectl
    

Fedora, Red Hat, CentOS, AlmaLinux, Rocky Linux

This section is for Red Hat Enterprise Linux, Fedora Linux, and all of their derivative distributions.

  1. First, disable swap:
    $ sudo swapoff -a
    

    You will also need to edit /etc/fstab and comment the swap line to disable it on future reboots.

  2. Start by installing the dnf-plugins-core package, in case it’s not already on your system. This will allow you to manage your dnf repositories and add the official Docker repo to them.
    $ sudo dnf -y install dnf-plugins-core
    
  3. Next, add the Docker repository to your system with the following command.
    $ sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
    
  4. Before we begin installing Docker, we need to remove the podman and buildah packages from our system, as they conflict with Docker and will inhibit it from being installed.


    $ sudo dnf remove podman buildah
    
  5. We can now install the three Docker packages we will need by executing the following command.
    $ sudo dnf install docker-ce docker-ce-cli containerd.io
    
  6. Add your current user to the Docker group:
    $ sudo usermod -a -G docker $USER
    
  7. Once installation is completed, start the Docker service and then enable it to run automatically whenever the system is rebooted:
    $ sudo systemctl start docker.service
    $ sudo systemctl start containerd.service
    $ sudo systemctl enable docker.service
    $ sudo systemctl enable containerd.service
    
  8. Add the Kubernetes repository to your system:
    cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
    [kubernetes]
    name=Kubernetes
    baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
    enabled=1
    gpgcheck=1
    gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
    exclude=kubelet kubeadm kubectl
    EOF
    
  9. Disable SELinux by putting it into permissive mode:
    $ sudo setenforce 0
    $ sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
    
  10. Install the kubelet, kubeadm, and kubectl packages:
    $ sudo dnf install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
    
  11. Instruct systemd to start kubelet and make it start up automatically on future system boots:
    $ sudo systemctl enable kubelet
    $ sudo systemctl start kubelet
    



Arch Linux and Manjaro

This section is for Linux distributions like Arch Linux, Manjaro Linux, and their derivatives.

  1. First, disable swap:
    $ sudo swapoff -a
    

    You will also need to edit /etc/fstab and comment the swap line to disable it on future reboots.

  2. Start by installing Docker (and yay to download Kubernetes from the AUR):
    $ sudo pacman -Syu
    $ sudo pacman -S docker yay devtools base-devel
    
  3. Add your current user to the Docker group:
    $ sudo usermod -a -G docker $USER
    
  4. Once installation is completed, start the Docker service and then enable it to run whenever the system is rebooted:
    $ sudo systemctl start docker.service
    $ sudo systemctl enable docker.service
    
  5. Now we can use yay to download kubeadm, kubelet, and kubectl from the AUR:
    $ yay -S kubeadm-bin kubelet-bin kubectl-bin
    
  6. Finally, start the kubelet service so Kubernetes will be ready to use:
    $ sudo systemctl start kubelet
    $ sudo systemctl enable kubelet
    

Snap Method

It also possible to use Snap package manager to install all of the necessary Kubernetes packages.

  1. Install Docker, kubeadm, kubectl, and kubelet with Snap:
    $ sudo snap install docker
    $ sudo snap install kubeadm kubectl kubelet --classic
    
  2. Add your current user to the Docker group:
    $ sudo usermod -a -G docker $USER
    
  3. And start the necessary services:
    $ sudo systemctl start docker
    $ sudo systemctl enable docker
    $ sudo systemctl start kubelet
    $ sudo systemctl enable kubelet
    

Closing Thoughts




In this tutorial, we saw how to install Kubernetes all major Linux distributions, including a universal method via the Snap package manager. These instructions are enough to get you started with the bare basics, which includes the installation of kubeadm and Docker. Once you get these services up and running, you can continue by joining nodes, deploying applications, and growing your Kubernetes cluster.



Comments and Discussions
Linux Forum