当前位置:   article > 正文

Kubernetes版本升级方法

kubernetes版本升级

这里主要是介绍kubernetes的版本升级方法,从v1.22.3升级到v1.22.17版本,根据kubernetes要求,在升级过程中要想把这个组件升级到v1.22.17,先要把kubeadm升级到v1.22.17版本,然后才能升级各个组件

一、环境

CentOS Linux release 7.7.1908 (Core) 3.10.0-1062.el7.x86_64

kubeadm-1.22.3-0.x86_64

kubelet-1.22.3-0.x86_64

kubectl-1.22.3-0.x86_64

  1. # kubectl get nodes
  2. NAME STATUS ROLES AGE VERSION
  3. k8s-master01 Ready control-plane 105d v1.22.3
  4. k8s-master02 Ready control-plane 105d v1.22.3
  5. k8s-master03 Ready control-plane 105d v1.22.3
  6. k8s-node01 Ready <none> 24d v1.22.3
  7. k8s-node02 Ready <none> 103d v1.22.3
  8. k8s-node03 Ready <none> 105d v1.22.3

二、先把要升级的节点设置为不可能调度

  1. #kubectl cordon k8s-master02
  2. node/k8s-master02 cordoned
  3. # kubectl get nodes
  4. NAME STATUS ROLES AGE VERSION
  5. k8s-master01 Ready control-plane 105d v1.22.17
  6. k8s-master02 Ready,SchedulingDisabled control-plane 105d v1.22.17
  7. k8s-master03 Ready control-plane 105d v1.22.17
  8. k8s-node01 Ready <none> 24d v1.22.17
  9. k8s-node02 Ready <none> 103d v1.22.17
  10. k8s-node03 Ready <none> 105d v1.22.17

三、把要升级的节点上的服务驱逐到别的节点上

  1. # kubectl drain k8s-master02 --ignore-daemonsets --force
  2. node/k8s-master02 already cordoned
  3. WARNING: ignoring DaemonSet-managed Pods: devops/node-exporter-2bjln, kube-flannel/kube-flannel-ds-dsjvk, kube-system/kube-proxy-kq56m
  4. evicting pod ingress-nginx/ingress-nginx-controller-55888bbc94-5h7mp
  5. pod/ingress-nginx-controller-55888bbc94-5h7mp evicted
  6. node/k8s-master02 evicted

四、查看kueadm的所有版本

1、使用阿里云的仓库

  1. cat >/etc/yum.repos.d/kubernetes.repo.bak <<EOF
  2. [kubernetes]
  3. name=Kubernetes
  4. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
  5. enabled=1
  6. gpgcheck=1
  7. repo_gpgcheck=1
  8. gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
  9. EOF

2、列出当前的所有版本

#这可以列出所有的版本,我只贴出一部分

  1. #yum list kubeadm.x86_64 --showduplicates
  2. kubeadm.x86_64 1.21.12-0 kubernetes
  3. kubeadm.x86_64 1.21.13-0 kubernetes
  4. kubeadm.x86_64 1.21.14-0 kubernetes
  5. kubeadm.x86_64 1.22.0-0 kubernetes
  6. kubeadm.x86_64 1.22.1-0 kubernetes
  7. kubeadm.x86_64 1.22.2-0 kubernetes
  8. kubeadm.x86_64 1.22.3-0 kubernetes
  9. kubeadm.x86_64 1.22.4-0 kubernetes
  10. kubeadm.x86_64 1.22.5-0 kubernetes
  11. kubeadm.x86_64 1.22.6-0 kubernetes
  12. kubeadm.x86_64 1.22.7-0 kubernetes
  13. kubeadm.x86_64 1.22.8-0 kubernetes
  14. kubeadm.x86_64 1.22.9-0 kubernetes
  15. kubeadm.x86_64 1.22.10-0 kubernetes
  16. kubeadm.x86_64 1.22.11-0 kubernetes
  17. kubeadm.x86_64 1.22.12-0 kubernetes
  18. kubeadm.x86_64 1.22.13-0 kubernetes
  19. kubeadm.x86_64 1.22.14-0 kubernetes
  20. kubeadm.x86_64 1.22.15-0 kubernetes
  21. kubeadm.x86_64 1.22.16-0 kubernetes
  22. kubeadm.x86_64 1.22.17-0 kubernetes

3、查看升级计划

