Introduction:-
#Amazon Elastic Kubernetes Service (Amazon EKS) is a managed #Kubernetes service that makes it easy to run containerized applications using #Kubernetes on AWS. Regularly updating your EKS cluster’s #Kubernetes version is crucial to benefit from the latest features, security patches, and bug fixes. In this tutorial, we will walk through the process of upgrading an Amazon EKS cluster’s #Kubernetes version using Terraform.
Prerequisites:
Basic knowledge of Amazon EKS and Kubernetes concepts.
Familiarity with Terraform and AWS.
aws-cli and Terraform should be installed in your system.
Step 1:- Set Up Terraform and AWS CLI.
Make sure you have Terraform and the AWS CLI installed on your local machine. Configure the AWS CLI with valid access and secret keys using the aws configure
command.
Step 2:- Create a folder named eks-version-upgrade in your home directory, With in the folder create a file named main.tf . Customize the configuration according to your requirements, such as specifying the cluster name, region, and desired Kubernetes version.
Step 3:- To upgrade the EKS cluster’s #Kubernetes version, add a null_resource
block in your Terraform configuration file main.tf
. This block will use the local-exec
provisioner to run the aws eks update-cluster-version
command.
resource "null_resource" "eks_cluster_upgrade" {
provisioner "local-exec" {
command = "aws eks update-cluster-version --region ${region_name} --name ${eks_cluster.name} --kubernetes-version <new_version>"
}
}
Step 4: Plan and Apply the Terraform Changes
Once you have made the necessary changes to your Terraform code, it’s time to apply the changes to upgrade the EKS cluster. Follow these steps:
Run
terraform init
to initialize the Terraform configuration.Run
terraform plan
to see the execution plan and verify the changes that will be made.Run
terraform apply
to apply the changes and trigger the EKS cluster upgrade. Terraform will execute theaws eks update-cluster-version
command to upgrade the Kubernetes version to 1.27.
Step 5: Verify the Upgrade.
After successfully applying the Terraform changes, you can verify the upgraded #Kubernetes version using either of the following methods:
- Below command will display the client and server versions of #Kubernetes. Ensure that the server version matches the upgraded version (1.27).
kubectl version --short
- Alternatively, you can check the #Kubernetes version directly in the AWS Management Console. Navigate to the EKS cluster you upgraded and check the #Kubernetes version displayed in the cluster details as shown in below picture.
By following these steps, you should be able to upgrade your EKS cluster to #Kubernetes version 1.27 using Terraform. Make sure to verify the upgrade to ensure it was successful and all components are functioning as expected.
Source code link :- “github.com/MahiraTechnology/Mahira-medium.git”
Conclusion:- Upgrading the #Kubernetes version of your Amazon EKS cluster is a crucial task to ensure that you are benefiting from the latest improvements and security updates. By using Terraform’s local-exec
provisioner and the aws eks update-cluster-version
command, you can easily automate the upgrade process and keep your EKS cluster up-to-date.