一、背景:
kubeadm部署的kubernetes集群进行升级,通常先升级控制节点,控制节点升级完成后再升级工作节点,本博文只升级了控制节点,工作节点按照相同的流程进行升级即可
环境说明:
主机名 | 节点 |
11.0.1.200 | k8s客户端操控节点 |
11.0.1.201 | master01 |
11.0.1.202 | node01 |
11.0.1.203 | node02 |
操作系统:Ubuntu 20.04.6 LTS
升级要求:将控制节点从1.27.0升级到1.27.1,etcd不做升级,从节点不做升级
二、操作流程
1) 将控制节点设置为不可调度
kubectl cordon master01
2) 驱逐控制节点上的pod
kubectl drain master01 --ignore-daemonsets --force --delete-emptydir-data
3) 切换至master01控制节点
ssh master01
#切换到管理员用户,否则加sudo也可以
sudo -i
4) 更新网络仓库
apt-get update
5) 查看kubeadm可安装版本
root@master01:~# apt-cache madison kubeadm | grep 1.27
kubeadm | 1.27.4-00 | https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 Packages
kubeadm | 1.27.3-00 | https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 Packages
kubeadm | 1.27.2-00 | https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 Packages
kubeadm | 1.27.1-00 | https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 Packages
kubeadm | 1.27.0-00 | https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 Packages
6) 安装kubeadm
root@master01:~# apt-get install kubeadm=1.27.1-00
# 验证
root@master01:~# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.1", GitCommit:"4c9411232e10168d7b050c49a1b59f6df9d7ea4b", GitTreeState:"clean", BuildDate:"2023-04-14T13:20:04Z", GoVersion:"go1.20.3", Compiler:"gc", Platform:"linux/amd64"}
7) 预升级集群
kubeadm upgrade plan v1.27.1
8) 升级集群
root@master01:~# kubeadm upgrade apply v1.27.1 --etcd-upgrade=false
[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/version] You have chosen to change the cluster version to "v1.27.1"
[upgrade/versions] Cluster version: v1.27.0
[upgrade/versions] kubeadm version: v1.27.1
[upgrade] Are you sure you want to proceed? [y/N]:
注意:升级成功标志
9) 升级kubelet
apt-get install kubelet=1.27.1-00
#验证
kubelet versopm
10) 升级kubectl
apt-get install kubectl=1.27.1-00
#验证版本
kubectl version
11) 恢复节点
kubectl uncordon master01
#验证
kubectl get nodes