avatarrouterhan

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2812

Abstract

<li>Update the <b>Kubeadm</b> Package:</li></ol><div id="4062"><pre>sudo apt<span class="hljs-operator">-</span>mark unhold kubeadm sudo apt<span class="hljs-operator">-</span><span class="hljs-keyword">get</span> <span class="hljs-keyword">update</span> sudo apt<span class="hljs-operator">-</span>cache policy kubeadm sudo apt<span class="hljs-operator">-</span><span class="hljs-keyword">get</span> install <span class="hljs-operator">-</span>y kubeadm<span class="hljs-operator">=</span>$TARGET_VERSION sudo apt<span class="hljs-operator">-</span>mark <span class="hljs-keyword">hold</span> kubeadm</pre></div><p id="c6c7">2.Drain the Control Plane Node:</p><p id="752a">Before upgrading, we need to drain the control plane node to prepare for the upgrade. This ensures that no new workloads are scheduled on the node during the upgrade process.</p><div id="8114"><pre>kubectl drain k8s-master <span class="hljs-attr">--ignore-daemonsets</span></pre></div><p id="514e">3.Plan the Upgrade:</p><p id="02ac">Use <code>kubeadm upgrade plan</code> to see which versions are available for the upgrade:</p><div id="3a23"><pre>sudo kubeadm upgrade plan</pre></div><p id="b52f">example output:</p><div id="01eb"><pre>[<span class="hljs-meta">upgrade/config</span>] Making sure the configuration <span class="hljs-keyword">is</span> correct: ... [<span class="hljs-meta">upgrade/prepull</span>] Will prepull images <span class="hljs-keyword">for</span> components [kube-apiserver kube-controller-manager kube-scheduler etcd] ... [<span class="hljs-meta">upgrade/apply</span>] Upgrading your Static Pod-hosted control plane to version <span class="hljs-string">"v1.26.8"</span>... ... [<span class="hljs-meta">upgrade/successful</span>] SUCCESS! Your control plane <span class="hljs-keyword">is</span> upgraded to version <span class="hljs-string">"v1.26.3"</span>.</pre></div><p id="5617"><b>4. Apply the Upgrade:</b></p><p id="1ed3">Run <code>kubeadm upgrade apply</code> to perform the upgrade of the control plane components:</p><div id="cd30"><pre>sudo kubeadm upgrade apply v<span class="hljs-variable">$TARGET_VERSION</span></pre></div><p id="55a7">Example output:</p><div id="8c5c"><pre>[upgrade/successful] SUCCESS! Your cluster was upgraded to <span class="hljs-string">"v1.26.8"</span>. Enjoy!</pre></div><p id="33d2"><b>5. Uncordon the Control Plane Node:</b></p><p id="f727">After the upgrade is complete, uncordon the control plane node to allow workloads to be scheduled on it again:</p><div id="ed0e"><pre>kubectl uncordon k8s-master</pre></div><p id="3cea">6.Update kubelet and kubectl:</p><p id="b45e">Finally, update the kubelet and kubectl on the control plane node to match the new version:</p><div id="4718"><pre>sudo apt<span class="hljs-operator">-</span>mark unhold kubelet kubectl sudo apt<span # Options class="hljs-operator">-</span><span class="hljs-keyword">get</span> <span class="hljs-keyword">update</span> sudo apt<span class="hljs-operator">-</span><span class="hljs-keyword">get</span> install <span class="hljs-operator">-</span>y kubelet<span class="hljs-operator">=</span>$TARGET_VERSION kubectl<span class="hljs-operator">=</span>$TARGET_VERSION sudo apt<span class="hljs-operator">-</span>mark <span class="hljs-keyword">hold</span> kubelet kubectl</pre></div><p id="dc02">After completing the upgrade on the<b> control plane/master</b> node, you will need to repeat a similar process on each <b>worker node</b> in the cluster. However, there are some key differences in the steps for upgrading worker nodes:</p><ol><li><b>Update Kubeadm on Worker Nodes:</b> Just like the control plane node, you will need to update the <code>kubeadm</code> package on each worker node to match the target version.</li><li><b>Drain the Worker Node:</b> Before performing the upgrade, you should drain the worker node to evict all the pods running on that node. This ensures that the upgrade process can proceed smoothly without any disruptions.</li><li><b>Perform the Upgrade:</b> Run the <code>kubeadm upgrade node</code> command on each worker node to upgrade the kubelet configuration. T<b>his step is different from the control plane upgrade process</b>, where we used <code>kubeadm upgrade apply</code>.</li><li><b>Uncordon the Worker Node:</b> After the upgrade is complete, uncordon the worker node to allow new pods to be scheduled on it.</li><li><b>Update Kubelet and Kubectl:</b> Finally, just like the control plane node, you need to update the <code>kubelet</code> and <code>kubectl</code> packages on each worker node to match the target version.</li></ol><p id="91c6">Remember to repeat these steps on each worker node in your cluster to ensure that all nodes are upgraded to the desired version.</p><p id="e7a3">Once all the nodes have been upgraded, your Kubernetes cluster will be running the latest version with all the latest features and bug fixes. Happy upgrading!</p><blockquote id="c392"><p>🔔 Stay tuned or <a href="https://routerhan.medium.com/subscribe">subscribe </a>to my series: “<a href="https://routerhan.medium.com/a-beginners-guide-to-kubernetes-e0f1c2866d36"><b>Understanding Kubernetes — A Beginner’s Guide</b></a>” to explore everything about Kubernetes. 🚀</p></blockquote><blockquote id="c899"><p>➕Join the <a href="https://medium.com/@routerhan/membership">Medium Membership Program</a> to support my work and connect with other writers.</p></blockquote><blockquote id="9f7b"><p>📝 Have questions or suggestions? Leave a comment or message me through Medium. Let’s connect!</p></blockquote><blockquote id="179d"><p>Thank you for your support! 🌟</p></blockquote></article></body>

