Atualize o cluster k8s implantado por kubeadm
Perspectiva DevOps de Master K
Atualizar cluster k8s
O uso de kubeadm para implantar um cluster kubernetes apresenta o uso de kubeadm para implantar rapidamente um cluster k8s. Este artigo fará o upgrade do cluster k8s.
Este método de atualização é aplicável apenas a clusters k8s implantados com kubeadm.
Atualize o kubeadm
Para atualizar o cluster k8s, você deve primeiro atualizar a versão kubeadm para a versão a ser atualizada. Ou seja, para atualizar o grupo de nível k8s implantado por kubeadm, você deve primeiro atualizar a versão 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"}
Atualize cada mestre para a versão de destino kubeadm
- Atualize o 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"}
- Ver plano de atualização
# 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.
Mestre de atualização
Atualize cada nó mestre. Os
nós mestre devem ser atualizados um por um, não ao mesmo tempo.
# 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
Atualizar kubelet e kubectl
# apt install kubelet=1.17.4-00 kubectl=1.17.4-00
Nó de atualização
Ver a versão atual do nó
# 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
Atualizar arquivo de configuração de nó
# 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.
Atualize o kubelet e o kubeadm do nó do nó
# apt install kubelet=1.17.4-00 kubeadm=1.17.4-00
Nó de visualização
# 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