Wednesday, March 16, 2022

Module 11: How to Install Kubernetes Cluster on Ubuntu 20.04 LTS

 How to Install Kubernetes Cluster on Ubuntu 20.04 LTS

This tutorial will help you with step by step procedure for installing and configuring kubernetes multinode cluster with Docker on Ubuntu 20.04 LTS using Kubeadm and Kubectl.


install kubernetes on ubuntu

Let’s get started.

How to Install Kubernetes Cluster on Ubuntu 20.04 LTS

Our Lab Setup:

How to Install Kubernetes Cluster on Ubuntu 20.04 LTS
How to Install Kubernetes Cluster on Ubuntu 20.04 LTS

Prerequisites:
1. Minimum 2 CPU’s with 4Gb Memory is required.
2. Make an entry of each host in /etc/hosts file for name resolution on all kubernetes nodes as below or configure it on DNS if you have DNS server.

Below are the steps to install the cluster once the VMs are provisioned.

I have created a detailed video on how to create VMs on google cloud and install the cluster using kubeadm, below is the link.

Ports and Protocols

When running Kubernetes in an environment with strict network boundaries, such as on-premises datacenter with physical network firewalls or Virtual Networks in Public Cloud, it is useful to be aware of the ports and protocols used by Kubernetes components

Control plane

ProtocolDirectionPort RangePurposeUsed By
TCPInbound6443Kubernetes API serverAll
TCPInbound2379-2380etcd server client APIkube-apiserver, etcd
TCPInbound10250Kubelet APISelf, Control plane
TCPInbound10259kube-schedulerSelf
TCPInbound10257kube-controller-managerSelf

Although etcd ports are included in control plane section, you can also host your own etcd cluster externally or on custom ports.

Worker node(s)

ProtocolDirectionPort RangePurposeUsed By
TCPInbound10250Kubelet APISelf, Control plane
TCPInbound30000-32767NodePort Services†All

Set up the Docker and Kubernetes repositories:

Download the GPG key for docker in both master and worker node1 and node2

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the docker repository   in both master and worker node1 and node2

We can get the latest release versions from https://docs.docker.com

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Add the GPG key for Kubernetes   in both master and worker node1 and node2

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

Add the kubernetes repository in both master and worker node1 and node2

Check for the latest release in https://packages.cloud.google.com/apt/dists

cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF

Update the repository  in both master and worker node1 and node2

# Update the repositries
sudo apt-get update

Install Docker and Kubernetes packages in both master and worker node1 and node2

Note that if you want to use a newer version of Kubernetes, change the version installed for kubelet, kubeadm, and kubectl and be sure that all three use the same version. These version should support the Docker CE version.

# Use the same versions to avoid issues with the installation.
sudo apt-get install -y docker-ce=5:19.03.13~3-0~ubuntu-$(lsb_release -cs) kubelet=1.19.4-00 kubeadm=1.19.4-00 kubectl=1.19.4-00

To hold the versions so that the versions will  not get accidently upgraded in both master and worker node1 and node2

sudo apt-mark hold docker-ce kubelet kubeadm kubectl

Enable the iptables bridge in both master and worker node1 and node2

#Set a value in the sysctl file , to allow proper network settings for Kubernetes on all the servers.

echo "net.bridge.bridge-nf-call-iptables=1" | sudo tee -a /etc/sysctl.conf

#To make the changes to take immediate effect for the iptables

sudo sysctl -p

On the Kubernetes master server

Initialize the cluster by passing the cidr value and the value will depend on the type of network CLI you choose.

Use either Flannel or Calico ( we are using Calico in this lab)
# For flannel network
sudo kubeadm init --pod-network-cidr=10.244.0.0/16

# Copy your join command and keep it safe.
# Below is a sample

sudo
kubeadm join 10.128.0.2:6443 --token swi0ci.jq9l75eg8lvpxz6g --discovery-token-ca-cert-hash sha256:2c3cdfa898334b0dfc0f73bbccb998d03f61252ee50f0405c85ba735ff90b4d1
For Calico network
sudo kubeadm init --pod-network-cidr=192.168.0.0/16

# Copy your join command and keep it safe.
sudo
kubeadm join 10.128.0.2:6443 --token swi0ci.jq9l75eg8lvpxz6g --discovery-token-ca-cert-hash sha256:2c3cdfa898334b0dfc0f73bbccb998d03f61252ee50f0405c85ba735ff90b4d1

To start using the cluster with current user . ( Do this command on 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

To set the flannel networking ( Do this on master only) 

# Use this if you have initialized the cluster with Flannel network add on.
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

To set up the Calico network  ( Do this on master only) 

# Use this if you have initialized the cluster with Calico network add on.
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

Check the nodes

# Check the status on the master node.
kubectl get nodes


On each of Kube node server

Joining the node to the cluster:

sudo kubeadm join $controller_private_ip:6443 --token $token --discovery-token-ca-cert-hash $hash
TIP

If the joining code is lost, it can retrieve using below command

kubeadm token create --print-join-command

No comments:

Post a Comment

Install SonaType Nexus 3 on Ubuntu 24.0.4 - How to configure SonaType Nexus 3 on Ubuntu - Install Nexus on Ubuntu

SonaType Nexus3 is one of the popular binary repository managers, used for storing build artifacts such as Jars,WARs, EARs. It is Java based...