Upgrading a K8S platform: Step 01 - logic and preparations

In short
  • Keep Kubernetes up to date: approximately three versions per year.
  • Recommendations and procedures.
  • Create an action plan before any operation.
  • Modularity requires checking the entire chain of components.

Introduction

Keeping your infrastructure and applications up to date has become a necessity (and should always have been...). Even before the cybersecurity trend...).

But it is not always easy to keep up. Obsessed with the need for new features and the race for functionality (not always useful), releases follow each other, sometimes interspersed with bugs and security vulnerabilities.

Kubernetes is no exception, with approximately three major versions per year and releases every four months.

Before embarking on the upgrade operation itself, it is important to have a good understanding of the Kubernetes lifecycle and to implement your update strategy.

Kubernetes lifecycle

The K8S numbering starts with the version number (currently 1).

Then comes the release number, for example 1.30, which is the thirtieth iteration of version 1.

Each release change corresponds to significant functional modifications. Some objects may transition to a different stability state in the API.

New objects may be introduced, and others may be removed. Similarly, compatibility requirements with other components may be reviewed.

You should always pay attention to the release notes and stay informed about the evolution of Kubernetes.

Each K8S object always follows a cycle in three phases:

  • Alpha (Prefix: vXalphaY (e.g., v1alpha1)): API branch hosting objects offering experimental features, which may still undergo significant changes.
  • Beta (Prefix: vXbetaY (e.g., v1beta1)): API branch hosting objects that are available by default and contain features considered stable enough for wider use, but which may still be subject to some adjustments.
  • Stable (Prefix vX (e.g., v1, v2, etc.)): API branch hosting objects associated with features considered mature and ready for large-scale production use.

A final state, not declared in the API but worth knowing, is the Deprecated state. Generally, an object appearing this way in a release note means that it will eventually be removed in a future version. However, it's time to learn how to do without it if it's used in your platform.

There are no rules regarding the transition of an object from one phase to another.

Just because a new release appears doesn't mean that all objects in the Alpha branch move to Beta.

This depends on the level of development progress for each individual object; some may remain in alpha or beta for many versions.

The support for each release is limited to 14 months. The first 12 months are considered "active" and can receive improvements and functional updates. The last two months are only used for bug fixes and/or security vulnerabilities. Therefore, the platform evolves rapidly, and you can quickly find yourself outside of its intended scope.

A third numbering may appear, for example, 1.30.5. This last number is associated with a set of patches that usually include bug fixes or security updates. After 14 months from the release date, it is no longer possible to see this last number evolve for that particular release.

Example of the K8S release lifecycle

Click the image to enlarge.

The diagram above is provided as an illustration; the versions were chosen arbitrarily, and the example starts only with the first month of the year to simplify the explanation.

The entire version history of Kubernetes can be viewed here.

The development approach of K8S is unique; it involves rotating teams for each release.

For each version, a new team is formed. This team is responsible for supervising the entire development and planning cycle until the application is released (including patches).

When you move to a new version, for example, from 1.30.9 to 1.31, it's a new team that takes over. The goal is to distribute responsibilities and avoid centralizing knowledge within a small group of individuals.

Each release has its own team

Click the image to enlarge.

However, this can result in significant changes between releases, and keeping Kubernetes up-to-date has long been considered difficult and complex.

This is particularly the case when using a vanilla installation, as I described in my cookbook on the subject.

A vanilla installation is a Kubernetes installation performed directly using the basic components.

Unlike the approach used by distributions like Kubernetes, such as OpenShift, with a vanilla platform, you are responsible for managing each dependency between the components that you have deployed. There are no built-in or prepackaged updates.

Feel free to explore this section of the website for more information on the topic.

However, we will see in this series of articles that it is quite possible to update your vanilla Kubernetes cluster. It simply requires following certain best practices and being methodical in your approach.

Recommendations