Understanding Kubernetes Cluster Upgrade— A Beginner’s Guide

How to keep your kubernetes cluster up-to-date?

Find Complete mind map of A Beginner’s Guide to Kubernetes

In this article, we will dive into another practical aspects of maintaining a Kubernetes cluster by focusing on the critical task of upgrading the cluster.

Keeping your Kubernetes cluster up-to-date is essential for gaining access to new features, bug fixes, and security enhancements.

We will present a step-by-step guide on how to upgrade a Kubernetes cluster built with Kubeadm, covering both the control plane and worker nodes, using a practical example on a Kubeadm-built cluster.

Check out “Understanding Kubernetes — A Beginner’s Guide” for the comprehensive series🚀

Kubernetes Versioning

Before we begin the upgrade process, let’s first understand Kubernetes versioning and the order in which components should be upgraded.

Kubernetes follows a semantic versioning scheme with major, minor, and patch versions. Major versions indicate significant changes that may require updates to your applications, while minor and patch versions contain bug fixes and improvements that are usually backward-compatible.

Upgrade Order

To ensure a smooth upgrade process, follow this order:

  1. Upgrade the control plane components (master nodes).
  2. Upgrade the worker nodes.

Upgrading the Control Plane

Let’s start by upgrading the control plane (master nodes) using Kubeadm.

  1. Update the Kubeadm Package:
sudo apt-mark unhold kubeadm
sudo apt-get update
sudo apt-cache policy kubeadm
sudo apt-get install -y kubeadm=$TARGET_VERSION
sudo apt-mark hold kubeadm

2.Drain the Control Plane Node:

Before upgrading, we need to drain the control plane node to prepare for the upgrade. This ensures that no new workloads are scheduled on the node during the upgrade process.

kubectl drain k8s-master --ignore-daemonsets

3.Plan the Upgrade:

Use kubeadm upgrade plan to see which versions are available for the upgrade:

sudo kubeadm upgrade plan

example output:

[upgrade/config] Making sure the configuration is correct:
...
[upgrade/prepull] Will prepull images for components [kube-apiserver kube-controller-manager kube-scheduler etcd]
...
[upgrade/apply] Upgrading your Static Pod-hosted control plane to version "v1.26.8"...
...
[upgrade/successful] SUCCESS! Your control plane is upgraded to version "v1.26.3".

4. Apply the Upgrade:

Run kubeadm upgrade apply to perform the upgrade of the control plane components:

sudo kubeadm upgrade apply v$TARGET_VERSION

Example output:

[upgrade/successful] SUCCESS! Your cluster was upgraded to "v1.26.8". Enjoy!

5. Uncordon the Control Plane Node:

After the upgrade is complete, uncordon the control plane node to allow workloads to be scheduled on it again:

kubectl uncordon k8s-master

6.Update kubelet and kubectl:

Finally, update the kubelet and kubectl on the control plane node to match the new version:

sudo apt-mark unhold kubelet kubectl
sudo apt-get update
sudo apt-get install -y kubelet=$TARGET_VERSION kubectl=$TARGET_VERSION
sudo apt-mark hold kubelet kubectl

After completing the upgrade on the control plane/master node, you will need to repeat a similar process on each worker node in the cluster. However, there are some key differences in the steps for upgrading worker nodes:

  1. Update Kubeadm on Worker Nodes: Just like the control plane node, you will need to update the kubeadm package on each worker node to match the target version.
  2. Drain the Worker Node: Before performing the upgrade, you should drain the worker node to evict all the pods running on that node. This ensures that the upgrade process can proceed smoothly without any disruptions.
  3. Perform the Upgrade: Run the kubeadm upgrade node command on each worker node to upgrade the kubelet configuration. This step is different from the control plane upgrade process, where we used kubeadm upgrade apply.
  4. Uncordon the Worker Node: After the upgrade is complete, uncordon the worker node to allow new pods to be scheduled on it.
  5. Update Kubelet and Kubectl: Finally, just like the control plane node, you need to update the kubelet and kubectl packages on each worker node to match the target version.

Remember to repeat these steps on each worker node in your cluster to ensure that all nodes are upgraded to the desired version.

Once all the nodes have been upgraded, your Kubernetes cluster will be running the latest version with all the latest features and bug fixes. Happy upgrading!

🔔 Stay tuned or subscribe to my series: “Understanding Kubernetes — A Beginner’s Guide” to explore everything about Kubernetes. 🚀

➕Join the Medium Membership Program to support my work and connect with other writers.

📝 Have questions or suggestions? Leave a comment or message me through Medium. Let’s connect!

Thank you for your support! 🌟

Kubernetes
DevOps
Software Development
Programming
Technology
Recommended from ReadMedium