环境

系统: centos7.5.1804

k8s版本: 1.11.x

只适用于1.11.x版本升级到1.12.1

我的安装方式是kubeadm安装的,此方法不适用二进制等其他安装方式

1.主节点升级kubeadm

yum upgrade -y kubeadm --disableexcludes=kubernetes


2.主节点运行

kubeadm upgrade plan

输出如下

[preflight] Running pre-flight checks.
[upgrade] Making sure the cluster is healthy:
[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'
[upgrade] Fetching available versions to upgrade to
[upgrade/versions] Cluster version: v1.11.3
[upgrade/versions] kubeadm version: v1.12.0
[upgrade/versions] Latest stable version: v1.11.3
[upgrade/versions] Latest version in the v1.11 series: v1.11.3
[upgrade/versions] Latest experimental version: v1.13.0-alpha.0

Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
COMPONENT   CURRENT       AVAILABLE
Kubelet     2 x v1.11.1   v1.12.0
            1 x v1.11.3   v1.12.0

Upgrade to the latest experimental version:

COMPONENT            CURRENT   AVAILABLE
API Server           v1.11.3   v1.12.0
Controller Manager   v1.11.3   v1.12.0
Scheduler            v1.11.3   v1.12.0
Kube Proxy           v1.11.3   v1.12.0
CoreDNS              1.1.3     1.2.2
Etcd                 3.2.18    3.2.24

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

    kubeadm upgrade apply v1.12.0 

_____________________________________________________________________

3.选择要升级的版本然后运行下面的命令

kubeadm upgrade apply v1.12.0


升级主节点和其他节点

1.讲其他节点暂时分离集群 主节点

kubectl drain $NODE --ignore-daemonsets

主节点必须加入以下参数
--ignore-daemonsets

其他节点命令如下

kubectl drain $NODE

不加参数可能会无法退出集群,可以根据提示添加参数退出集群 在初主节点外的每个从节点升级kubelet

kubeadm upgrade node config --kubelet-version $(kubelet --version | cut -d ' ' -f 2)

重启kubelet

systemctl restart kubelet
将节点加入集群(在主上面操作)
kubectl uncordon $NODE

查看集群升级后的节点版本

kubectl get nodes


升级后的版本为1.12.1,升级成功!

欢迎留言