Here are some recommendations based on my experience:

  • Never wait too long between updates, and prioritize regular version upgrades to avoid falling behind in releases. An upgrade cycle every 6 months is a good average (unless there is an emergency or the need to apply a fix due to bugs or security issues).
  • Try to always stay on the latest patched version of the previous release and maintain a difference of one version between your version and the latest available online. For example, if you are running 1.29.9, wait for the release of 1.31 to upgrade to 1.30.5. This way, you always have a version that is considered very stable (because it has already been patched many times) without having too large a gap with the latest release. You also avoid potential problems associated with a newly released version.
  • Write your upgrade procedure and document it as much as possible, evolving it over time.
  • Always prioritize testing the upgrade on a test cluster that is as similar as possible to your production cluster. For example, if your production cluster has multiple control planes, set up a test cluster with multiple control planes.
  • Set your upgrade schedule: reserve dates throughout the year for performing updates.
  • Make sure you have all the necessary backups, starting with the etcd database, and that you know how to restore them. Check your backup solutions, if you have deployed any, such as Velero, for example.
  • Always upgrade one version at a time (or patch by patch within the same release), for example, from 1.28 to 1.29. Never try to skip versions. If you are behind, go through the intermediate versions. For example, if you are on 1.28 and want to switch to 1.31, first upgrade to 1.29.x, then to 1.30.x, where 'x' is always the latest patched version of the release. Ideally, even start with an upgrade to 1.28.x.

The important thing to remember is that it is better to upgrade frequently than to let your version fall too far behind. This limits the risk of significant functional differences and gives you more confidence in the procedure by increasing your mastery. Nothing prevents you from industrializing some actions and automating them gradually.

Procedures

In terms of procedures, here is a suggestion. Of course, this needs to be detailed further on your end and adapted based on your configuration.

  1. Choosing the target version: I look at the available releases and set my target. In this series of articles, I will start with a cluster running 1.29.4 to upgrade it to a cluster running 1.30.5. (The latest version available at the time of writing was 1.31.1.)
  2. Checking compatibility matrices: Now that I have my target version, I check its compatibility with the additional components of my cluster. I rely on what I described in my cookbook. It is possible that these components are not the same for you, but the logic remains the same
    1. Checking my OS: In my case, PhotonOS 5.0
    2. Checking the container runtime: In my case, containerd. The compatibility matrix is available here. In my example, I will need to upgrade to version 1.7.22 (I am starting from 1.7.16).
    3. Checking the Cloud Provider Interface (CPI): In my case, it is the vSphere CPI. I use the vendor's repository. The CPI is a component specific to my use of Kubernetes with vSphere; it may not be used by you. This depends on your cluster execution platform. If you would like more information about the vSphere CPI, feel free to consult this article.
    4. Checking the CSI (Container Storage Interface): in my case, vSphere, NFS, and SMB. CSIs provide persistent storage solutions for a K8S cluster. Please refer to this article and this one for more information on the subject. There are several CSI drivers available. You need to determine which ones to use and how to update them. In my case, I will need to upgrade the vSphere driver from version 3.3.0 to 3.3.1. The compatibility matrix is available here.
    5. Checking my network provider: in my case, Cilium. Again, you need to consult the compatibility matrix available here. In my case, I will be upgrading to version 1.16.2 (I am currently running version 1.15.4).
    6. Checking my internal third-party applications within the cluster: in my case, Traefik, CertManager, etc. For these, the compatibility matrix is less of a concern, but it's always good to review the release notes and ensure their compatibility with the target version of the Kubernetes update. It is not necessary to upgrade these components, but by synchronizing your version upgrades with your Kubernetes updates, you can ensure consistency across your platform. You don't need to use the latest releases; it's up to you to set your own rules on this matter.
    7. Checking all external applications that may be affected by the version upgrade. This includes applications such as CI/CD tools, GUIs, monitoring systems, and others. Many third-party tools call the Kubernetes API, so it is logical to ensure their compatibility with the new API release during a K8S version upgrade.

