DEV Community

marocz
marocz

Posted on

Title: How to Spin Up an AWS EKS Cluster Using Terraform

Image description
Introduction:

Elastic Kubernetes Service (EKS) is Amazon's managed Kubernetes solution that makes it easier to run Kubernetes on AWS without managing the underlying infrastructure. In this post, we'll walk through the process of deploying an EKS cluster using Terraform.

Prerequisites:

An AWS account
AWS CLI installed and configured
Terraform installed
kubectl installed

Step 1: Set up Terraform:

Before you can use Terraform to create resources in AWS, ensure you've set it up correctly:

$ terraform init

Sure! Here's a basic outline and content for a Dev.to post on creating an AWS EKS Cluster using Terraform:

Title: How to Spin Up an AWS EKS Cluster Using Terraform

Introduction:
Elastic Kubernetes Service (EKS) is Amazon's managed Kubernetes solution that makes it easier to run Kubernetes on AWS without managing the underlying infrastructure. In this post, we'll walk through the process of deploying an EKS cluster using Terraform.

Prerequisites:

An AWS account
AWS CLI installed and configured
Terraform installed
kubectl installed

Step 1: Set up Terraform:

Before you can use Terraform to create resources in AWS, ensure you've set it up correctly:

$ terraform init

Step 2: Define Your Infrastructure:

Create a file named eks-cluster.tf and define your AWS provider and EKS resources:

provider "aws" {
  region = "us-west-2"
}

module "eks" {
  source          = "terraform-aws-modules/eks/aws"
  cluster_name    = "my-cluster"
  cluster_version = "1.20"
  subnets         = ["subnet-abcde012", "subnet-bcde012a", "subnet-cde012ab"]

  node_groups = {
    eks_nodes = {
      desired_capacity = 2
      max_capacity     = 3
      min_capacity     = 1

      instance_type = "m5.large"
      key_name      = var.key_name
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Step 3: Initialize and Apply:

$ terraform init
$ terraform apply
Enter fullscreen mode Exit fullscreen mode

After running the terraform apply command, Terraform will show you the changes it plans to make and ask for confirmation. If everything looks good, type yes.

Sure! Here's a basic outline and content for a Dev.to post on creating an AWS EKS Cluster using Terraform:

Title: How to Spin Up an AWS EKS Cluster Using Terraform

Introduction:
Elastic Kubernetes Service (EKS) is Amazon's managed Kubernetes solution that makes it easier to run Kubernetes on AWS without managing the underlying infrastructure. In this post, we'll walk through the process of deploying an EKS cluster using Terraform.

Prerequisites:

An AWS account
AWS CLI installed and configured
Terraform installed
kubectl installed

Step 1: Set up Terraform:
Before you can use Terraform to create resources in AWS, ensure you've set it up correctly:

$ terraform init
Enter fullscreen mode Exit fullscreen mode

Step 2: Define Your Infrastructure:

Create a file named eks-cluster.tf and define your AWS provider and EKS resources:

provider "aws" {
  region = "us-west-2"
}

module "eks" {
  source          = "terraform-aws-modules/eks/aws"
  cluster_name    = "my-cluster"
  cluster_version = "1.20"
  subnets         = ["subnet-abcde012", "subnet-bcde012a", "subnet-cde012ab"]

  node_groups = {
    eks_nodes = {
      desired_capacity = 2
      max_capacity     = 3
      min_capacity     = 1

      instance_type = "m5.large"
      key_name      = var.key_name
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Step 3: Initialize and Apply:

$ terraform init
$ terraform apply
Enter fullscreen mode Exit fullscreen mode

After running the terraform apply command, Terraform will show you the changes it plans to make and ask for confirmation. If everything looks good, type yes.

Step 4: Configure kubectl:
Once your EKS cluster is up, you need to configure kubectl:

$ aws eks --region us-west-2 update-kubeconfig --name my-cluster
Enter fullscreen mode Exit fullscreen mode

Step 5: Verify:

$ kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

Conclusion:

Using Terraform, you can easily deploy an EKS cluster and manage its lifecycle. This method is repeatable, version-controlled, and can be extended with more advanced features and configurations.

Further Reading:

Terraform AWS EKS Introduction
Amazon EKS documentation

You can now use kubectl to view your nodes:

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay