Install Kubernetes – Ubuntu Focal 20.04

  • Distribution: Ubuntu Focal 20.04 (LTS)

You need to set up the cluster: Master node and Worker nodes.

  • Master: A Master a system that control API calls for the pods, controllers, services, nodes and other components of a Kubernetes cluster are executed.
  • Worker: A Worker is a system that provides the run-time environments for the containers. A set of container pods can span multiple nodes.

Kubernetes Packages

There are 3 packages you need to install.

  • kubeadm: a tool which sets up a cluster
  • kubelet: a component which run containers on a node
  • kubectl: command-line tool for interacting with a cluster and its resources

Prerequisite – Docker

Install Docker

Set up the Kubernetes repositories

curl -s | sudo apt-key add -

cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb kubernetes-xenial main
  • At the time of the writing, “kubernetes-xenial” is the latest Kubernetes repository. It might be replaced with “kubernetes-focal”. Check

Install Kubernetes packages

sudo apt-get update

sudo apt-get install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl

Configure sysctl

sudo modprobe overlay

sudo modprobe br_netfilter

sudo 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

sudo sysctl --system

Disable Swap

sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

sudo swapoff -a

Confirm installation of kubectl

kubectl version --client && kubeadm version

Initialize the cluster – Master Only

#Enable kubelet service.
sudo systemctl enable kubelet

#Pull container images
sudo kubeadm config images pull

sudo kubeadm init --pod-network-cidr=
  • Copy the last part of the result — You will need this.

Set up local kubeconfig – Master Only

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

export KUBECONFIG=$HOME/.kube/config

Install Flannel networking – Master Only

kubectl apply -f

Check the nodes – Master

kubectl get nodes
  • You can see the master node.

Join Worker to the Cluster – Worker

  • Run the Join command copied from the “kubeadm init” command
sudo kubeadm join --token 90wmxd.76csh4jlamyhs7io \
--discovery-token-ca-cert-hash sha256:1384a4aa86c6128a35ca3d7e4461431474f27487500f40954a7c3ce56b083bab

Check the nodes – Master

kubectl get nodes

kubectl get pods --all-namespaces

kubectl cluster-info
  • You can see the master node and all worker nodes

Installing Metrics Server

kubectl apply -f 

# verify - wait for ready
kubectl get deployment metrics-server -n kube-system

# check metrics
kubectl top nodes
kubectl top pods -A

  • If the deployment fails with Liveness probe failed: HTTP probe failed with statuscode: 500′, do the following.
# edit deployment
kubectl edit deploy metrics-server -n kube-system 

# find the args
# add --kubelet-insecure-tls under the port
- --secure-port=4443
- --kubelet-insecure-tls

# verify - wait for ready
kubectl get deployment metrics-server -n kube-system

1 Comment

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s