This tutorial will show you how to install Kubernetes on Ubuntu Linux 20.04 using CRI-O as the container runtime and Calico for the Pod network add-on.
Overview of steps
First we will prepare the Ubuntu server for Kubernetes by disabling Swap, configuring the network and installing CRI-O. Then we will install kubeadm and Kubernetes. Finally, we will use kubeadm to create a single node cluster and deploy the Calico Pod network add-on.
Step 1: Disable Swap
As of writing, Kubernetes requires that Swap is disabled on the Linux server so that the kubelet process can reliably schedule memory to the pods. To disable swap, run the following command:
sudo swapoff -a
To make the change permanent, you will need to edit the fstab file.
Open /etc/fstab, remove the line containing swap and then save the file.
/swap.img none swap sw 0 0
This will prevent swap from being enabled the next time the system boots.
Step 2: Configure the Network
Assign a static IP address (I’ve used 10.1.1.11 in this guide) - Tutorial
Assign a hostname (I’ve used k8s-master in this guide) - Tutorial
Configure iptables to see bridged traffic.
# Create the .conf file to load the modules at bootup
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
sudo modprobe overlay
sudo modprobe br_netfilter
# Set up required sysctl params, these persist across reboots.
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
sudo sysctl --system
Step 3: Install CRI-O
Add the Kubic repository because it contains the binary packages of CRI-O.
You can check to see if the pods have started with the following watch command:
watch kubectl get pods -n kube-system
Wait until each pod has the STATUS of Running then terminate the watch utility.
Check to see if the node is ready with the following command:
kubectl get nodes -o wide
You should see an output like the following:
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8s-master Ready control-plane,master 3m55s v1.23.4 10.1.1.11 <none> Ubuntu 20.04.4 LTS 5.4.0-100-generic cri-o://1.23.1
Congrats! You now have a single node Kubernetes cluster running on Ubuntu 20.04. We used CRI-O as a lightweight alternative to the Docker container runtime and we used Calico for the Pod network. You’re now ready to deploy some pods or join some worker nodes to the cluster.