Module: eks-workers
Terraform module to provision AWS resources to run EC2 worker nodes for Elastic Kubernetes Service.
Instantiate it multiple times to create many EKS worker node pools with specific settings such as GPUs, EC2 instance types, or autoscale parameters.
Introduction
The module provisions the following resources:
- IAM Role and Instance Profile to allow Kubernetes nodes to access other AWS services
- Security Group with rules for EKS workers to allow networking traffic
- AutoScaling Group with Launch Template to configure and launch worker instances
- AutoScaling Policies and CloudWatch Metric Alarms to monitor CPU utilization on the EC2 instances and scale the number of instance in the AutoScaling Group up or down.
If you don't want to use the provided functionality, or want to provide your own policies, disable it by setting the variable
autoscaling_policies_enabled
to"false"
.
Usage
For a complete example, see examples/complete
provider "aws" {
region = var.region
}
locals {
# The usage of the specific kubernetes.io/cluster/* resource tags below are required
# for EKS and Kubernetes to discover and manage networking resources
# https://www.terraform.io/docs/providers/aws/guides/eks-getting-started.html#base-vpc-networking
tags = merge(var.tags, map("kubernetes.io/cluster/${var.cluster_name}", "shared"))
}
module "vpc" {
source = "cloudposse/vpc/aws"
version = "2.1.1"
namespace = var.namespace
stage = var.stage
name = var.name
ipv4_primary_cidr_block = "172.16.0.0/16"
tags = local.tags
}
module "subnets" {
source = "cloudposse/dynamic-subnets/aws"
version = "2.4.1"
namespace = var.namespace
stage = var.stage
name = var.name
availability_zones = var.availability_zones
vpc_id = module.vpc.vpc_id
igw_id = [module.vpc.igw_id]
ipv4_cidr_block = [module.vpc.vpc_cidr_block]
nat_gateway_enabled = false
nat_instance_enabled = false
tags = local.tags
}
module "eks_workers" {
source = "cloudposse/eks-workers/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = var.namespace
stage = var.stage
name = var.name
instance_type = var.instance_type
vpc_id = module.vpc.vpc_id
subnet_ids = module.subnets.public_subnet_ids
health_check_type = var.health_check_type
min_size = var.min_size
max_size = var.max_size
wait_for_capacity_timeout = var.wait_for_capacity_timeout
cluster_name = var.cluster_name
cluster_endpoint = var.cluster_endpoint
cluster_certificate_authority_data = var.cluster_certificate_authority_data
cluster_security_group_id = var.cluster_security_group_id
# Auto-scaling policies and CloudWatch metric alarms
autoscaling_policies_enabled = var.autoscaling_policies_enabled
cpu_utilization_high_threshold_percent = var.cpu_utilization_high_threshold_percent
cpu_utilization_low_threshold_percent = var.cpu_utilization_low_threshold_percent
}