How to Install Kubernetes & Container Runtime on Ubuntu 20.04 LTS.
Kubernetes is a tool for managing Docker containers at scale on on-premise server or across hybrid cloud environments. It is provided with Kubernetes to help users to install a production ready Kubernetes cluster. In Kubernetes cluster. we needs a minimum of two nodes – a master node and a worker node.
- Master: It is a node which control API calls for the pods, replications controllers, services, nodes and other components of a Kubernetes cluster.
- Node: It provides the run-time environments for the containers. A set of container pods can span multiple nodes.
Install Kubernetes on Ubuntu
Update the system.
apt-get update
Set Kubernetes repository.
apt-get -y install curl apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" |
sudo tee /etc/apt/sources.list.d/kubernetes.list
Here is the command output.
Install kubelet, kubeadm and kubectl.
apt-get update
apt-get -y install vim git curl wget kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
Here is the command output.
Once Installation is done,check the version of kubectl.
kubectl version --client && kubeadm version
Here is the command output.
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2",
GitTreeState:"clean", BuildDate:"2021-06-16T12:59:11Z",Platform:"linux/amd64"}
kubeadm version: &version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2",
GitTreeState:"clean", BuildDate:"2021-06-16T12:57:56Z",Platform:"linux/amd64"}
Disable Swap.
- Turn off swap.
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
swapoff -a
- Configure sysctl.
modprobe overlay
modprobe br_netfilter
tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
Here is the command output.
Install Container runtime
- Run containers in Pods, Kubernetes uses a container runtime.
- It supports Docker,CRI-O & Containerd container runtimes.
Docker runtime:
##Update the system
apt-get update
## Install Required Repositroy.
apt install curl gnupg2 software-properties-common apt-transport-https ca-certificates
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu
$(lsb_release -cs) stable"
##Install Docker
apt-get update
apt install -y containerd.io docker-ce docker-ce-cli
Create Directory.
mkdir -p /etc/systemd/system/docker.service.d
Create daemon json config file.
tee /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
Here is the command output.
Start & Enable Docker.
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
Install CRI-O:
- Set load modules.
modprobe overlay
modprobe br_netfilter
- Set required sysctl params.
tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
- Reload the sysctl.
sysctl --system
- Add repo.
. /etc/os-release
sh -c "echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:
/stable/x${NAME}_${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:
libcontainers:stable.list"
wget -nv https://download.opensuse.org/repositories/devel:kubic:
libcontainers:stable/x${NAME}_${VERSION_ID}/Release.key -O- | sudo apt-key add -
- Update the system.
apt-get update
- Install CRI-O.
apt-get install cri-o-runc
- Start and enable Service.
systemctl daemon-reload
systemctl start crio
systemctl enable crio
Installing Containerd:
- Configure persistent loading of modules.
tee /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF
- Set Load modules.
modprobe overlay
modprobe br_netfilter
- Set sysctl params.
tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
- Reload configs.
sysctl --system
- Install required packages.
apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates
- Add Docker repo.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu
$(lsb_release -cs) stable"
- Install containerd.
apt update
apt install -y containerd.io
- Configure containerd and start service.
mkdir -p /etc/containerd
sudo su -
containerd config default /etc/containerd/config.toml
- Restart containerd.
systemctl restart containerd
systemctl enable containerd