一、查看k8s当前版本号及最新版本
1.1、查看当前集群节点数和版本号
kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 129d v1.16.0
node1 Ready <none> 129d v1.16.0
node2 Ready <none> 129d v1.16.0
1.2、查看服务端和客户端版本号
kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:27:17Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
1.3、查看仓库集群版本
yum list --showduplicates kubeadm --disableexcludes=kubernetes
二、升级kubeadm版本并查看集群是否满足升级需求
2.1、升级kubeadm版本
yum install -y kubeadm-1.17.0-0 --disableexcludes=kubernetes
2.2、查看升级后的kubeadm版本
kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:17:50Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
三、查看集群是否可以升级和升级后各组件的版本信息
kubeadm upgrade plan
Upgrade to the latest stable version:
COMPONENT CURRENT AVAILABLE
API Server v1.16.0 v1.17.17
Controller Manager v1.16.0 v1.17.17
Scheduler v1.16.0 v1.17.17
Kube Proxy v1.16.0 v1.17.17
CoreDNS 1.6.2 1.6.5
Etcd 3.3.15 3.4.3-0
You can now apply the upgrade by executing the following command:
kubeadm upgrade apply v1.17.17
Note: Before you can perform this upgrade, you have to update kubeadm to v1.17.17.
You can now apply the upgrade by executing the following command翻译成中文就是现在可以通过执行以下命令来应用升级,也就是可以升级。
四、升级k8s集群(master节点)
kubeadm upgrade apply v1.17.0 -v 5
执行完此命令后会有个提示Are you sure you want to proceed with the upgrade? [y/N]翻译成中文就是 您确定要继续升级吗?[是/否]此时选择y即可
升级完成后结尾打印的日志会有一行[upgrade/successful] SUCCESS! Your cluster was upgraded to "v1.17.0". Enjoy!类似的信息,翻译成中文就是 [升级/成功]成功!您的群集已升级到“v1.17.0”。享受
此时master就升级成功了!
如果有多个master节点,升级其它master节点(单个master可以忽略)
4.1、测试升级过程
kubeadm upgrade plan
测试结尾提示Latest version in the v1.16 series: v1.17.0意为v1中的最新版本。16系列:v1证明升级没有问题
4.2、升级其它master节点
kubeadm upgrade node
升级完成后会在屏幕上打印出The configuration for this node was successfully updated!意为此节点的配置已成功更新!
4.3、升级所有master节点的kubelet和kubectl(单个master忽略)
yum install -y kubelet-1.17.0 kubectl-1.17.0 --disableexcludes=kubernetes
systemctl daemon-reload
systemctl restart kubelet
五、在所有node节点升级kubeadm组件(在所有node节点执行)
yum install -y kubeadm-1.17.0 --disableexcludes=kubernetes
六、将node节点标记为不可调试,维护节点升级(在master执行)
kubectl drain node1 --ignore-daemonsets
先升级k8s02节点,如果多节点要重复升级,每个节点都要执行,如果报错根据提示添加--delete-local-data参数
验证是否标记为不可调试:
kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 129d v1.16.0
node1 Ready,SchedulingDisabled <none> 129d v1.16.0
node2 Ready <none> 129d v1.16.0
看到node1后面标记了SchedulingDisabled参数就代表标记成功
七、在node1节点升级kubelet和kubectl
kubeadm upgrade node
yum install -y kubelet-1.17.0 kubectl-1.17.0 --disableexcludes=kubernetes
重载配置文件
systemctl daemon-reload
重启kubelet
systemctl restart kubelet
在master节点恢复node1节点的调试策略
kubectl uncordon node1
剩余节点按照步骤五至步骤七升级即可!
踩坑总结:
1、升级完成后可能会遇到kube-system命名空间中的corednsPod起不来,查看Pod详细信息时:
skipping: network is not ready: runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized的
报cni的网络未初始化的错误
解决方法:(重新安装flannel)
下载官方flannel的yml的文件
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
然后执行下这个文件
kubectl apply -f kube-flannel.yml
这时可能会遇到多个flannel相关的Pod,查询flannel的ds控制器发现多了一个名为amd的flannel控制器,把这个控制器删除即可,当然不删除也可以正常使用。
2、成功升级master后执行kubectl get node时发现master还在上个版本且一直没升级,查看kubectl version发现Client Version的版本一直没升上去。
解决方法:
手动安装下客户端组件:
yum install -y kubelet-1.17.0 kubectl-1.17.0 --disableexcludes=kubernetes
重载配置文件
systemctl daemon-reload
重启kubelet
systemctl restart kubelet
仅登录用户可评论,点击 登录