Upgrading an EKS Cluster: A Step-by-Step Guide
Tags: eks, kubernetes, aws, devops
Published: 2024-05-18 00:02:19

Upgrading an Amazon EKS (Elastic Kubernetes Service) cluster can seem daunting, especially in a production environment. However, with a well-defined strategy and the right tools, the process can be smooth and minimally disruptive. In this post, I'll walk you through the upgrade process from version 1.27 to 1.28 using Terraform, ensuring your EKS cluster remains functional and resilient throughout.

**Why Upgrading EKS Matters**

EKS clusters need to stay updated to leverage the latest features, security patches, and performance improvements. However, EKS-managed clusters can only be upgraded one minor version at a time, making a systematic approach essential.

**_The Upgrade Process_**

If you're managing your EKS cluster configuration with Terraform, it's essential to understand that EKS-managed clusters can only undergo upgrades one minor version at a time. The [terraform-aws-eks](https://github.com/terraform-aws-modules/terraform-aws-eks/blob/0e3cb9a0afcea87e1da0c87ecc969ffb963619ea/main.tf#L406-L412) module is specifically designed to handle upgrades in the correct order when changing the cluster version.

Here's a simplified overview of what we'll cover:

- Upgrading the EKS Cluster Version
- Updating EKS Add-ons
- Upgrading EKS Managed Node Groups
- Upgrade Other Resources (e.g., Karpenter)

**_Step 1: Upgrading the Control Plane_**

The control plane is the brain of your Kubernetes cluster, managing all the operations within the cluster. To upgrade:

- **_Update the Control Plane_**: This is the first step in the upgrade process. The control plane version dictates the compatibility of the cluster's components.


- **_Initiate the Upgrade_**: Use Terraform to apply the new configuration. This ensures that the control plane updates to the desired version without manual intervention.
```
module "eks" {
  source  = "terraform-aws-modules/eks/aws"
  version = "~> 20.0"

  cluster_name    = local.name
  cluster_version = "1.27" => "1.28"

  cluster_endpoint_public_access = true

  cluster_addons = {
    coredns = {
      most_recent = true
    }
    kube-proxy = {
      most_recent = true
    }
    vpc-cni = {
      most_recent = true
    }
  }
```

![eks-console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9yrfj32hgldaaqx4cmvn.png)

**_Step 2: Updating EKS Add-ons_**

Add-ons in EKS are additional features that enhance your cluster's capabilities, such as DNS management or monitoring tools. These add-ons are tightly coupled with the cluster's version.

- **_Automatic Compatibility_**: When the control plane is updated, EKS automatically aligns the add-on versions with the new cluster version.


- **_Verify Add-on Versions_**: Ensure that each add-on is updated and compatible with the new version of the control plane.

**_Step 3: Upgrading EKS Managed Node Groups_**

Node groups are the workers in your cluster, running your applications. These groups need to be in sync with the control plane.

- **_Node Group Update Process:_** After the control plane is updated, node groups are updated to match the new version. This ensures that all nodes run the compatible Kubernetes version.


- _**Minimize Disruption:**_ EKS handles node group updates in a way that minimizes disruption. By default, it limits the number of unavailable nodes during the upgrade to 33%, ensuring that most of your applications remain operational.

![modules](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v77bwra4dbjntlro4399.png)



**_Ensuring Minimal Disruption_**

Our upgrade approach prioritizes minimal disruption, making it suitable for production environments. By systematically updating the control plane, add-ons, and node groups, you ensure that your cluster remains functional and efficient throughout the upgrade process.

**_Upgrade Other Resources_**

If you are using additional tools like Karpenter, an open-source cluster autoscaler, you will need to upgrade these as well:

- Verify the compatibility of these resources with the new EKS version.

**Conclusion**

Upgrading your EKS cluster is paramount to maintaining security, stability, and accessing the latest Kubernetes features. It's imperative to follow the recommended upgrade procedure to seamlessly transition from v1.27 to v1.28 while mitigating disruptions. Before implementing upgrades in production, thorough testing in a staging environment is essential. Leveraging the terraform-aws-eks module can streamline the upgrade process, ensuring efficiency and accuracy. Stay informed about Kubernetes releases and adhere to best practices to uphold the success of your AWS EKS deployment.