Loading... ## 使用kubeadm对于K8S集群进行升级操作 kubeadm提供了upgrade命令对于使用kubeadm安装的集群进行升级操作 ### 升级前需要注意的事项: #### (1) kubeadm的升级不会触及工作负载,需要在升级之前做好系统备份。 #### (2) 升级过程可能会因为Pod的变化而造成容器的重启。 #### 本次演示的升级为:kubernetes v1.17.0 --> kubernetes v1.17.3 ### 1.获取kubeadm升级版本:(本次升级 v1.17.0 --- v1.17.3) ```shell $ yum list --showduplicates kubeadm --disableexcludes=kubernetes Loaded plugins: fastestmirr Loading mirror speeds from cached hostfile Installed Packages kubeadm.x86_64 1.17.3-0 @k8s Available Packages kubeadm.x86_64 1.6.0-0 k8s kubeadm.x86_64 1.6.1-0 k8s ... kubeadm.x86_64 1.17.0-0 k8s kubeadm.x86_64 1.17.1-0 k8s kubeadm.x86_64 1.17.2-0 k8s kubeadm.x86_64 1.17.3-0 k8s ``` ### 2.获取系统中k8s集群版本: ```shell $ kubectl version Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:20:10Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:12:17Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"} ``` ### 3.升级kubeadm: ```shell $ yum install -y kubeadm-1.17.3-0 --disableexcludes=kubernetes Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package kubeadm.x86_64 0:1.17.0-0 will be updated ---> Package kubeadm.x86_64 0:1.17.3-0 will be an update --> Finished Dependency Resolution ....... Transaction test succeeded Running transaction Updating : kubeadm-1.17.3-0.x86_64 1/2 Cleanup : kubeadm-1.17.0-0.x86_64 2/2 Verifying : kubeadm-1.17.3-0.x86_64 1/2 Verifying : kubeadm-1.17.0-0.x86_64 2/2 Updated: kubeadm.x86_64 0:1.17.3-0 Complete! 查看kubeadm版本: $ kubeadm version kubeadm version: &version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:12:12Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"} ``` ### 4.查看kubeadm的升级计划: ```shell $ 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 -oyaml' [preflight] Running pre-flight checks. [upgrade] Making sure the cluster is healthy: [upgrade] Fetching available versions to upgrade to [upgrade/versions] Cluster version: v1.17.0 [upgrade/versions] kubeadm version: v1.17.3 [upgrade/versions] Latest stable version: v1.17.3 [upgrade/versions] Latest version in the v1.17 series: v1.17.3 Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply': COMPONENT CURRENT AVAILABLE Kubelet 3 x v1.17.0 v1.17.3 Upgrade to the latest version in the v1.17 series: COMPONENT CURRENT AVAILABLE API Server v1.17.0 v1.17.3 Controller Manager v1.17.0 v1.17.3 Scheduler v1.17.0 v1.17.3 Kube Proxy v1.17.0 v1.17.3 CoreDNS 1.6.5 1.6.5 Etcd 3.4.3 3.4.3-0 You can now apply the upgrade by executing the following command: kubeadm upgrade apply v1.17.3 _____________________________________________________________________ ``` ### 5.按照命令进行升级: ```shell $ kubeadm upgrade apply v1.17.3 [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' [preflight] Running pre-flight checks [upgrade] Making sure the cluster is healthy: [upgrade/version] You have chosen to change the cluster version to "v1.17.3" [upgrade/versions] Cluster version: v1.17.0 [upgrade/versions] kubeadm version: v1.17.3 [upgrade/confirm] Are you sure you want to proceed with the upgrade? [y/N]: y [upgrade/prepull] Will prepull images for components [kube-apiserver kube-controller-manager kube-scheduler etcd] [upgrade/prepull] Prepulling image for component etcd. [upgrade/prepull] Prepulling image for component kube-apiserver. [upgrade/prepull] Prepulling image for component kube-controller-manager. [upgrade/prepull] Prepulling image for component kube-scheduler. ....... [addons]: Migrating CoreDNS Corefile [addons] Applied essential addon: CoreDNS [addons] Applied essential addon: kube-proxy [upgrade/successful] SUCCESS! Your cluster was upgraded to "v1.17.3". Enjoy! [upgrade/kubelet] Now that your control plane is upgraded, please proceed with upgrading your kubelets if you haven't already done so. ``` ### 6.查看系统版本:(发现server端已经升级完毕) ```shell $ kubectl version Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:20:10Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:07:13Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"} ``` ### 7.升级Node版本: ```shell $ kubeadm upgrade node config --kubelet-version 1.17.3 Command "config" is deprecated, use "kubeadm upgrade node" instead [upgrade] Reading configuration from the cluster... [upgrade] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml' [upgrade] Using kubelet config version 1.17.3, while kubernetes-version is v1.17.3 [kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.17" ConfigMap in the kube-system namespace [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" [upgrade] The configuration for this node was successfully updated! [upgrade] Now you should go ahead and upgrade the kubelet package using your package manager. ``` ### 8.查询现有Node的版本: ```shell $ kubectl get nodes NAME STATUS ROLES AGE VERSION master Ready master 61d v1.17.0 node01 Ready <none> 61d v1.17.0 node02 Ready <none> 61d v1.17.0 ``` #### 我们发现虽然K8s集群的内部升级完毕,但是服务端的控制平面还是显示旧版本,接下来我们要升级控制面板。 ### 9.控制平面节点升级: ```shell (1)升级主节点的控制平面: $ yum install -y kubelet-1.17.3-0 kubectl-1.17.3-0 --disableexcludes=kubernetes $ systemctl daemon-reload $ systemctl restart kubelet (2)升级工作节点: $ kubectl drain node01 --ignore-daemonsets $ ssh node01 "yum install -y kubelet-1.17.3-0 kubectl-1.17.3-0 --disableexcludes=kubernetes" $ ssh node01 "systemctl daemon-reload" $ ssh node01 "systemctl restart kubelet" (3)查看Node的版本: $ kubectl get node NAME STATUS ROLES AGE VERSION master Ready master 66d v1.17.3 node01 Ready <none> 66d v1.17.3 node02 Ready <none> 66d v1.17.3 ``` ### 10.完成 Last modification:August 5th, 2020 at 10:17 pm © 允许规范转载