Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
A Comprehensive Guide to Upgrading a Multi-Node Kubernetes Cluster with Kubeadm#
Kubernetes cluster upgrades are a critical aspect of maintaining a healthy and secure container orchestration environment. In this guide, we’ll walk through the process of upgrading a multi-node Kubernetes cluster using kubeadm, focusing on best practices and potential pitfalls.
Prerequisites#
Before beginning the upgrade process, ensure:
- Your cluster is in a healthy state
- You have root or sudo access to all nodes
- You have a recent backup of your cluster and important data
- You’ve reviewed the Kubernetes release notes for any breaking changes
Understanding Kubernetes Versioning#
Kubernetes follows a semantic versioning scheme (MAJOR.MINOR.PATCH). It’s crucial to note:
- ETCD and CoreDNS have separate version numbers from other Kubernetes components
- Always upgrade one minor version at a time (e.g., 1.29.x to 1.30.x)
Step 1: Upgrading the Control Plane Node#
Let’s start by upgrading the control plane (master) node:
-
Find the latest 1.30.x version:
Terminal window 1sudo apt update2sudo apt-cache madison kubeadm -
Upgrade kubeadm:
Terminal window 1sudo apt-mark unhold kubeadm && \2sudo apt-get update && sudo apt-get install -y kubeadm='1.30.2-1.1' && \3sudo apt-mark hold kubeadm -
Plan the upgrade:
Terminal window 1sudo kubeadm upgrade plan -
Apply the upgrade:
Terminal window 1sudo kubeadm upgrade apply v1.30.2 -
Drain the control plane node:
Terminal window 1kubectl drain <control-plane-node> --ignore-daemonsets -
Upgrade kubelet and kubectl:
Terminal window 1sudo apt-mark unhold kubelet kubectl && \2sudo apt-get update && sudo apt-get install -y kubelet='1.30.2-1.1' kubectl='1.30.2-1.1' && \3sudo apt-mark hold kubelet kubectl -
Restart kubelet:
Terminal window 1sudo systemctl daemon-reload2sudo systemctl restart kubelet -
Uncordon the control plane node:
Terminal window 1kubectl uncordon <control-plane-node>
Step 2: Upgrading Worker Nodes#
Repeat the following steps for each worker node:
-
Drain the node:
Terminal window 1kubectl drain <worker-node> --ignore-daemonsets -
SSH into the worker node and upgrade kubeadm:
Terminal window 1sudo apt-mark unhold kubeadm && \2sudo apt-get update && sudo apt-get install -y kubeadm='1.30.2-1.1' && \3sudo apt-mark hold kubeadm -
Upgrade the kubelet configuration:
Terminal window 1sudo kubeadm upgrade node -
Upgrade kubelet and kubectl:
Terminal window 1sudo apt-mark unhold kubelet kubectl && \2sudo apt-get update && sudo apt-get install -y kubelet='1.30.2-1.1' kubectl='1.30.2-1.1' && \3sudo apt-mark hold kubelet kubectl -
Restart kubelet:
Terminal window 1sudo systemctl daemon-reload2sudo systemctl restart kubelet -
Uncordon the node:
Terminal window 1kubectl uncordon <worker-node>
Step 3: Verifying the Upgrade#
After upgrading all nodes, verify the cluster state:
-
Check node versions:
Terminal window 1kubectl get nodes -
Verify pod health:
Terminal window 1kubectl get pods --all-namespaces -
Run a sample workload to ensure cluster functionality
Key Takeaways and Best Practices#
-
Incremental Upgrades: Always upgrade one minor version at a time to minimize risks.
-
Control Plane First: Upgrade the control plane before worker nodes to ensure compatibility.
-
Node Draining: Always drain nodes before upgrading to minimize workload disruption.
-
Backup: Create backups before starting the upgrade process.
-
Testing: Have a staging environment to test upgrades before applying to production.
-
Component Versions: Pay attention to component-specific versions (e.g., ETCD, CoreDNS).
-
Rolling Upgrades: For larger clusters, consider upgrading worker nodes in batches to maintain availability.
-
Monitoring: Keep a close eye on cluster health metrics during and after the upgrade.
-
Documentation: Keep detailed notes of the upgrade process for future reference and troubleshooting.
Conclusion#
Upgrading a Kubernetes cluster requires careful planning and execution. By following this guide and adhering to best practices, you can ensure a smooth upgrade process with minimal disruption to your workloads. Remember, the key to successful upgrades is thorough preparation, careful execution, and comprehensive verification.
As Kubernetes continues to evolve, staying up-to-date with the latest stable versions is crucial for maintaining security, performance, and access to new features. Regular, well-planned upgrades should be part of your ongoing Kubernetes maintenance strategy.