docs: Move examples that are more like test cases to the new tests/ directory; add better example configurations (#3069)

* chore: Move examples that are more like test cases to the new `tests/` directory

* chore: Stash

* feat: Add better examples for EKS managed node groups

* chore: Add better examples for self-managed node groups

* chore: Update docs and correct `nodegroup` to `node group`
This commit is contained in:
Bryant Biggs
2024-06-13 10:51:40 -04:00
committed by GitHub
parent 73b752a1e3
commit 323fb759d7
85 changed files with 509 additions and 109 deletions

View File

@@ -0,0 +1,21 @@
# Self-managed Node Group Examples
Configuration in this directory creates Amazon EKS clusters with self-managed node groups demonstrating different configurations:
- `eks-al2.tf` demonstrates an EKS cluster using self-managed node group that utilizes the EKS Amazon Linux 2 optimized AMI
- `eks-al2023.tf` demonstrates an EKS cluster using self-managed node group that utilizes the EKS Amazon Linux 2023 optimized AMI
- `eks-bottlerocket.tf` demonstrates an EKS cluster using self-managed node group that utilizes the Bottlerocket EKS optimized AMI
The different cluster configuration examples provided are separated per file and independent of the other cluster configurations.
## Usage
To provision the provided configurations you need to execute:
```bash
$ terraform init
$ terraform plan
$ terraform apply --auto-approve
```
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.

View File

@@ -0,0 +1,33 @@
module "eks_al2" {
source = "terraform-aws-modules/eks/aws"
version = "~> 20.0"
cluster_name = "${local.name}-al2"
cluster_version = "1.30"
# EKS Addons
cluster_addons = {
coredns = {}
eks-pod-identity-agent = {}
kube-proxy = {}
vpc-cni = {}
}
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
self_managed_node_groups = {
example = {
ami_type = "AL2_x86_64"
instance_type = "m6i.large"
min_size = 2
max_size = 5
# This value is ignored after the initial creation
# https://github.com/bryantbiggs/eks-desired-size-hack
desired_size = 2
}
}
tags = local.tags
}

View File

@@ -0,0 +1,52 @@
module "eks_al2023" {
source = "terraform-aws-modules/eks/aws"
version = "~> 20.0"
cluster_name = "${local.name}-al2023"
cluster_version = "1.30"
# EKS Addons
cluster_addons = {
coredns = {}
eks-pod-identity-agent = {}
kube-proxy = {}
vpc-cni = {}
}
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
self_managed_node_groups = {
example = {
ami_type = "AL2023_x86_64_STANDARD"
instance_type = "m6i.large"
min_size = 2
max_size = 5
# This value is ignored after the initial creation
# https://github.com/bryantbiggs/eks-desired-size-hack
desired_size = 2
# This is not required - demonstrates how to pass additional configuration to nodeadm
# Ref https://awslabs.github.io/amazon-eks-ami/nodeadm/doc/api/
cloudinit_pre_nodeadm = [
{
content_type = "application/node.eks.aws"
content = <<-EOT
---
apiVersion: node.eks.aws/v1alpha1
kind: NodeConfig
spec:
kubelet:
config:
shutdownGracePeriod: 30s
featureGates:
DisableKubeletCloudCredentialProviders: true
EOT
}
]
}
}
tags = local.tags
}

View File

@@ -0,0 +1,52 @@
module "eks_bottlerocket" {
source = "terraform-aws-modules/eks/aws"
version = "~> 20.0"
cluster_name = "${local.name}-bottlerocket"
cluster_version = "1.30"
# EKS Addons
cluster_addons = {
coredns = {}
eks-pod-identity-agent = {}
kube-proxy = {}
vpc-cni = {}
}
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
self_managed_node_groups = {
example = {
ami_type = "BOTTLEROCKET_x86_64"
instance_type = "m6i.large"
min_size = 2
max_size = 5
# This value is ignored after the initial creation
# https://github.com/bryantbiggs/eks-desired-size-hack
desired_size = 2
# This is not required - demonstrates how to pass additional configuration
# Ref https://bottlerocket.dev/en/os/1.19.x/api/settings/
bootstrap_extra_args = <<-EOT
# The admin host container provides SSH access and runs with "superpowers".
# It is disabled by default, but can be disabled explicitly.
[settings.host-containers.admin]
enabled = false
# The control host container provides out-of-band access via SSM.
# It is enabled by default, and can be disabled if you do not expect to use SSM.
# This could leave you with no way to access the API and change settings on an existing node!
[settings.host-containers.control]
enabled = true
# extra args added
[settings.kernel]
lockdown = "integrity"
EOT
}
}
tags = local.tags
}

View File

@@ -0,0 +1,49 @@
provider "aws" {
region = local.region
}
data "aws_availability_zones" "available" {}
locals {
name = "ex-self-mng"
region = "eu-west-1"
vpc_cidr = "10.0.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)
tags = {
Example = local.name
GithubRepo = "terraform-aws-eks"
GithubOrg = "terraform-aws-modules"
}
}
################################################################################
# VPC
################################################################################
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.0"
name = local.name
cidr = local.vpc_cidr
azs = local.azs
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 48)]
intra_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 52)]
enable_nat_gateway = true
single_nat_gateway = true
public_subnet_tags = {
"kubernetes.io/role/elb" = 1
}
private_subnet_tags = {
"kubernetes.io/role/internal-elb" = 1
}
tags = local.tags
}

View File

@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.3.2"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.40"
}
}
}