1. 版本介绍

了解kubernetes版本的命名:x.y.z
x—主版本号
y—次版本号
z—补丁号

升级kubernetes的时候,是不能跨版本升级的:
1.y — 1.y+1

不能够
1.y — 1.y+2

2. 更新流程

先更新master再更新worker
1.先更新kubeadm
2.把节点设置drain
3.更新组件
4.更新kubelet、kubectl
5.把节点恢复正常

3. 查看仓库支持的版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@node001 ~]# yum list --showduplicates kubeadm --disableexcludes=kubernetes
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
kubeadm.x86_64 1.24.2-0 @kubernetes
Available Packages
kubeadm.x86_64 1.6.0-0 kubernetes
kubeadm.x86_64 1.6.1-0 kubernetes
...
kubeadm.x86_64 1.23.8-0 kubernetes
kubeadm.x86_64 1.23.9-0 kubernetes
kubeadm.x86_64 1.23.10-0 kubernetes
kubeadm.x86_64 1.24.0-0 kubernetes
kubeadm.x86_64 1.24.1-0 kubernetes
kubeadm.x86_64 1.24.2-0 kubernetes
kubeadm.x86_64 1.24.3-0 kubernetes
kubeadm.x86_64 1.24.4-0 kubernetes
kubeadm.x86_64 1.25.0-0 kubernetes

4. 升级master001节点

升级到1.24.4

1
[root@node001 ~]# yum install -y kubeadm-1.24.4-0 --disableexcludes=kubernetes

4.1 查看升级变更

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[root@node001 ~]# kubeadm upgrade plan
[upgrade/config] Making sure the configuration is correct:
[upgrade/config] Reading configuration from the cluster...
[upgrade/config] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[preflight] Running pre-flight checks.
[upgrade] Running cluster health checks
[upgrade] Fetching available versions to upgrade to
[upgrade/versions] Cluster version: v1.24.2
[upgrade/versions] kubeadm version: v1.24.4
I0907 02:28:59.947040 14493 version.go:255] remote version is much newer: v1.25.0; falling back to: stable-1.24
[upgrade/versions] Target version: v1.24.4
[upgrade/versions] Latest version in the v1.24 series: v1.24.4

Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
COMPONENT CURRENT TARGET
kubelet 3 x v1.24.2 v1.24.4

Upgrade to the latest version in the v1.24 series:

COMPONENT CURRENT TARGET
kube-apiserver v1.24.2 v1.24.4
kube-controller-manager v1.24.2 v1.24.4
kube-scheduler v1.24.2 v1.24.4
kube-proxy v1.24.2 v1.24.4
CoreDNS v1.8.6 v1.8.6
etcd 3.5.3-0 3.5.3-0

You can now apply the upgrade by executing the following command:

kubeadm upgrade apply v1.24.4

_____________________________________________________________________


The table below shows the current state of component configs as understood by this version of kubeadm.
Configs that have a "yes" mark in the "MANUAL UPGRADE REQUIRED" column require manual config upgrade or
resetting to kubeadm defaults before a successful upgrade can be performed. The version to manually
upgrade to is denoted in the "PREFERRED VERSION" column.

API GROUP CURRENT VERSION PREFERRED VERSION MANUAL UPGRADE REQUIRED
kubeproxy.config.k8s.io v1alpha1 v1alpha1 no
kubelet.config.k8s.io v1beta1 v1beta1 no
_____________________________________________________________________

4.2 维护节点

1
2
3
4
5
6
7
8
9
10
[root@node001 ~]# kubectl drain node001 --ignore-daemonsets 
node/node001 already cordoned
WARNING: ignoring DaemonSet-managed Pods: kube-system/calico-node-wb8pd, kube-system/kube-proxy-xhhtf
evicting pod kube-system/coredns-74586cf9b6-z6nn9
evicting pod kube-system/calico-kube-controllers-6799f5f4b4-jfclq
evicting pod kube-system/coredns-74586cf9b6-224q9
pod/calico-kube-controllers-6799f5f4b4-jfclq evicted
pod/coredns-74586cf9b6-z6nn9 evicted
pod/coredns-74586cf9b6-224q9 evicted
node/node001 drained

查看节点

1
2
3
4
5
[root@node001 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
node001 Ready,SchedulingDisabled control-plane 27h v1.24.2
node002 Ready <none> 27h v1.24.2
node003 Ready <none> 27h v1.24.2

4.3 更新master001节点

1
[root@node001 ~]# kubeadm upgrade apply v1.24.2 --etcd-upgrade=false

第一个master节点需要执行,其他master和worker不需要执行。

4.4 升级kubelet和kubectl

1
[root@node001 ~]# yum install -y kubelet-1.24.4-0 kubectl-1.24.4-0 --disableexcludes=kubernetes

4.5 重启kubelet

1
[root@node001 ~]# systemctl daemon-reload ;systemctl restart kubelet

4.6 查看节点版本

node001已更新到1.24.4

1
2
3
4
5
[root@node001 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
node001 Ready,SchedulingDisabled control-plane 28h v1.24.4
node002 Ready <none> 28h v1.24.2
node003 Ready <none> 27h v1.24.2

4.7 取消污点

1
[root@node001 ~]# kubectl uncordon node001

5. 升级worker节点

5.1 升级kubeadm

1
2
[root@node002 ~]# yum install -y kubeadm-1.24.4-0 --disableexcludes=kubernetes
[root@node003 ~]# yum install -y kubeadm-1.24.4-0 --disableexcludes=kubernetes

5.2 维护节点

1
[root@node001 ~]# kubectl drain node002 --ignore-daemonsets 

5.3 升级节点

1
[root@node002 ~]# kubeadm upgrade node

5.4 升级kubelet和kubectl

1
[root@node002 ~]# yum install -y kubelet-1.24.4-0 kubectl-1.24.4-0 --disableexcludes=kubernetes

5.5 重启kubelet

1
[root@node002 ~]# systemctl daemon-reload ;systemctl restart kubelet

5.6 取消污点

1
[root@node001 ~]# kubectl uncordon node002

5.7 查看节点版本

1
2
3
4
5
[root@node001 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
node001 Ready control-plane 28h v1.24.4
node002 Ready <none> 28h v1.24.4
node003 Ready,SchedulingDisabled <none> 27h v1.24.2