How to upgrade kubernetes
To upgrade kubernetes I will 2 steps to implement it.
- Upgrade master node
- Upgrade worker nodes
Master node upgrade process
Check out the current kubeadm and kubelet version
First thing first, login the master node with ssh.
1
2
3
4
5
6
7
8
| kubeadm version
kubectl --version
## Running result
kubelet --version
Kubernetes v1.23.10
kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.10", GitCommit:"7e54d50d3012cf3389e43b096ba35300f36e0817", GitTreeState:"clean", BuildDate:"2022-08-17T18:31:47Z", GoVersion:"go1.17.13", Compiler:"gc", Platform:"linux/amd64"}
|
Install the new kubeadm version
We will upgrade kubernetes from v1.23.10-00 to 1.23.11-00
1
2
3
4
5
6
7
8
9
10
11
12
13
| sudo su
# Update apt list
apt update
# Check the latest version available
apt-cache madison kubeadm
apt-mark unhold kubeadm && \
apt-get update && apt-get install -y kubeadm=1.23.11-00 && \
apt-mark hold kubeadm
# Check kubeadm version
kubeadm version
|
Plan the kubeadm upgrade
Apply the kubeadm upgrade
1
| kubeadm upgrade apply v1.23.11
|
Cordon the node
1
2
3
4
| # check nodes name
kubectl get nodes
# drain the master nodes named 'ubuntu-k8s-master'
kubectl drain ubuntu-k8s-master --ignore-daemonsets
|
Upgrade the kubelet and kubectl
1
2
3
4
5
6
7
| apt-mark unhold kubelet kubectl && \
apt-get update && apt-get install -y kubelet=1.23.11-00 kubectl=1.23.11-00 && \
apt-mark hold kubelet kubectl
# Restart the kubelet
sudo systemctl daemon-reload
sudo systemctl restart kubelet
|
Uncordon the node
1
| kubectl uncordon ubuntu-k8s-master
|
Upgrade Worker Nodes
Check out the current kubeadm and kubelet version
1
2
| kubeadm version
kubelet --version
|
Install the new kubeadm version
1
2
3
4
| sudo su
apt-mark unhold kubeadm && \
apt-get update && apt-get install -y kubeadm=1.23.11-00 && \
apt-mark hold kubeadm
|
Plan the kubeadm upgrade
Apply the kubeadm upgrade
cordon the worker node
1
| kubectl drain ubuntu-k8s-node01
|
Upgrade the kubelet
1
2
3
4
5
6
7
| apt-mark unhold kubelet kubectl && \
apt-get update && apt-get install -y kubelet=1.23.11-00 kubectl=1.23.11-00 && \
apt-mark hold kubelet kubectl
# Restart the kubelet for the changes to take effect:
sudo systemctl daemon-reload
sudo systemctl restart kubelet
|
uncordon the node
1
| kubectl uncordon ubuntu-k8s-node01
|
Exit the worker node