Kubernetes升级强烈建议参考官方文档,看英文没有问题,下面的可以忽略了,我这里可以看作个人翻译笔记。我的环境是离线升级,对应的rpm包和docker镜像包提前准备好了,具体方法可以参看本系列的前面3个章节。
官方文档地址:https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/
# replace x in 1.17.x-0 with the latest patch version
sudo um install -y kubeadm-1.17.x-0 --disableexcludes=kubernetes核对kubeadm的版本
sudo kubeadm version# replace <cp-node-name> with the name of your control plane node
sudo kubectl drain <cp-node-name> --ignore-daemonsetssudo 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 -oyaml‘
[preflight] Running pre-flight checks.
[upgrade] Making sure the cluster is healthy:
[upgrade] Fetching available versions to upgrade to
[upgrade/versions] Cluster version: v1.16.0
[upgrade/versions] kubeadm version: v1.17.0
Components that must be upgraded manually after you have upgraded the control plane with ‘kubeadm upgrade apply‘:
COMPONENT   CURRENT       AVAILABLE
Kubelet     1 x v1.16.0   v1.17.0
Upgrade to the latest version in the v1.16 series:
COMPONENT            CURRENT   AVAILABLE
API Server           v1.16.0   v1.17.0
Controller Manager   v1.16.0   v1.17.0
Scheduler            v1.16.0   v1.17.0
Kube Proxy           v1.16.0   v1.17.0
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.0上述命令只是检查集群是否能够升级,以及可以升级的版本。
# replace x with the patch version you picked for this upgrade
sudo kubeadm upgrade apply v1.17.x执行后可以在末尾看见
......
[upgrade/successful] SUCCESS! Your cluster was upgraded to "v1.17.0". Enjoy!
[upgrade/kubelet] Now that your control plane is upgraded, please proceed with upgrading your kubelets if you haven‘t already done so.如flannel,由于此次升级网络插件没有变化,因此没有升级。
# replace <cp-node-name> with the name of your control plane node
sudo kubectl uncordon <cp-node-name>直接执行升级命令:
sudo kubeadm upgrade node# replace x in 1.17.x-0 with the latest patch version
sudo yum install -y kubelet-1.17.x-0 kubectl-1.17.x-0 --disableexcludes=kubernetes重新加载kubelet并重启
sudo systemctl daemon-reload
sudo systemctl restart kubelet# replace x in 1.17.x-0 with the latest patch version
sudo yum install -y kubeadm-1.17.x-0 --disableexcludes=kubernetes# replace <node-to-drain> with the name of your node you are draining
sudo kubectl drain <node-to-drain> --ignore-daemonsets上述命令执行后可能出现如下类似输出:
node/ip-172-31-85-18 cordoned
WARNING: ignoring DaemonSet-managed Pods: kube-system/kube-proxy-dj7d7, kube-system/weave-net-z65qx
node/ip-172-31-85-18 drainedsudo kubeadm upgrade node# replace x in 1.17.x-0 with the latest patch version
yum install -y kubelet-1.17.x-0 kubectl-1.17.x-0 --disableexcludes=kubernetes重载并重启kubectl
sudo systemctl daemon-reload
sudo systemctl restart kubelet# replace <node-to-drain> with the name of your node 
sudo kubectl uncordon <node-to-drain>sudo kubectl get nodes原文:https://blog.51cto.com/huanghai/2480733