此次升级是kubeadm安装的k8s
在升级之前你需要了解各版本间的关系:
通过查询命令行帮助:
$ kubeadm upgrade -h
Upgrade your cluster smoothly to a newer version with this command.
Usage:
kubeadm upgrade [flags]
kubeadm upgrade [command]
`
Available Commands:
apply Upgrade your Kubernetes cluster to the specified version.
diff Show what differences would be applied to existing static pod manifests. See also: kubeadm upgrade apply --dry-run
node Upgrade commands for a node in the cluster. Currently only supports upgrading the configuration, not the kubelet itself.
plan Check which versions are available to upgrade to and validate whether your current cluster is upgradeable. To skip the internet check, pass in the optional [version] parameter.
命令解析:
其中node子命令又支持如下子命令和选项:
$ kubeadm upgrade node -h
Upgrade commands for a node in the cluster. Currently only supports upgrading the configuration, not the kubelet itself.
Usage:
kubeadm upgrade node [flags]
kubeadm upgrade node [command]
Available Commands:
config Downloads the kubelet configuration from the cluster ConfigMap kubelet-config-1.X, where X is the minor version of the kubelet.
experimental-control-plane Upgrades the control plane instance deployed on this node. IMPORTANT. This command should be executed after executing `kubeadm upgrade apply` on another control plane instance
Flags:
-h, --help help for node
Global Flags:
--log-file string If non-empty, use this log file
--rootfs string [EXPERIMENTAL] The path to the 'real' host root filesystem.
--skip-headers If true, avoid header prefixes in the log messages
-v, --v Level number for the log level verbosity
命令解析:
kubectl get nodes
kubectl version
升级CNI插件。
这一步是可选的,查询CNI插件是否可以升级。
yum list --showduplicates kubeadm --disableexcludes=kubernetes
# 升级kubeadm版本
yum install kubeadm-1.18.13-0 kubelet-1.18.13-0 kubectl-1.18.13-0
# 安装完成之后 确认一下各个组件的版本 确保是你想要的
kubelet --version
kubectl version
kubeadm version
# 升级检查和方案
kubeadm upgrade plan
# 删除刚刚装的1.18
yum remove -y kubectl-1.18.13
yum -y remove kubelet-1.18.13-0.x86_64
yum install kubeadm-1.15.2-0 kubelet-1.15.2-0 kubectl-1.15.2-0 -y
kubeadm upgrade plan
kubeadm config view > /tmp/kubeadm-config.yaml
kubeadm upgrade apply v1.15.2
继续升级
报错了 ERROR CoreDNSUnsupportedPlugins]: there are unsupported plugins in the CoreDNS Corefile
网上说是因为coredns里的host模块的问题 需要注释掉
# edit configmap 并注释
kubectl edit cm coredns -n kube-system
继续尝试升级 依旧报错
there are NotReady control-planes in the cluster: [op-k8s-m001]
此时查看node状态会发现master 是notready
查看报错
journalctl -u kubelet | tail -n 300
临时解决的办法是给 /etc/cni/net.d/10-flannel.conflist 添加cniVersion字段
重启Node后将需要重做,终极办法是在Master上更新Flannel(新的版本带有cniVersion字段)或者修改Flannel的ConfigMap kubectl edit cm kube-flannel-cfg -n kube-system
,因为这个配置是Node加入时读取的。
继续升级
报错There are kubelets in this cluster that are too old that have these versions [v1.14.2]
升级node的kubelet
yum install kubelet-1.15.2-0 -y
systemctl daemon-reload
systemctl restart kubelet
systemctl status kubelet
继续升级
master成功升级到1.16.2
升级node到1.16.2
yum install kubelet-1.16.2-0 -y
systemctl daemon-reload
systemctl restart kubelet
systemctl status kubelet
升级master到1.17.2
yum install kubeadm-1.17.2-0 kubelet-1.17.2-0 kubectl-1.17.2-0 -y
kubeadm upgrade plan
kubeadm upgrade apply v1.17.2
升级node到1.17.2
yum install kubelet-1.17.2-0 -y
systemctl daemon-reload
systemctl restart kubelet
systemctl status kubelet
升级到1.18.2
master
yum install kubeadm-1.18.2-0 kubelet-1.18.2-0 kubectl-1.18.2-0 -y
kubeadm upgrade plan
kubeadm upgrade apply v1.18.2
升级node到1.18.2
yum install kubelet-1.18.2-0 -y
systemctl daemon-reload
systemctl restart kubelet
systemctl status kubelet
升级完成