k8s版本升级1.19.8升级为1.20.2
文档:https://v1-18.docs.kubernetes.io/zh/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/#%E5%8D%87%E7%BA%A7-kubelet-%E4%B8%8E-kubectl
一、升级master节点
1、查看版本列表
yum list --showduplicates kubeadm --disableexcludes=kubernetes
2、下载新版本的kubeadm
#下载新版本的kubeadm [root@master ~]# yum install -y kubeadm-1.20.2 --disableexcludes=kubernetes #验证kubeadm版本 [root@master ~]# kubeadm version kubeadm version: &version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.2", GitCommit:"faecb196815e248d3ecfb03c680a4507229c2a56", GitTreeState:"clean", BuildDate:"2021-01-13T13:25:59Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
3、腾空升级服务器的节点
[root@master ~]# kubectl drain master --ignore-daemonsets node/master cordoned WARNING: ignoring DaemonSet-managed Pods: kube-system/calico-node-rdqxb, kube-system/kube-proxy-78lws
4、验证升级计划
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | [root@master ~] # 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.19.8 [upgrade /versions ] kubeadm version: v1.20.2 [upgrade /versions ] Latest stable version: v1.20.4 [upgrade /versions ] Latest stable version: v1.20.4 [upgrade /versions ] Latest version in the v1.19 series: v1.19.8 [upgrade /versions ] Latest version in the v1.19 series: v1.19.8 Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply' : COMPONENT CURRENT AVAILABLE kubelet 2 x v1.19.8 v1.20.4 Upgrade to the latest stable version: COMPONENT CURRENT AVAILABLE kube-apiserver v1.19.8 v1.20.4 kube-controller-manager v1.19.8 v1.20.4 kube-scheduler v1.19.8 v1.20.4 kube-proxy v1.19.8 v1.20.4 CoreDNS 1.7.0 1.7.0 etcd 3.4.13-0 3.4.13-0 You can now apply the upgrade by executing the following command : kubeadm upgrade apply v1.20.4 Note: Before you can perform this upgrade, you have to update kubeadm to v1.20.4. _____________________________________________________________________ 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 _____________________________________________________________________ |
5、选择要升级到的目标版本
如果不是第一个升级的master的话执行:kubeadm upgrade node
只有第一个升级的master执行:kubeadm upgrade apply操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | [root@master ~] # kubeadm upgrade apply v1.20.2 [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 /version ] You have chosen to change the cluster version to "v1.20.2" [upgrade /versions ] Cluster version: v1.19.8 [upgrade /versions ] kubeadm version: v1.20.2 [upgrade /confirm ] Are you sure you want to proceed with the upgrade? [y /N ]: y [upgrade /prepull ] Pulling images required for setting up a Kubernetes cluster [upgrade /prepull ] This might take a minute or two, depending on the speed of your internet connection [upgrade /prepull ] You can also perform this action in beforehand using 'kubeadm config images pull' [upgrade /apply ] Upgrading your Static Pod-hosted control plane to version "v1.20.2" ... Static pod: kube-apiserver-master hash : 719a832e897de592e91b599477986810 Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 [upgrade /etcd ] Upgrading to TLS for etcd Static pod: etcd-master hash : ae851f5ba1b074f38b4de05cb1aadcd4 [upgrade /staticpods ] Preparing for "etcd" upgrade [upgrade /staticpods ] Renewing etcd-server certificate [upgrade /staticpods ] Renewing etcd-peer certificate [upgrade /staticpods ] Renewing etcd-healthcheck-client certificate [upgrade /staticpods ] Moved new manifest to "/etc/kubernetes/manifests/etcd.yaml" and backed up old manifest to "/etc/kubernetes/tmp/kubeadm-backup-manifests-2021-02-27-16-28-09/etcd.yaml" [upgrade /staticpods ] Waiting for the kubelet to restart the component [upgrade /staticpods ] This might take a minute or longer depending on the component /version gap (timeout 5m0s) Static pod: etcd-master hash : ae851f5ba1b074f38b4de05cb1aadcd4 Static pod: etcd-master hash : ae851f5ba1b074f38b4de05cb1aadcd4 Static pod: etcd-master hash : 3c6eed0df938b588a1cbefd450e3bcbd [apiclient] Found 1 Pods for label selector component=etcd [upgrade /staticpods ] Component "etcd" upgraded successfully! [upgrade /etcd ] Waiting for etcd to become available [upgrade /staticpods ] Writing new Static Pod manifests to "/etc/kubernetes/tmp/kubeadm-upgraded-manifests520412682" [upgrade /staticpods ] Preparing for "kube-apiserver" upgrade [upgrade /staticpods ] Renewing apiserver certificate [upgrade /staticpods ] Renewing apiserver-kubelet-client certificate [upgrade /staticpods ] Renewing front-proxy-client certificate [upgrade /staticpods ] Renewing apiserver-etcd-client certificate [upgrade /staticpods ] Moved new manifest to "/etc/kubernetes/manifests/kube-apiserver.yaml" and backed up old manifest to "/etc/kubernetes/tmp/kubeadm-backup-manifests-2021-02-27-16-28-09/kube-apiserver.yaml" [upgrade /staticpods ] Waiting for the kubelet to restart the component [upgrade /staticpods ] This might take a minute or longer depending on the component /version gap (timeout 5m0s) Static pod: kube-apiserver-master hash : 719a832e897de592e91b599477986810 Static pod: kube-apiserver-master hash : 719a832e897de592e91b599477986810 Static pod: kube-apiserver-master hash : d07bc053b450ce24a8c1085f6d68d40d [apiclient] Found 1 Pods for label selector component=kube-apiserver [upgrade /staticpods ] Component "kube-apiserver" upgraded successfully! [upgrade /staticpods ] Preparing for "kube-controller-manager" upgrade [upgrade /staticpods ] Renewing controller-manager.conf certificate [upgrade /staticpods ] Moved new manifest to "/etc/kubernetes/manifests/kube-controller-manager.yaml" and backed up old manifest to "/etc/kubernetes/tmp/kubeadm-backup-manifests-2021-02-27-16-28-09/kube-controller-manager.yaml" [upgrade /staticpods ] Waiting for the kubelet to restart the component [upgrade /staticpods ] This might take a minute or longer depending on the component /version gap (timeout 5m0s) Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 4331a0b9c79c549b926db152caaa327d Static pod: kube-controller-manager-master hash : 0c91bb51488c4e7f19222042dd8bb76d [apiclient] Found 1 Pods for label selector component=kube-controller-manager [upgrade /staticpods ] Component "kube-controller-manager" upgraded successfully! [upgrade /staticpods ] Preparing for "kube-scheduler" upgrade [upgrade /staticpods ] Renewing scheduler.conf certificate [upgrade /staticpods ] Moved new manifest to "/etc/kubernetes/manifests/kube-scheduler.yaml" and backed up old manifest to "/etc/kubernetes/tmp/kubeadm-backup-manifests-2021-02-27-16-28-09/kube-scheduler.yaml" [upgrade /staticpods ] Waiting for the kubelet to restart the component [upgrade /staticpods ] This might take a minute or longer depending on the component /version gap (timeout 5m0s) Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : 6dbdba13d86ee08fe701bc482cc2c039 Static pod: kube-scheduler-master hash : bd4765a68b7a13f0c7d6b33332e0b273 [apiclient] Found 1 Pods for label selector component=kube-scheduler [upgrade /staticpods ] Component "kube-scheduler" upgraded successfully! [upgrade /postupgrade ] Applying label node-role.kubernetes.io /control-plane = '' to Nodes with label node-role.kubernetes.io /master = '' (deprecated) [upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace [kubelet] Creating a ConfigMap "kubelet-config-1.20" in namespace kube-system with the configuration for the kubelets in the cluster [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" [bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes [bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials [bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token [bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster [addons] Applied essential addon: CoreDNS [addons] Applied essential addon: kube-proxy [upgrade /successful ] SUCCESS! Your cluster was upgraded to "v1.20.2" . Enjoy! [upgrade /kubelet ] Now that your control plane is upgraded, please proceed with upgrading your kubelets if you haven't already done so. |
6、取消对控制面节点的保护
1 | [root@master ~] # kubectl uncordon master |
7、升级 kubelet 和 kubectl
1 2 3 4 5 | [root@master ~] # yum install -y kubelet-1.20.2 kubectl-1.20.2 --disableexcludes=kubernetes #重启 kubelet [root@master ~] # systemctl daemon-reload [root@master ~] # systemctl restart kubelet |
二、升级工作节点(node节点)
1、升级 kubeadm
1 | [root@node1 ~] # yum install -y kubeadm-1.20.2 --disableexcludes=kubernetes |
2、保护节点
1 | [root@master ~] # kubectl drain node1 --ignore-daemonsets |
3、升级 kubelet 配置
1 | [root@node1 ~] # kubeadm upgrade node |
4、升级 kubelet 与 kubectl
1 2 3 4 5 | [root@node1 ~] # yum install -y kubelet-1.20.2 kubectl-1.20.2 --disableexcludes=kubernetes #重启 kubelet [root@node1 ~] # systemctl daemon-reload [root@node1 ~] # systemctl restart kubelet |
5、取消对节点的保护
1 | [root@master ~] # kubectl uncordon node1 |
三、验证集群
1 2 3 4 | [root@master ~] # kubectl get nodes NAME STATUS ROLES AGE VERSION master Ready control-plane,master 68m v1.20.2 node1 Ready <none> 67m v1.20.2 |
分类:
kubernetes
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律