Cluster Upgrade Process
- Regarding the core control plane components, it is not mandatory for them all to be the same version.
- The
kube-apiserveris the primary component in the ControlPlane. - None of the other components in the ControlPlane group should be at a higher version than the
kube-apiserver.
- The
- The
controller-managerandkube-schedulercan be one version lower than thekube-apiserver. kubeletandkube-proxycan be two versions lower.kubectlcan be one version higher, the same version or one version lower than thekube-apiserver.- The skew in versions allows for live upgrades to be carried out.
- When should you upgrade?
- Kubernetes only supports the latest 3 minor versions.
- The recommended approach is to upgrade 1 minor version at a time.
- Can upgrade to the latest version this way.
- The upgrade process varies depending on how the cluster was set up.
- Google Kubernetes Engine allows you to upload with a few clicks.
kubeadmallows you to run these commandskubeadm upgrade planandkubeadm upgrade apply.- You can also manually update each component of the cluster yourself as well.
- For example there is a cluster with one Master node and three Worker nodes.
- You firstly upgrade the Master node, then the Worker node.
- When the Master node is upgraded, the control plane components go down briefly -
kube-apiserver - Because the Master node is down, doesn’t mean the Worker nodes are impacted and these continue to server users.
- When the Master node is upgraded, the control plane components go down briefly -
- You firstly upgrade the Master node, then the Worker node.
- Since the Master Node is down, all cluster functionality such as deploying new pods is unavailable.
- Once the upgrade on the Master node is complete and the node is back up, the cluster should be back up.
- The the Master Node will be on one minor version later than the Worker Nodes.
- Strategy for updating the Worker Nodes - Upgrade them all at the same times means no users can access any applications.
- New pods would then be scheduled and users can resume access.
- Second Strategy is to upgrade one Worker node at a time.
- The workloads are therefore split between the nodes that are still up.
- A third strategy is to add new nodes to the cluster, that have a newer software version.
- Move the workload over to the new node and remove the older node that is running an older version.
- Then run
kubeadm upgrade plan.kubeadmdoes not install or upgradekubelets
- Example upgrade steps for
kubeadm:dnf upgrade -y kubeadm=1.12.0-00- Then
kubeadm upgrade apply v1.12.0- It pulls the necessary images and upgrades the cluster components.
- If you then run the
kubectl get nodescommand, you see the version of the nodes still displayed as the older version.- That is because it is showing the
kubeletversion that is registered with thekube-apiserver.- Not the
apiserveritself.
- Not the
- That is because it is showing the
- If you then run the
- It pulls the necessary images and upgrades the cluster components.
kubeadmuseskubeletsto deploy things on the Master Node.- Then upgrade the
kubeletwithdnf upgrade -y kubelet=1.12.0-00 - Then restart the
kubeletservice:systemctl restart kubelet - Then running the
kubectl get nodescommand will show the Master Node is upgraded to the new version. - Steps to upgrade the Worker Nodes:
- The
kubectl drain <node>command helps to remove all pods on a node and re-schedules those to other nodes.- It also cordons the node and marks it as unschedulable.
- Run
dnf upgrade -y kubeadm=1.12.0-00 - Run
dnf upgrade -y kubelet=1.12.0-00 - Run
kubeadm upgarde node config --kubelet-version v1.12.0 - Restart the
kubeletservice:sudo systemctl restart kubelet - Then unmark it as non-schedulable with
kubectl uncordon <node>. - It is only marked as schedulable when pods are deleted from other nodes or new pods are created.
- Perform the above steps on each node.