Member-only story
Build EKS cluster with Terraform

Last Update ⏰ October 2024
Stuck behind a paywall? Click Here
Introduction
This post describes the creation of a multi-zone Kubernetes Cluster in AWS, using Terraform with some AWS modules. Specifically, we are going to use infrastructure as code to create:
- A new VPC with multi-zone public & private Subnets, and a single NAT gateway.
- A Kubernetes Cluster, based on Spot EC2 instances running in private Subnets, with an Autoscaling Group based on average CPU usage.
- An Application Load Balancer (ALB) to accept public HTTP calls and route them into Kubernetes nodes, as well as run health checks to scale Kubernetes services if required.
- An AWS Load Balancer Controller inside the Cluster, to receive & forward HTTP requests from the outside world into Kubernetes pods.
- A DNS zone with SSL certificate to provide HTTPS to each Kubernetes service. This zone will be managed from Kubernetes by a service called External DNS.
- A sample application to deploy into our Cluster, using a small Helm Chart.

The usage of official Terraform modules brings us simplicity of coding AWS components following the best practices from verified providers (A.K.A. do not reinvent the wheel), like Private Networks or Kubernetes Clusters.
Project structure
All Terraform definitions in this example are distributed between two modules: