Kubernetes Installation

From PKC
Jump to navigation Jump to search

What is Kubernetes?

Installation Outline

After watching many videos on installing Kubernetes, the following outline is extracted from Edureka's tutorial.

The suggested initial configuration is to start with one master node and one worker node.

The master node must have at least 2 CPU cores, 2 Gb of memory.
The worker node (slave) should have at least 1 CPU core and 2 Gb of memory. 

If one needs to add more machine, one can do it after the above two machines are working.

Ideally, set up the domain names of these two nodes with their public IPv4 addresses.

Procedure for both Master and Slave

The usual initial action is to update, but make sure that you switch to the super user mode and keep being in that role throughout most of the installation.

sudo su
apt update

Swap Space must be turned off

Then, turn off swap space

swapoff -a

The /etc/fstab file must be edited to remove the line entry that specifies a /swapoff directory.

nano /etc/fstab

Update Hostname, Hosts, and Setup Static IP

Then, update the hostname file at the /etc/hostname location:

nano /etc/hostname

Change the master node and worker node to kmaster and w1 respectively.

Install Net-Tools

Before inspecting the IP addresses of these machines, you will need to first install Net-Tools.

apt install net-tools

Afterwards, run the instruction:

ifconfig

This will show some information, such as follows:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9001
        inet 172.31.20.148  netmask 255.255.240.0  broadcast 172.31.31.255
        inet6 fe80::5d:ddff:fea4:9331  prefixlen 64  scopeid 0x20<link>
        ether 02:5d:dd:a4:93:31  txqueuelen 1000  (Ethernet)
        RX packets 14905  bytes 20660726 (20.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2247  bytes 270976 (270.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 198  bytes 17010 (17.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 198  bytes 17010 (17.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Set a static IP address

Notice the inet value: 172.31.20.148. This is the static and private IP address, that can be used even after one reboots the machine. One may set up the static IP address here:

nano /etc/network/interfaces

Then, put in the following textual content:

auto enp0s8
iface enp0s8 inet static
address <IP-Address-of-masters and slaves>

Note that this step needs to be executed for each master and slave/worker node.


Set a host names

After setting up the network interfaces, one needs to set up a static look up table for the /etc/hosts file:

nano /etc/hosts

Then, put in the following textual content: Note that this step needs to be executed for each master and slave/worker node.

127.0.0.1 localhost
172.31.28.100 w1
172.31.20.148 kmaster

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Note that one may put in multiple entries at once, in this case, two entries, w1 and kmaster, are registered in the /etc/hosts file.

At this time, one may issue the command reboot, to restart the machine.

reboot

After rebooting, the machines should show the host name in command line. More importantly, use ifconfig to check if the locally-defined IP address has been kept stable.

Install Open SSH Server and Docker

If ssh server is not available, it can be set up by:

sudo apt-get install openssh-server

Afterwards, one may install docker

sudo apt-get update
sudo apt-get install -y docker.io

Then, one must make sure curl and other things are available:

sudo apt-get update && apt-get install -y apt-transport-https curl

Then, use curl to install the following

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

Install kubeadm, kubelet and kubectl

Then, one needs to add a file to the Debian package list:

cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
> deb http://apt.kubernetes.io/ kubernetes-xenial main
>EOF

Then, run the following two commands:

apt-get update
apt-get install -y kubelet kubeadm kubectl

Update the Kubernetes configuration

The following file must be edited with an extra data entry:

nano /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

In this file, add the following entry to the last line.

Environment="cgroup-driver=systemd/cgroup-driver=cgroupfs"

Only do this for the Master Node

It is time to use the kubeadm init command.

sudo kubeadm init

Or one may specify more parameter using this instruction:

sudo kubeadm init --pod-network-cidr=<depends on calico or flannel pod network> --apiserver-advertise-address=<ip-address-of-master>

An example based on Calico Pod Network (192.168.0.0/16) is shown here:

 sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --apiserver-advertise-address=172.31.20.148

An example based on Flannel Pod Network (10.244.0.0/16) is shown here:

 sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=172.31.20.148

After the Kubernetes master node has been successfully initialized, one must run the following three instructions before proceeding:

 mkdir -p $HOME/.kube
 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
 sudo chown $(id -u):$(id -g) $HOME/.kube/config

Create a Pod network based on Calico

First download the calico.yaml file

curl https://docs.projectcalico.org/manifests/calico.yaml -O

Use the kubectl apply command.

kubectl apply -f calico.yaml

Create the Kubernetes Dashboard before having any Worker nodes joining the cluster

Launch the following command:

kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml

Only at the Slave

Kubernetes on Ubuntu by Edureka

{{#ev:youtube|UWg3ORRRF60}}

Two K8s Installation tutorials by the same guy

{{#ev:youtube|briu_Ev89sw}}

{{#ev:youtube|15pdT15NUrk}}

Kubernetes Cluster on AWS EKS (Nana)

{{#ev:youtube|p6xDCz00TxU}}

A 14-minute tutorial

{{#ev:youtube|h4IawuI-EWk}}

Another tutorial

{{#ev:youtube|TDLKQWsrSyk}}


A rather short tutorial (seems to have caused errors after testing)

{{#ev:youtube|vpEDUmt_WKA}}



Some online installation tutorials

  1. https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
  2. https://computingforgeeks.com/deploy-kubernetes-cluster-on-ubuntu-with-kubeadm/
  3. https://blog.knoldus.com/how-to-install-kubernetes-on-ubuntu-20-04-kubeadm-and-minikube/