Cyberithub

How to Install kubeadm on Ubuntu 20.04 LTS (Focal Fossa)

Advertisements

In this article, I will take you through the steps to install kubeadm on Ubuntu 20.04 LTS (Focal Fossa). Kubeadm is a free and open source tool used for performing action necessary to make Kubernetes Clusters up and running. Originally it is only built to bootstrap the control plane and worker nodes and not to provision the machines. It can also be used to manage the Kubernetes Certificates and kubeconfig files. kubeadm init and kubeadm join are the most often used commands for creating Kubernetes Clusters. We will see the usage of both these commands along with the installation of kubeadm in below section. More on Kubeadm Official Page.

How to Install kubeadm on Ubuntu 20.04 LTS (Focal Fossa)

How to Install kubeadm on Ubuntu 20.04 LTS (Focal Fossa)

Also Read: How to Install PostgreSQL DB on RHEL/CentOS 7/8

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 LTS Server.

b) You should have snap utility available in your Server.

c) You should have sudo or root access to run privileged commands.

 

Step 2: Update Your Server

Before installing the kubeadm utility, it is a good idea to sync the System with the latest updates using apt update command as shown below. If any of the packages needs to be upgraded then run apt upgrade command.

root@cyberithub:~# apt update
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:3 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:4 http://ppa.launchpad.net/nilarimogard/webupd8/ubuntu focal InRelease
Get:5 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:7 https://dl.google.com/linux/chrome/deb stable InRelease [1,811 B]
Hit:8 http://apt.postgresql.org/pub/repos/apt focal-pgdg InRelease
Get:9 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [623 kB]
Get:10 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1,680 kB]
Get:11 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [278 kB]
Get:12 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [14.8 kB]
Get:13 http://in.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [913 kB]
Get:14 http://in.archive.ubuntu.com/ubuntu focal-updates/universe i386 Packages [673 kB]

 

Step 3: Install kubeadm

There are multiple ways to install kubeadm command line tool. But here we will install it as a snap package using snap install kubeadm --classic command as shown below. It will download and install the package from Snap Store.

root@cyberithub:~# snap install kubeadm --classic
kubeadm 1.23.5 from Canonical* installed

 

Step 4: Check Version

After successful installation you can check the snap package version by using kubeadm version command as shown below.

root@cyberithub:~# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.5", GitCommit:"c285e781331a3785a7f436042c65c5641ce8a9e9", GitTreeState:"clean", BuildDate:"2022-03-17T03:51:28Z", GoVersion:"go1.17.8", Compiler:"gc", Platform:"linux/amd64"}

 

Step 5: Bootstrap Control Plane Node

To initialize a control plane node you need to use below kubeadm init command. This will run the pre flight checks and initialize all the components required to make the master node up and running.

root@cyberithub:~# kubeadm init --apiserver-advertise-address $(hostname -i) --pod-network-cidr 10.5.0.0/16
Initializing machine ID from random generator.
I0330 01:56:07.086592 882 version.go:251] remote version is much newer: v1.23.5; falling back to: stable-1.20
[init] Using Kubernetes version: v1.20.15
[preflight] Running pre-flight checks
[WARNING Service-Docker]: docker service is not active, please run 'systemctl start docker.service'
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[WARNING FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
[WARNING Swap]: running with swap on is not supported. Please disable swap
[preflight] The system verification failed. Printing the output from the verification:
KERNEL_VERSION: 4.4.0-210-generic
DOCKER_VERSION: 20.10.1
OS: Linux
CGROUPS_CPU: enabled
CGROUPS_CPUACCT: enabled
CGROUPS_CPUSET: enabled
CGROUPS_DEVICES: enabled
CGROUPS_FREEZER: enabled
CGROUPS_MEMORY: enabled
CGROUPS_PIDS: enabled
CGROUPS_HUGETLB: enabled
[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.1. Latest validated version: 19.03
[WARNING SystemVerification]: failed to parse kernel config: unable to load kernel module: "configs", output: "", err: exit status 1
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
.......................................

 

Step 6: Bootstrap Worker Node

If you have a worker node then you need to run below kubeadm join command to join it as a worker node to the Kubernetes Cluster.

root@worker:~# kubeadm join 192.168.0.23:6443 --token c7w389.boxtmiojts0aasd0 --discovery-token-ca-cert-hash sha256:4b448181634c48fbc7d90379adef27534f8fe7e5de0cd0b39a15d0f35797f8b0
Initializing machine ID from random generator.
[preflight] Running pre-flight checks
[WARNING Service-Docker]: docker service is not active, please run 'systemctl start docker.service'
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[WARNING FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
[WARNING Swap]: running with swap on is not supported. Please disable swap
[preflight] The system verification failed. Printing the output from the verification:
KERNEL_VERSION: 4.4.0-210-generic
DOCKER_VERSION: 20.10.1
OS: Linux
CGROUPS_CPU: enabled
CGROUPS_CPUACCT: enabled
CGROUPS_CPUSET: enabled
CGROUPS_DEVICES: enabled
CGROUPS_FREEZER: enabled
CGROUPS_MEMORY: enabled
CGROUPS_PIDS: enabled
CGROUPS_HUGETLB: enabled
[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.1. Latest validated version: 19.03
[WARNING SystemVerification]: failed to parse kernel config: unable to load kernel module: "configs", output: "", err: exit status 1
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

 

Step 7: Check all the available options

You can also check all the options available with kubeadm command using kubeadm --help as shown below.

root@cyberithub:~# kubeadm --help

┌──────────────────────────────────────────────────────────┐
│ KUBEADM                                                  │
│ Easily bootstrap a secure Kubernetes cluster             │
│                                                          │
│ Please give us feedback at:                              │
│ https://github.com/kubernetes/kubeadm/issues             │
└──────────────────────────────────────────────────────────┘

Example usage:

Create a two-machine cluster with one control-plane node
(which controls the cluster), and one worker node
(where your workloads, like Pods and Deployments run).

┌──────────────────────────────────────────────────────────┐
│ On the first machine:                                    │
├──────────────────────────────────────────────────────────┤
│ control-plane# kubeadm init                              │
└──────────────────────────────────────────────────────────┘

┌──────────────────────────────────────────────────────────┐
│ On the second machine:                                   │
├──────────────────────────────────────────────────────────┤
│ worker# kubeadm join <arguments-returned-from-init>      │
└──────────────────────────────────────────────────────────┘

 

Step 8: Uninstall kubeadm

Once you are done with kubeadm command line tool then you can also uninstall it from your system by using snap remove kubeadm command as shown below.

root@cyberithub:~# snap remove kubeadm
kubeadm removed

Leave a Comment