[Kubernetes (K8S) Kubespray] Use Kubespray to upgrade the exist kubernetes (K8S) cluster

Upgrade the exist kubernetes (K8S) cluster

Kubespray handles upgrades the same way it handles initial deployment. That is to say that each component is laid down in a fixed order.

Usages

First, check current all node version(v.1.21.4):

1
2
3
4
5
6
7
8
9
# kubectl get nodes
NAME STATUS ROLES AGE VERSION
node1 Ready control-plane,master 8d v1.21.4
node2 Ready control-plane,master 8d v1.21.4
node3 Ready control-plane,master 5d v1.21.4

# kubectl version
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.4", GitCommit:"3cce4a82b44f032d0cd1a1790e6d2f5a55d20aae", GitTreeState:"clean", BuildDate:"2021-08-11T18:16:05Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.4", GitCommit:"3cce4a82b44f032d0cd1a1790e6d2f5a55d20aae", GitTreeState:"clean", BuildDate:"2021-08-11T18:10:22Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"linux/amd64"}

Graceful upgrade

Kubespray supports cordon, drain and uncordoning of nodes when performing a cluster upgrade. There is a separate playbook used for this purpose. It is important to note that upgrade-cluster.yml can only be used for upgrading an existing cluster. That means there must be at least 1 kube_control_plane already deployed.

1
# ansible-playbook -i inventory/mycluster/hosts.yaml --private-key ~/.ssh/id_rsa upgrade-cluster.yml -e kube_version=v1.22.1 -b

You can use --limit=NODE_NAME to limit Kubespray to avoid disturbing other nodes in the cluster.

1
# ansible-playbook -i inventory/mycluster/hosts.yaml --private-key ~/.ssh/id_rsa upgrade-cluster.yml -e kube_version=v1.22.1 -b --limit=node3

Check current all node version.

1
2
3
4
5
6
7
8
9
# kubectl get nodes
NAME STATUS ROLES AGE VERSION
node1 Ready control-plane,master 8d v1.22.1
node2 Ready control-plane,master 8d v1.22.1
node3 Ready control-plane,master 5d v1.22.1

# kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.1", GitCommit:"632ed300f2c34f6d6d15ca4cef3d3c7073412212", GitTreeState:"clean", BuildDate:"2021-08-19T15:45:37Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.1", GitCommit:"632ed300f2c34f6d6d15ca4cef3d3c7073412212", GitTreeState:"clean", BuildDate:"2021-08-19T15:39:34Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"linux/amd64"}

References

[1] Upgrades - https://kubespray.io/#/docs/upgrades

[2] Getting started - https://kubespray.io/#/docs/getting-started

[3] kubernetes-sigs/kubespray: Deploy a Production Ready Kubernetes Cluster - https://github.com/kubernetes-sigs/kubespray

[4] Deploy a Production Ready Kubernetes Cluster | Readme - https://kubespray.io/

[5] Ansible is Simple IT Automation - https://www.ansible.com/

[6] Kubernetes - https://kubernetes.io/