image

In this lab we will practice doing a version upgrade on a Kubernetes cluster using Kubeadm

Agenda

In this lab we will upgrade kubernetes cluster to version 1.19.3

you can only upgrade from one minor version at a time in this case we will be upgrading from 1.18.4 to 1.19.3

Lets Practice

Create Kubernetes cluster with 3 worker nodes.

Master: 1 node

Worker: 2 node

Hint

Solution

Create docker hub account. Docker Hub if you already have one skip this step

Open Play with Kubernetes login with your docker hub account.

Click on start

It will start a 4 hr session

create three instance

click on + ADD NEW INSTANCE three time to add three instances

image

on first instance enter below command, this node will be master node

kubeadm init --apiserver-advertise-address $(hostname -i) --pod-network-cidr 10.5.0.0/16

enter below command on first node

kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter.yaml

capture output of kubeadm join XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

image

enter captured command in second and third node

kubeadm join  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

image

image

Check node status, all 3 nodes should be in ready state

image

Create a pod with below details using kubectl

name: web

image: nginx

Use Kubectl command

verify with below command

kubectl get pods
Solution

this command will create pod with image nginx and name web

kubectl run web --image=nginx

Create a deployment with follwing details:

name: demo

image: nginx

Use Kubectl command

verify with below command

kubectl create deployment demo --image=nginx
Solution

this command will create a deployment with name demo and image nginx

kubectl run web --image=nginx

Create a pod using Kubectl and expose port, port should be accessible from outside kubernetes cluster

name: web

image: nginx

port: 80

verify with below command

kubectl get all
Solution
 kubectl expose pod web --port 80 --name=nginx-svc --type=NodePort --target-port=80

Find port used by nodeport service in Kubernetes to expose contianer

Solution
kubectl get all

Check Kubernetes version running on all nodes

Solution
kubectl get nodes

Check Kubelet version running on all nodes

Solution
kubelet --version

Check Kubectl version running on master nodes

Solution
kubectl version

Check Kubeadm version running on master nodes

Solution
kubeadm version

List available Kubeadm version on master node

Solution
yum list --showduplicates kubeadm --disableexcludes=kubernetes
yum list --showduplicates kubeadm --disableexcludes=kubernetes | grep <use the version of interest>

find 1.x.x

Upgrade Kubeadm, Kubelet, Kubectl version running on master nodes

Solution
yum install -y kubeadm-1.X.x-x kubelet-1.X.x-x kubectl-1.X.x-x --disableexcludes=kubernetes

Verify updagrade performed in previous step

Solution
kubeadm version
kubelet --version
kubectl version

Take node1 to maintainence mode

Solution
kubectl drain node1 --ignore-daemonsets

Check upgrade plan on master node

Solution
kubeadm upgrade plan

Upgrade cluster

Solution
kubeadm upgrade apply v1.x.x

Check Kubectl version running on master nodes

Solution
kubectl version

Upgrade CNI

Solution
kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter.yaml

Restart kubelet on node 1

Solution
systemctl daemon-reload && systemctl restart kubelet

Check kubernetes version on node1

Solution
kubectl get nodes

Bring node1 back from maintainence mode

Solution
kubectl uncordon node1

Upgrade node 2 and 3

Solution

Delete all three nodes and close session

  1. click on first node and then DELETE
  2. Repeat same for second and third node
  3. click close session

image

Congratulations you have completed this lab

Let us know if you still have any question