Install and Configure Kubernetes on Ubuntu

~

How to install and configure Kubernetes Ubuntu 18.10, here I am using google instance

~

Below are the details of instances

Node Name Master Node Node1 Node2 Node3
Hostname K8master K8node1 K8nod2 K8nod3
IP Address 10.142.0.15 10.142.0.16 10.142.0.17 10.142.0.18

~

There is one master node and other three nodes will at as slave and will add in Kubernetes cluster.

*Installation and configuration steps*

~

Step1 – First run apt-get update on all instances

~

Step2 – change the hostname of all instances

sudo hostnamectl set-hostname “<hostname>”

exec bash

~

Step3 – add below entries in /etc/hosts on all instances

K8master             10.142.0.15

K8node1              10.142.0.16

K8nod2                 10.142.0.17

K8nod3                 10.142.0.18

~

Step4 – Install docker and start the service on all instances

sudo apt-get install docker.io -y

sudo systemctl start docker

sudo systemctl enable docker

~

Step5 – Install required packages on all instances

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

~

Step6 – Add Kubernetes package repository key on all instances

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

~

Step7 – Configure Kubernetes repository using below apt commands on all instances

sudo apt-add-repository “deb http://apt.kubernetes.io/ kubernetes-xenial main”

~

Step8 – Disable swap on all instances*

sudo swapoff -a

*Note – permanent swap disable, comment out swapfile in /etc/fstab

~

Step9 – Install Kubeadm package on all instances

sudo apt-get install kubeadm -y

~

Step9 – Initialize and Start Kubernetes Cluster on Master Node

sudo kubeadm init –pod-network-<cidr>

~

Output –

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube

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

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

You should now deploy a pod network to the cluster.

Run “kubectl apply -f [podnetwork].yaml” with one of the options listed at:

https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 10.142.0.15:6443 –token dlrgmp.6ur3hxw4p82blpty \

    –discovery-token-ca-cert-hash sha256:9c7f3814c72f7a4c57bb47792d5ac13b67938cbb2302740e9bf55be80615c78e

~

As mater node initialize successfully, need to start cluster by below commands

mkdir -p $HOME/.kube

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

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

and verify the master node status

~

# kubectl get nods                               

NAME                                     STATUS           ROLES            AGE         VERSION

K8master                               Not Ready      master            1m           v1.14.1

above command output shows that master node is not ready because as of now we have not deployed any pod.

~

Step10 – Installation of Flannel as Pod Network on Master node

sudo kubectl apply -f  https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

~

verify the master node status and pod namespaces

sudo  kubectl get nodes

sudo  kubectl get pods –all-namespaces

~

Step11 – add the nodes on cluster

In Step 9, kubeadm output will show the command to add the node on cluster

~

Run below command on all node instances

sudo kubeadm join 10.142.0.15:6443 –token dlrgmp.6ur3hxw4p82blpty \     –discovery-token-ca-cert-hash sha256:9c7f3814c72f7a4c57bb47792d5ac13b67938cbb2302740e9bf55be80615c78e

~

Now check the master and slave node status from master server

Leave a Reply

}