具體步驟可以參考kubernetes官網:https://kubernetes.io/zh-cn/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/
確定升級到哪個版本
示例是從同版本1.28.2 升級到1.28.7
所以使用作業系統的包管理器找到最新可按照的版本中,是否有需要的補丁版本
sudo yum list --showduplicates kubeadm --disableexcludes=kubernetes
點選檢視返回的版本資訊
[root@whdcinthe004 ~]# yum list --showduplicates kubeadm --disableexcludes=kubernetes
Last metadata expiration check: 1:30:29 ago on Wed 13 Mar 2024 08:22:56 AM CST.
Installed Packages
kubeadm.x86_64 1.28.2-0 @kubernetes
Available Packages
kubeadm.aarch64 1.28.0-150500.1.1 kubernetes
kubeadm.ppc64le 1.28.0-150500.1.1 kubernetes
kubeadm.s390x 1.28.0-150500.1.1 kubernetes
kubeadm.src 1.28.0-150500.1.1 kubernetes
kubeadm.x86_64 1.28.0-150500.1.1 kubernetes
kubeadm.aarch64 1.28.1-150500.1.1 kubernetes
kubeadm.ppc64le 1.28.1-150500.1.1 kubernetes
kubeadm.s390x 1.28.1-150500.1.1 kubernetes
kubeadm.src 1.28.1-150500.1.1 kubernetes
kubeadm.x86_64 1.28.1-150500.1.1 kubernetes
kubeadm.aarch64 1.28.2-150500.1.1 kubernetes
kubeadm.ppc64le 1.28.2-150500.1.1 kubernetes
kubeadm.s390x 1.28.2-150500.1.1 kubernetes
kubeadm.src 1.28.2-150500.1.1 kubernetes
kubeadm.x86_64 1.28.2-150500.1.1 kubernetes
kubeadm.aarch64 1.28.3-150500.1.1 kubernetes
kubeadm.ppc64le 1.28.3-150500.1.1 kubernetes
kubeadm.s390x 1.28.3-150500.1.1 kubernetes
kubeadm.src 1.28.3-150500.1.1 kubernetes
kubeadm.x86_64 1.28.3-150500.1.1 kubernetes
kubeadm.aarch64 1.28.4-150500.1.1 kubernetes
kubeadm.ppc64le 1.28.4-150500.1.1 kubernetes
kubeadm.s390x 1.28.4-150500.1.1 kubernetes
kubeadm.src 1.28.4-150500.1.1 kubernetes
kubeadm.x86_64 1.28.4-150500.1.1 kubernetes
kubeadm.aarch64 1.28.5-150500.1.1 kubernetes
kubeadm.ppc64le 1.28.5-150500.1.1 kubernetes
kubeadm.s390x 1.28.5-150500.1.1 kubernetes
kubeadm.src 1.28.5-150500.1.1 kubernetes
kubeadm.x86_64 1.28.5-150500.1.1 kubernetes
kubeadm.aarch64 1.28.6-150500.1.1 kubernetes
kubeadm.ppc64le 1.28.6-150500.1.1 kubernetes
kubeadm.s390x 1.28.6-150500.1.1 kubernetes
kubeadm.src 1.28.6-150500.1.1 kubernetes
kubeadm.x86_64 1.28.6-150500.1.1 kubernetes
kubeadm.aarch64 1.28.7-150500.1.1 kubernetes
kubeadm.ppc64le 1.28.7-150500.1.1 kubernetes
kubeadm.s390x 1.28.7-150500.1.1 kubernetes
kubeadm.src 1.28.7-150500.1.1 kubernetes
kubeadm.x86_64 1.28.7-150500.1.1
升級控制平面節點kubeadm
控制面節點上的升級過程應該每次處理一個節點。 首先選擇一個要先行升級的控制面節點。該節點上必須擁有 /etc/kubernetes/admin.conf
檔案。
1. 升級kubeadm:
# 按照所需要版本 1.28.7-* 中的 x
sudo yum install -y kubeadm-'1.28.7-*' --disableexcludes=kubernetes
2. 驗證下載操作正常,並且 kubeadm 版本正確:
[root@whdcinthe004 ~]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"28", GitVersion:"v1.28.7", GitCommit:"c8dcb00be9961ec36d141d2e4103f85f92bcf291", GitTreeState:"clean", BuildDate:"2024-02-14T10:39:01Z", GoVersion:"go1.21.7", Compiler:"gc", Platform:"linux/amd64"}
3.驗證升級計劃
sudo kubeadm upgrade plan
4.升級kubeadm
sudo kubeadm upgrade apply v1.28.7
#要注意,會提問你是否要保護,記得輸入y
#[upgrade] Are you sure you want to proceed? [y/N]: y
結束後,你會看到:
[upgrade/successful] SUCCESS! Your cluster was upgraded to "v1.28.7". Enjoy!
[upgrade/kubelet] Now that your control plane is upgraded, please proceed with upgrading your kubelets if you haven't already done so.
保護節點
將節點標記為不可排程並驅逐所有負載,準備節點的維護:
kubectl drain <node-to-drain> --ignore-daemonsets
#node-to-drain指的節點名稱,比如我這裡,需要替換命令為 kubectl drain whdcinthe004.cn.infra --ignore-daemonsets
升級Kubelet kubectl
- 命令
yum install -y kubelet-'1.28.7-*' kubectl-'1.28.7-*' --disableexcludes=kubernetes
- 重啟kubelet
sudo systemctl daemon-reload
sudo systemctl restart kubelet
解除節點保護
kubectl uncordon <node-to-uncordon>
# kubectl uncordon whdcinthe004.cn.infra
驗證叢集狀態:
kubectl get nodes