#通过这个升级计划,会建议里升级到哪个版本

  1. # kubeadm upgrade plan
  2. [upgrade/config] Making sure the configuration is correct:
  3. [upgrade/config] Reading configuration from the cluster...
  4. [upgrade/config] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
  5. [preflight] Running pre-flight checks.
  6. [upgrade] Running cluster health checks
  7. [upgrade] Fetching available versions to upgrade to
  8. [upgrade/versions] Cluster version: v1.22.0
  9. [upgrade/versions] kubeadm version: v1.22.17
  10. I0222 11:29:39.617205 31327 version.go:255] remote version is much newer: v1.26.1; falling back to: stable-1.22
  11. [upgrade/versions] Target version: v1.22.17
  12. [upgrade/versions] Latest version in the v1.22 series: v1.22.17
  13. Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
  14. COMPONENT CURRENT TARGET
  15. kubelet 6 x v1.22.3 v1.22.17
  16. Upgrade to the latest version in the v1.22 series:
  17. COMPONENT CURRENT TARGET
  18. kube-apiserver v1.22.0 v1.22.17
  19. kube-controller-manager v1.22.0 v1.22.17
  20. kube-scheduler v1.22.0 v1.22.17
  21. kube-proxy v1.22.0 v1.22.17
  22. CoreDNS v1.8.4 v1.8.4
  23. etcd 3.5.0-0 3.5.6-0
  24. You can now apply the upgrade by executing the following command:
  25. kubeadm upgrade apply v1.22.17
  26. _____________________________________________________________________
  27. The table below shows the current state of component configs as understood by this version of kubeadm.
  28. Configs that have a "yes" mark in the "MANUAL UPGRADE REQUIRED" column require manual config upgrade or
  29. resetting to kubeadm defaults before a successful upgrade can be performed. The version to manually
  30. upgrade to is denoted in the "PREFERRED VERSION" column.
  31. API GROUP CURRENT VERSION PREFERRED VERSION MANUAL UPGRADE REQUIRED
  32. kubeproxy.config.k8s.io v1alpha1 v1alpha1 no
  33. kubelet.config.k8s.io v1beta1 v1beta1 no
  34. _____________________________________________________________________

五、升级kueadm

  1. # yum install kubeadm-1.22.17-0.x86_64 -y --disableexcludes=kubernetes
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.tuna.tsinghua.edu.cn
  5. * elrepo: mirrors.tuna.tsinghua.edu.cn
  6. * extras: mirrors.bupt.edu.cn
  7. * updates: mirrors.tuna.tsinghua.edu.cn
  8. Resolving Dependencies
  9. --> Running transaction check
  10. ---> Package kubeadm.x86_64 0:1.22.3-0 will be updated
  11. ---> Package kubeadm.x86_64 0:1.22.17-0 will be an update
  12. --> Finished Dependency Resolution
  13. Dependencies Resolved
  14. =====================================================================================================================================================
  15. Package Arch Version Repository Size
  16. =====================================================================================================================================================
  17. Updating:
  18. kubeadm x86_64 1.22.17-0 kubernetes 9.3 M
  19. Transaction Summary
  20. =====================================================================================================================================================
  21. Upgrade 1 Package
  22. Total download size: 9.3 M
  23. Is this ok [y/d/N]: y
  24. Downloading packages:
  25. Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
  26. 8c09e88292176956bbc5153ff29e5a01be398b984c73f63c519f8ac2cbc30e76-kubeadm-1.22.17-0.x86_64.rpm | 9.3 MB 00:00:32
  27. Running transaction check
  28. Running transaction test
  29. Transaction test succeeded
  30. Running transaction
  31. Updating : kubeadm-1.22.17-0.x86_64 1/2
  32. Cleanup : kubeadm-1.22.3-0.x86_64 2/2
  33. Verifying : kubeadm-1.22.17-0.x86_64 1/2
  34. Verifying : kubeadm-1.22.3-0.x86_64 2/2
  35. Updated:
  36. kubeadm.x86_64 0:1.22.17-0
  37. Complete!

六、升级其它组件

