升级kubeadm部署的k8s集群

K爷 DevOps视角

升级k8s集群


使用kubeadm部署kubernetes集群介绍了使用kubeadm快速部署k8s集群,这篇文章将升级k8s集群。

此升级方法仅适用于使用kubeadm部署的k8s集群。

升级kubeadm


升级k8s集群必须先升级kubeadm版本到要升级的版本。即要升级kubeadm部署的k8s级群,必须先升级kubeadm版本。


# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.2", GitCommit:"59603c6e503c87169aea6106f57b9f242f64df89", GitTreeState:"clean", BuildDate:"2020-01-18T23:27:49Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"linux/amd64"}

各master升级到目的版本kubeadm


  • 升级kubeadm

# apt-cache madison kubeadm
# apt-get install kubeadm=1.17.4-00
# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.4", GitCommit:"8d8aa39598534325ad77120c120a22b3a990b5ea", GitTreeState:"clean", BuildDate:"2020-03-12T21:01:11Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"linux/amd64"}
  • 查看升级计划

# 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.2
[upgrade/versions] kubeadm version: v1.17.4
I0723 15:10:34.814329   40861 version.go:251] remote version is much newer: v1.18.6; falling back to: stable-1.17
[upgrade/versions] Latest stable version: v1.17.9
[upgrade/versions] Latest version in the v1.17 series: v1.17.9

Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
COMPONENT   CURRENT       AVAILABLE
Kubelet     6 x v1.17.2   v1.17.9

Upgrade to the latest version in the v1.17 series:

COMPONENT            CURRENT   AVAILABLE
API Server           v1.17.2   v1.17.9
Controller Manager   v1.17.2   v1.17.9
Scheduler            v1.17.2   v1.17.9
Kube Proxy           v1.17.2   v1.17.9
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.9

Note: Before you can perform this upgrade, you have to update kubeadm to v1.17.9.

升级master

在各个master节点进行升级
master节点要一个一个升级,不要一起同时升级


# kubeadm upgrade apply v1.17.4
......
[upgrade/successful] SUCCESS! Your cluster was upgraded to "v1.17.4". Enjoy!

[upgrade/kubelet] Now that your control plane is upgraded, please proceed with upgrading your kubelets if you haven't already done so.
# docker images|grep v1.17.4
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy                v1.17.4             6dec7cfde1e5        4 months ago        116MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver            v1.17.4             2e1ba57fe95a        4 months ago        171MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager   v1.17.4             7f997fcf3e94        4 months ago        161MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler            v1.17.4

升级kubelet和kubectl


# apt install kubelet=1.17.4-00 kubectl=1.17.4-00

升级node节点


查看当前node 版本


# kubectl get node
NAME          STATUS   ROLES    AGE   VERSION
k8s-master1   Ready    master   25h   v1.17.4
k8s-master2   Ready    master   24h   v1.17.4
k8s-master3   Ready    master   24h   v1.17.4
k8s-node1     Ready    <none>   23h   v1.17.2
k8s-node2     Ready    <none>   23h   v1.17.2
k8s-node3     Ready    <none>   23h   v1.17.2

升级node节点配置文件


# kubeadm upgrade node --kubelet-version 1.17.4
[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] Skipping phase. Not a control plane node.
[upgrade] Using kubelet config version 1.17.4, while kubernetes-version is v1.17.4
[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.

升级node节点的kubelet、kubeadm


# apt install kubelet=1.17.4-00 kubeadm=1.17.4-00

查看node


# kubectl get node
NAME          STATUS   ROLES    AGE   VERSION
k8s-master1   Ready    master   25h   v1.17.4
k8s-master2   Ready    master   24h   v1.17.4
k8s-master3   Ready    master   24h   v1.17.4
k8s-node1     Ready    <none>   24h   v1.17.4
k8s-node2     Ready    <none>   24h   v1.17.4
k8s-node3     Ready    <none>   24h   v1.17.4