Note: Regarding the CPI and the CSI for vSphere, I also have a dependency on my VMware infrastructure. For example, I need to ensure that the versions of my ESXi hosts and my vCenter server are compatible. This is an element to consider even if you do not use vSphere. If you are using a CSI driver specific to a storage vendor, such as NetApp, for example, you need to ensure the compatibility of the triad: Kubernetes version / CSI Driver / Firmware of your storage array.

Action plan

At this stage, I normally have my roadmap for updating all the third-party components that I need to update before or after my Kubernetes upgrade.

Here is a simplified overview of the operations to be performed. This covers the points mentioned previously and is based on the logic of using a Kubernetes cluster deployed with kubeadm, as I described in my cookbook.

  1. Check prerequisites: are my backups OK, are my restoration procedures known and mastered?
  2. Check the status of the cluster and my pods before the update. Are my applications OK, am I encountering any errors before the upgrade operation?
  3. Update the Container Plugin Interface (CPI) if necessary (in my case, vSphere).
  4. Update the Container Storage Interface (CSI) if necessary (in my case, vSphere, NFS, SMB).
  5. Update the network provider (in my case, Cilium).
  6. Put the first control plane into maintenance mode.
  7. Update the container runtime on the first control plane.
  8. Update the operating system on the first control plane.
  9. Reboot the first control plane.
  10. Change the repository for the vanilla sources corresponding to my target version on the first control plane.
  11. Upgrade the K8S components on the first control plane
    1. Update kubeadm on the first control plane.
    2. Run the kubeadm command with the update options.
    3. Update the kubelet agent on the first control plane.
    4. Update kubectl on the first control plane.
  12. Exit maintenance mode on the first control plane
  13. Move to the next control plane (using the same strategy as for the first one).

I process all my control planes in this way, one by one, and then move on to the worker nodes. Similarly, I proceed worker by worker, always with:

  1. Put the node into maintenance mode
  2. Update the container runtime
  3. Update the operating system
  4. Reboot
  5. Change the repository for the vanilla sources corresponding to my target version
  6. Update kubeadm
  7. Start the Kubernetes update
  8. Update the kubelet agent (but not kubectl, which is not present on the worker nodes).
  9. Exit maintenance mode
  10. Move to the next worker node

At the end of the operation, I should have all my nodes at the target version.

I can then proceed with updating the additional applications:

  1. Traefik
  2. Certmanager

(This list may evolve over time).

Summary of the upgrade strategy

Click the image to enlarge.

Conclusion

This article, which details the logic and preparations required for a K8S upgrade, is closely tied to my cookbook on installing a vanilla Kubernetes cluster with kubeadm.

It's quite possible that your clusters differ from mine, and that the components vary between my example and your infrastructure. Therefore, this article should be adapted to your needs, but the overall logic may apply to other configurations. This remains true only when using a standard vanilla cluster. If you are using a managed cluster from a cloud provider or a K8S distribution like OpenShift, you should contact your provider/vendor to follow their guidelines.

You can perform these actions live, but I strongly advise reserving time slots for interventions based on the capabilities of your production environment. The downtime depends on the deployment of your applications and your application architectures. If you are in environments with microservices and high redundancy of your pods, then the operations should be transparent. Conversely, if you have monolithic containers, they will need to restart, which will cause interruptions. In any case, it is always a good idea to allow for some flexibility in your operations in case an incident occurs.

My goal here is to highlight the importance of being rigorous when upgrading your cluster. It's important to understand the order of actions and prepare your intervention carefully. The biggest challenge is ensuring compatibility between the different components. If you need to achieve compatibility with the target version, you also need to maintain functionality with the current version.

If you upgrade an element as a prerequisite for your K8S upgrade, but you break the existing functionality, that's not ideal. Again, if you maintain a regular update schedule, this type of problem should not occur.

Don't be afraid to use a vanilla cluster. As versions evolve, operations become simpler, and often good preparation is all that's needed for the operation to proceed smoothly. This is the downside of Kubernetes' modular nature.

There are the basic building blocks and everything else, and when you upgrade the core of the platform, you need to ensure that everything continues to function. Furthermore, after the theory, we can move on to practice, but this will be covered in this article.