#这里避免升级etcd,所以加了"--etcd-upgrade=false"

  1. # kubeadm upgrade apply v1.22.17 --etcd-upgrade=false
  2. [upgrade/config] Making sure the configuration is correct:
  3. [upgrade/config] Reading configuration from the cluster...
  4. [upgrade/config] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
  5. [preflight] Running pre-flight checks.
  6. [upgrade] Running cluster health checks
  7. [upgrade/version] You have chosen to change the cluster version to "v1.22.17"
  8. [upgrade/versions] Cluster version: v1.22.0
  9. [upgrade/versions] kubeadm version: v1.22.17
  10. [upgrade/confirm] Are you sure you want to proceed with the upgrade? [y/N]: y
  11. [upgrade/prepull] Pulling images required for setting up a Kubernetes cluster
  12. [upgrade/prepull] This might take a minute or two, depending on the speed of your internet connection
  13. [upgrade/prepull] You can also perform this action in beforehand using 'kubeadm config images pull'
  14. [upgrade/apply] Upgrading your Static Pod-hosted control plane to version "v1.22.17"...
  15. Static pod: kube-apiserver-k8s-master03 hash: 4b3445136e77bb42044da85627a3bc22
  16. Static pod: kube-controller-manager-k8s-master03 hash: 930fc0ab2d9cc85badf9b56f69e5405f
  17. Static pod: kube-scheduler-k8s-master03 hash: 1f2c35a1c38369885118a637b7ed926d
  18. [upgrade/staticpods] Writing new Static Pod manifests to "/etc/kubernetes/tmp/kubeadm-upgraded-manifests260373592"
  19. [upgrade/staticpods] Preparing for "kube-apiserver" upgrade
  20. [upgrade/staticpods] Renewing apiserver certificate
  21. [upgrade/staticpods] Renewing apiserver-kubelet-client certificate
  22. [upgrade/staticpods] Renewing front-proxy-client certificate
  23. [upgrade/staticpods] Renewing apiserver-etcd-client certificate
  24. [upgrade/staticpods] Moved new manifest to "/etc/kubernetes/manifests/kube-apiserver.yaml" and backed up old manifest to "/etc/kubernetes/tmp/kubeadm-backup-manifests-2023-02-22-11-32-09/kube-apiserver.yaml"
  25. [upgrade/staticpods] Waiting for the kubelet to restart the component
  26. [upgrade/staticpods] This might take a minute or longer depending on the component/version gap (timeout 5m0s)
  27. Static pod: kube-apiserver-k8s-master03 hash: 4b3445136e77bb42044da85627a3bc22
  28. Static pod: kube-apiserver-k8s-master03 hash: 06066076d8f4226a7b07db07c2385475
  29. [apiclient] Found 3 Pods for label selector component=kube-apiserver
  30. [upgrade/staticpods] Component "kube-apiserver" upgraded successfully!
  31. [upgrade/staticpods] Preparing for "kube-controller-manager" upgrade
  32. [upgrade/staticpods] Renewing controller-manager.conf certificate
  33. [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-2023-02-22-11-32-09/kube-controller-manager.yaml"
  34. [upgrade/staticpods] Waiting for the kubelet to restart the component
  35. [upgrade/staticpods] This might take a minute or longer depending on the component/version gap (timeout 5m0s)
  36. Static pod: kube-controller-manager-k8s-master03 hash: 930fc0ab2d9cc85badf9b56f69e5405f
  37. Static pod: kube-controller-manager-k8s-master03 hash: 6556618dd7bdee28fe84c1fea6778d41
  38. [apiclient] Found 3 Pods for label selector component=kube-controller-manager
  39. [upgrade/staticpods] Component "kube-controller-manager" upgraded successfully!
  40. [upgrade/staticpods] Preparing for "kube-scheduler" upgrade
  41. [upgrade/staticpods] Renewing scheduler.conf certificate
  42. [upgrade/staticpods] Moved new manifest to "/etc/kubernetes/manifests/kube-scheduler.yaml" and backed up old manifest to "/etc/kubernetes/tmp/kubeadm-backup-manifests-2023-02-22-11-32-09/kube-scheduler.yaml"
  43. [upgrade/staticpods] Waiting for the kubelet to restart the component
  44. [upgrade/staticpods] This might take a minute or longer depending on the component/version gap (timeout 5m0s)
  45. Static pod: kube-scheduler-k8s-master03 hash: 1f2c35a1c38369885118a637b7ed926d
  46. Static pod: kube-scheduler-k8s-master03 hash: e5494ea4c4fa231c20be0bf6ed451284
  47. [apiclient] Found 3 Pods for label selector component=kube-scheduler
  48. [upgrade/staticpods] Component "kube-scheduler" upgraded successfully!
  49. [upgrade/postupgrade] Applying label node-role.kubernetes.io/control-plane='' to Nodes with label node-role.kubernetes.io/master='' (deprecated)
  50. [upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
  51. [kubelet] Creating a ConfigMap "kubelet-config-1.22" in namespace kube-system with the configuration for the kubelets in the cluster
  52. [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
  53. [bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes
  54. [bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
  55. [bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
  56. [bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
  57. [addons] Applied essential addon: CoreDNS
  58. [endpoint] WARNING: port specified in controlPlaneEndpoint overrides bindPort in the controlplane address
  59. [addons] Applied essential addon: kube-proxy
  60. [upgrade/successful] SUCCESS! Your cluster was upgraded to "v1.22.17". Enjoy!
  61. [upgrade/kubelet] Now that your control plane is upgraded, please proceed with upgrading your kubelets if you haven't already done so.

七、升级kubelet组件

#yum install kubelet-1.22.17-0.x86_64 -y

#重启kubelet服务

  1. #systemctl daemon-reload
  2. #systemctl restart kubelet

八、重新设置已升级的节点为可调度

#kubectl uncordon k8s-master02
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/171499
推荐阅读
相关标签
  

闽ICP备14008679号