The upgrade idea is to upgrade the control node first and then the working node after expelling the load and taking off the traffic.

1. View cluster version

1
2
3
4
kubectl version

Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.4", GitCommit:"e87da0bd6e03ec3fea7933c4b5263d151aafd07c", GitTreeState:"clean", BuildDate:"2021-02-18T16:12:00Z", GoVersion:"go1.15.8", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.0", GitCommit:"c2b5237ccd9c0f1d600d3072634ca66cefdf272f", GitTreeState:"clean", BuildDate:"2021-08-04T17:57:25Z", GoVersion:"go1.16.6", Compiler:"gc", Platform:"linux/amd64"}

The current version is 1.22. Since kubeadm does not allow cross-version upgrades, we are going to upgrade to 1.23.

2. Add Kubernetes installation source

CentOS operating system.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
cat > /etc/yum.repos.d/kubernetes.repo << EOF 
[kubernetes] 
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 
enabled=1 
gpgcheck=0 
epo_gpgcheck=0 
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg 
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg 
EOF

Ubuntu operating system.

1
2
3
4
5
6
apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - 
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update

3. Find the target version of kubeadm

1
2
3
4
yum list --showduplicates kubeadm --disableexcludes=kubernetes

...
kubeadm.x86_64              1.23.4-0             kubernetes

4. Upgrade Kubeadm

1
2
yum remove -y kubeadm
yum install -y kubeadm-1.23.4-0 --disableexcludes=kubernetes

5. View upgrade plan

Some error cases are ignored here, and the upgrade plan is forced to be viewed.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
kubeadm upgrade plan --ignore-preflight-errors=ControlPlaneNodesReady,CoreDNSUnsupportedPlugins,CoreDNSMigration

...
Upgrade to the latest stable version:

COMPONENT                 CURRENT   TARGET
kube-apiserver            v1.22.0   v1.23.4
kube-controller-manager   v1.22.0   v1.23.4
kube-scheduler            v1.22.0   v1.23.4
kube-proxy                v1.22.0   v1.23.4
CoreDNS                   v1.8.4    v1.8.6
etcd                      3.5.0-0   3.5.1-0

6. Pulling dependent mirrors

Pulling dependencies ahead of time will allow you to find unpullable images in advance and speed up the upgrade process. If you can’t pull the images, you can use the kubeadm config images list command to see the list of images, and then pull the images by the following way.

1
2
docker pull k8simage/kube-apiserver:v1.23.4
docker tag k8simage/kube-apiserver:v1.23.4 k8s.gcr.io/kube-apiserver:v1.23.4

Pulling directly from dependent mirrors.

1
2
3
4
5
6
7
8
9
kubeadm config images pull

[config/images] Pulled k8s.gcr.io/kube-apiserver:v1.23.4
[config/images] Pulled k8s.gcr.io/kube-controller-manager:v1.23.4
[config/images] Pulled k8s.gcr.io/kube-scheduler:v1.23.4
[config/images] Pulled k8s.gcr.io/kube-proxy:v1.23.4
[config/images] Pulled k8s.gcr.io/pause:3.6
[config/images] Pulled k8s.gcr.io/etcd:3.5.1-0
[config/images] Pulled k8s.gcr.io/coredns/coredns:v1.8.6

7. Start upgrading Kubernetes clusters

1
2
3
4
kubeadm upgrade apply v1.23.4 --ignore-preflight-errors=ControlPlaneNodesReady,CoreDNSUnsupportedPlugins,CoreDNSMigration

[upgrade/successful] SUCCESS! Your cluster was upgraded to "v1.23.4". Enjoy!
[upgrade/kubelet] Now that your control plane is upgraded, please proceed with upgrading your kubelets if you haven't already done so.

8. Upgrade kubectl and kubelet

1
yum install -y kubelet-1.23.4-0 kubectl-1.23.4-0 --disableexcludes=kubernetes