Skip to main content

Command Palette

Search for a command to run...

16: Kubernetes Cluster Management: Upgrading and Backing Up Your Cluster

Updated
3 min read
16: Kubernetes Cluster Management: Upgrading and Backing Up Your Cluster

Managing a Kubernetes (K8s) cluster involves routine upgrades to maintain security, compatibility, and new features, as well as reliable backup strategies to ensure data integrity. This blog will guide you through upgrading your Kubernetes cluster and implementing robust backup mechanisms with built-in and third-party tools.


Upgrading Your Kubernetes Cluster

Upgrading your cluster involves updating kubeadm, applying the upgrade to the control plane, and ensuring nodes and components align with the new version. Below are the detailed steps:

Steps to Upgrade the Cluster

  1. Check the Nodes in the Cluster:

     kubectl get nodes
    

    This command lists all nodes in the cluster and their current status.

  2. Update the System Package Index:

     sudo apt update
    
  3. Check Available Versions of kubeadm:

     sudo apt-cache madison kubeadm
    

    Identify the version of kubeadm you want to install. Replace 1.30.x with the desired version.

  4. Install the New Version of kubeadm:

     sudo apt-mark unhold kubeadm && \
     sudo apt-get update && sudo apt-get install -y kubeadm=1.30.x-* && \
     sudo apt-mark hold kubeadm
    
  5. Verify the Installed kubeadm Version:

     kubeadm version
    
  6. Plan the Upgrade:

     sudo kubeadm upgrade plan
    

    This command shows the current cluster state, available upgrades, and a step-by-step guide for applying the upgrade.

  7. Apply the Upgrade:

     sudo kubeadm upgrade apply v1.30.x
    

    Replace v1.30.x with the target version. This updates the control plane components.

  8. Upgrade the Nodes: After upgrading the control plane, update the nodes by following similar steps, ensuring kubelet and kubectl versions match the control plane.


Backing Up Your Kubernetes Cluster

Reliable backups are critical for disaster recovery and cluster restoration. Here are two popular backup methods:

1. Built-in ETCD Backup

ETCD is the primary datastore for Kubernetes and stores all cluster state information. To back it up:

  1. Use etcdctl for Backup:

     ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 \
       --cacert=/etc/kubernetes/pki/etcd/ca.crt \
       --cert=/etc/kubernetes/pki/etcd/server.crt \
       --key=/etc/kubernetes/pki/etcd/server.key \
       snapshot save /path/to/backup/etcd-snapshot.db
    

    Replace /path/to/backup/etcd-snapshot.db with the desired backup location. Ensure you provide the correct certificate paths (usually located in /etc/kubernetes/pki/etcd/).

  2. Verify the Backup:

     ETCDCTL_API=3 etcdctl snapshot status /path/to/backup/etcd-snapshot.db
    

2. Velero for Production Backups

Velero is a widely-used third-party tool for backing up and restoring Kubernetes clusters. It is particularly useful for production environments.

  1. Install Velero: Follow the official Velero documentation to install it in your cluster.

  2. Create a Backup:

     velero backup create <backup-name> --include-namespaces=<namespace>
    

    Replace <backup-name> with a descriptive name and <namespace> with the desired namespace (or use --all-namespaces).

  3. Verify Backups:

     velero backup get
    
  4. Restore from Backup:

     velero restore create --from-backup <backup-name>
    

Conclusion

Regularly upgrading and backing up your Kubernetes cluster ensures stability, security, and disaster recovery readiness.

Key Notes:

  • Always test upgrades in a staging environment before applying them to production.

  • For built-in ETCD backups, validate the snapshot's integrity.

  • Velero provides a flexible, production-ready solution with cloud storage support.

By following the above methods, you can confidently maintain your Kubernetes infrastructure and mitigate risks effectively.

More from this blog

DevOps Journey with M Hassan

174 posts

I am writing these blogs because I recently completed a comprehensive DevOps course where I gained in-depth knowledge of the topics mentioned. As I progressed through the course, I realized the importance of having a concise and accessible resource to revise and reinforce my understanding of each topic. Therefore, I decided to create cheat sheets in the form of blog posts. These cheat sheets will not only serve as a handy reference for myself but also benefit others who are also interested in mastering DevOps concepts. By documenting each topic and providing concise explanations, I aim to create a valuable resource that simplifies complex concepts and facilitates hands-on practice. This way, I can solidify my own understanding while helping others on their DevOps journey.