Upgrading nodes in an EKS cluster using Terraform involves updating the configuration of the node group to use a new Amazon Machine Image (AMI). Here’s a step-by-step guide:
Prerequisites:
- Ensure you have Terraform installed.
- Ensure you have AWS CLI configured.
- Ensure you have an existing EKS cluster managed by Terraform.
1. Find the Latest AMI ID:
- Find the Latest EKS-Optimized AMI ID: Check the latest AMI IDs in the Amazon EKS optimized AMI page.
2. Update Terraform Configuration:
1.Update Launch Template (for Managed Node Groups):
- If you are using a launch template for your node group, update the launch template with the new AMI ID.
- Update your Terraform code to use the new AMI ID.
resource "aws_launch_template" "example" {
name_prefix = "example"
# Other configurations
image_id = "ami-xxxxxxxxxxxxxxxxx" # Update with the new AMI ID
# Other configurations
}
2. Update Launch Configuration (for Self-Managed Node Groups):
- If you are using a launch configuration, update it with the new AMI ID.
resource "aws_launch_configuration" "example" {
name = "example"
image_id = "ami-xxxxxxxxxxxxxxxxx" # Update with the new AMI ID
instance_type = "t2.micro"
# Other configurations
}
3. Update Node Group Configuration:
- If you are managing your node groups directly in Terraform, update the node group resource to use the new launch template or launch configuration.
resource "aws_eks_node_group" "example" {
cluster_name = aws_eks_cluster.example.name
node_group_name = "example"
# Other configurations
launch_template {
id = aws_launch_template.example.id
version = "$Latest" # Use the latest version of the launch template
}
# Other configurations
}
4. Apply Terraform Changes:
1.Plan the Changes:
- Run
terraform plan
to see the changes that will be applied.
terraform plan
2. Apply Changes:
Run terraform apply
to apply the changes
terraform apply