Upgrading a Kubernetes Cluster Using Kubeadm

Upgrading a Kubernetes Cluster Using Kubeadm

Note: The following example demonstrates upgrading a Kubernetes cluster from version 1.23 to 1.24. Replace the version numbers according to your specific setup.

To ensure a seamless upgrade, it’s crucial to follow these steps in order:

  1. Upgrade the Control Plane node.
  2. Upgrade Worker Nodes.

Additionally, upgrade the following components on both the control plane and worker nodes:

  • Kubeadm
  • Kubelet
  • Kubectl

Before commencing the upgrade process, be sure to identify the cluster and node names. Execute the following command to retrieve the node names:

kubectl get nodes        

Upgrade the Control Plane (Master Node)

Step 1: Check the existing Kubeadm version

Log in to the control plane and check the existing version using the following command:

kubeadm version -o json        

Step 2: Decide on the upgrade version

Obtain a list of available Kubeadm versions:

sudo apt update
sudo apt-cache madison kubeadm | tac
        

Alternatively, run a kubeadm upgrade plan for upgrade suggestions:

sudo kubeadm upgrade plan        

Step 3: Unhold kubeadm and Install the required version

Unhold kubeadm and install the desired version:

sudo apt-mark unhold kubeadm && \
sudo apt-get update && sudo apt-get install -y kubeadm=1.24.6-00 && \
sudo apt-mark hold kubeadm
        

Step 4: Apply Kubeadm upgrade

Apply the upgrade:

sudo kubeadm upgrade node        

Step 5: Evict all workloads from the control plane

To apply the upgrade, evict all workloads except daemonsets:

kubectl drain master-node --ignore-daemonsets        

If using local storage, include –delete-local-data:

sudo kubectl drain master-node --ignore-daemonsets --delete-local-data        

Step 6: Upgrade Kubelet and Kubectl

Unhold and upgrade kubectl and kubelet:

sudo apt-mark unhold kubelet kubectl && \

sudo apt-get update && sudo apt-get install -y kubelet=1.24.6-00 kubectl=1.24.6-00 && \

sudo apt-mark hold kubelet kubectl\        

Restart the services:

sudo systemctl daemon-reload
sudo systemctl restart kubelet
        

Step 7: Uncordon the Node and Verify the Node Status

Uncordon the control plane node:

kubectl uncordon master-node        

Verify the node status and version:

kubectl get nodes        

Upgrade Worker Nodes

Step 1: Unhold Kubeadm and Install Required Version

Install the required version of Kubeadm on worker nodes:

sudo apt-mark unhold kubeadm && \
sudo apt-get update && sudo apt-get install -y kubeadm=1.24.6-00 && \
sudo apt-mark hold kubeadm
        

Step 2: Upgrade Kubeadm

Run the following command on each worker node:

sudo kubeadm upgrade node        

Step 3: Drain the Node

Evict all pods on the worker node by draining it:

kubectl drain worker-node01 --ignore-daemonsets        

Step 4: Upgrade Kubelet & Kubectl

Upgrade kubelet and kubectl:

sudo apt-mark unhold kubelet kubectl && \
sudo apt-get update && sudo apt-get install -y kubelet=1.24.6-00 kubectl=1.24.6-00 && \
sudo apt-mark hold kubelet kubectl
        

Restart kubelet:

sudo systemctl daemon-reload
sudo systemctl restart kubelet
        

Step 5: Uncordon worker node

kubectl uncordon worker-node01        

Verify Cluster Upgrade

Check if the cluster is upgraded and operational

kubectl get nodes        

Verify the status of all cluster components:

kubectl get --raw='/readyz?verbose'
curl -k https://localhost:6443/livez?verbose        

Also, ensure that all kube-system control node pods are running:

kubectl get po -n kube-system        

This completes the Kubernetes cluster upgrade process.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了