这篇文章主要记录 k8s 集群的版本更新,版本更新是我们在维护集群中必然会遇到的一个问题。以下方式适用于使用 kubeadm 方式安装的集群。官方也有提供详细的更新教程,reference here
更新前的注意内容
官方文档中标注的在开始更新前的准备
You need to have a kubeadm Kubernetes cluster running version 1.xx.0 or later.
Swap must be disabled.
The cluster should use a static control plane and etcd pods or external etcd.
Make sure you read the release notes carefully.
Make sure to back up any important components, such as app-level state stored in a database. kubeadm upgrade does not touch your workloads, only components internal to Kubernetes, but backups are always a best practice.
补充一些更新前的操作
集群中的 pod 要处于正常运行的状态,这是因为更新时会运行一个健康检查的 pod,集群如果出现异常 pod,会退出更新。
$ sudo 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 -o yaml'[preflight] Running pre-flight checks.
[upgrade] Running cluster health checks
[upgrade] Fetching available versions to upgrade to
[upgrade/versions] Cluster version: v1.21.8
[upgrade/versions] kubeadm version: v1.22.5
I1230 17:11:03.706723 9208 version.go:255] remote version is much newer: v1.23.1; falling back to: stable-1.22
[upgrade/versions] Target version: v1.22.5
[upgrade/versions] Latest version in the v1.21 series: v1.21.8
Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
COMPONENT CURRENT TARGET
kubelet 4 x v1.21.8 v1.22.5
Upgrade to the latest stable version:
COMPONENT CURRENT TARGET
kube-apiserver v1.21.8 v1.22.5
kube-controller-manager v1.21.8 v1.22.5
kube-scheduler v1.21.8 v1.22.5
kube-proxy v1.21.8 v1.22.5
CoreDNS v1.8.0 v1.8.4
etcd 3.4.13-0 3.5.0-0
You can now apply the upgrade by executing the following command:
kubeadm upgrade apply v1.22.5
_____________________________________________________________________
The table below shows the current state of component configs as understood by this version of kubeadm.
Configs that have a "yes" mark in the "MANUAL UPGRADE REQUIRED" column require manual config upgrade or
resetting to kubeadm defaults before a successful upgrade can be performed. The version to manually
upgrade to is denoted in the "PREFERRED VERSION" column.
API GROUP CURRENT VERSION PREFERRED VERSION MANUAL UPGRADE REQUIRED
kubeproxy.config.k8s.io v1alpha1 v1alpha1 no
kubelet.config.k8s.io v1beta1 v1beta1 no
_____________________________________________________________________
按照上述提示操作,静待升级完成即可。
1
2
3
4
5
6
7
8
$ sudo kubeadm upgrade apply v1.22.5
# 执行成功后,会有类似以下输出(以下粘贴中省略了一部分输出)...
[upgrade/successful] SUCCESS! Your cluster was upgraded to "v1.22.5". Enjoy!
[upgrade/kubelet] Now that your control plane is upgraded, please proceed with upgrading your kubelets if you haven't already done so.