Skip to content

Commit 1d40b81

Browse files
daroga0002Dawid Rogaczewski
authored and
Dawid Rogaczewski
committed
update examples
1 parent 19364b7 commit 1d40b81

File tree

14 files changed

+210
-27
lines changed

14 files changed

+210
-27
lines changed

examples/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Examples
2+
3+
Examples are created to help users understand and build EKS clusters using this module. Examples are helpful for some Proof of Concept build and are focusing on showing usage of different possibilities.
4+
5+
> Important
6+
>
7+
> Examples should not be used for production deployments. Examples try to be simple and not consistently implement best practices in areas of high availability or security.
8+
9+
## Example rules
10+
11+
- each example is independent of each other and can be created independently
12+
- there is implemented additional random suffix so the same example should be able to be launched on the same AWS account
13+
- each example requires some generic resources like VPC, subnets and etc., which are embedded into the standard `generic.tf` file. The file is exactly the same across all examples
14+
- by default example is launched in `eu-west-1` region. To launch it in another region just override the region variable in terraform using `terraform apply -var=region=us-east-1`

examples/bottlerocket/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module "eks" {
88
cluster_endpoint_public_access = true
99

1010
write_kubeconfig = false
11-
manage_aws_auth = false
11+
manage_aws_auth = true
1212

1313
worker_groups_launch_template = [
1414
{

examples/fargate/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Note that this example may create resources which cost money. Run `terraform des
3737
| Name | Source | Version |
3838
|------|--------|---------|
3939
| <a name="module_eks"></a> [eks](#module\_eks) | ../.. | |
40+
| <a name="module_fargate_profile_existing_cluster"></a> [fargate\_profile\_existing\_cluster](#module\_fargate\_profile\_existing\_cluster) | ../../modules/fargate | |
4041
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.7.0 |
4142

4243
## Resources

examples/fargate/main.tf

+85
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ module "eks" {
99
subnets = [module.vpc.private_subnets[0], module.vpc.public_subnets[1]]
1010
fargate_subnets = [module.vpc.private_subnets[2]]
1111

12+
# You require a node group to schedule coredns which is critical for running correctly internal DNS.
13+
# If you want to use only fargate you must follow docs `(Optional) Update CoreDNS`
14+
# available under https://docs.aws.amazon.com/eks/latest/userguide/fargate-getting-started.html
15+
node_groups = {
16+
example = {
17+
desired_capacity = 1
18+
19+
instance_types = ["t3.large"]
20+
k8s_labels = {
21+
Example = "managed_node_groups"
22+
GithubRepo = "terraform-aws-eks"
23+
GithubOrg = "terraform-aws-modules"
24+
}
25+
additional_tags = {
26+
ExtraTag = "example"
27+
}
28+
update_config = {
29+
max_unavailable_percentage = 50 # or set `max_unavailable`
30+
}
31+
}
32+
}
33+
1234
fargate_profiles = {
1335
default = {
1436
name = "default"
@@ -62,3 +84,66 @@ module "eks" {
6284
GithubOrg = "terraform-aws-modules"
6385
}
6486
}
87+
88+
89+
##############################################
90+
# Calling submodule with existing EKS cluster
91+
##############################################
92+
93+
module "fargate_profile_existing_cluster" {
94+
source = "../../modules/fargate"
95+
96+
cluster_name = module.eks.cluster_id
97+
subnets = [module.vpc.private_subnets[0], module.vpc.private_subnets[2]]
98+
99+
fargate_profiles = {
100+
profile1 = {
101+
name = "profile1"
102+
selectors = [
103+
{
104+
namespace = "kube-system"
105+
labels = {
106+
k8s-app = "kube-dns"
107+
}
108+
},
109+
{
110+
namespace = "profile"
111+
labels = {
112+
WorkerType = "fargate"
113+
}
114+
}
115+
]
116+
117+
tags = {
118+
Owner = "profile1"
119+
submodule = "true"
120+
}
121+
}
122+
123+
profile2 = {
124+
name = "profile2"
125+
selectors = [
126+
{
127+
namespace = "default"
128+
labels = {
129+
Fargate = "profile2"
130+
}
131+
}
132+
]
133+
134+
# Using specific subnets instead of the ones configured in EKS (`subnets` and `fargate_subnets`)
135+
subnets = [module.vpc.private_subnets[0]]
136+
137+
tags = {
138+
Owner = "profile2"
139+
submodule = "true"
140+
}
141+
}
142+
}
143+
144+
tags = {
145+
Example = var.example_name
146+
GithubRepo = "terraform-aws-eks"
147+
GithubOrg = "terraform-aws-modules"
148+
}
149+
}

examples/instance_refresh/main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ provider "helm" {
77
token = data.aws_eks_cluster_auth.cluster.token
88
}
99
}
10+
1011
data "aws_caller_identity" "current" {}
1112

1213
data "aws_iam_policy_document" "aws_node_termination_handler" {

examples/irsa/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Note that this example may create resources which cost money. Run `terraform des
2121
|------|---------|
2222
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
2323
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.22.0 |
24+
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | ~> 2.1.2 |
2425
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 2.0.0 |
2526
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 2.0.0 |
2627
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.1 |
@@ -30,6 +31,7 @@ Note that this example may create resources which cost money. Run `terraform des
3031
| Name | Version |
3132
|------|---------|
3233
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.22.0 |
34+
| <a name="provider_helm"></a> [helm](#provider\_helm) | ~> 2.1.2 |
3335
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.1 |
3436

3537
## Modules
@@ -45,6 +47,7 @@ Note that this example may create resources which cost money. Run `terraform des
4547
| Name | Type |
4648
|------|------|
4749
| [aws_iam_policy.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
50+
| [helm_release.cluster-autoscaler](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
4851
| [random_string.suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
4952
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
5053
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |

examples/irsa/cluster-autoscaler-chart-values.yaml

-14
This file was deleted.

examples/irsa/irsa.tf

+48-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,54 @@ data "aws_caller_identity" "current" {}
22

33
locals {
44
k8s_service_account_namespace = "kube-system"
5-
k8s_service_account_name = "cluster-autoscaler-aws-cluster-autoscaler-chart"
5+
k8s_service_account_name = "cluster-autoscaler-aws"
6+
}
7+
8+
provider "helm" {
9+
kubernetes {
10+
host = data.aws_eks_cluster.cluster.endpoint
11+
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority[0].data)
12+
token = data.aws_eks_cluster_auth.cluster.token
13+
}
14+
}
15+
16+
resource "helm_release" "cluster-autoscaler" {
17+
depends_on = [
18+
module.eks
19+
]
20+
21+
name = "cluster-autoscaler"
22+
namespace = local.k8s_service_account_namespace
23+
repository = "https://kubernetes.github.io/autoscaler"
24+
chart = "cluster-autoscaler"
25+
version = "9.10.7"
26+
create_namespace = false
27+
28+
set {
29+
name = "awsRegion"
30+
value = var.region
31+
}
32+
set {
33+
name = "rbac.serviceAccount.name"
34+
value = local.k8s_service_account_name
35+
}
36+
set {
37+
name = "rbac.serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"
38+
value = module.iam_assumable_role_admin.iam_role_arn
39+
type = "string"
40+
}
41+
set {
42+
name = "autoDiscovery.clusterName"
43+
value = local.cluster_name
44+
}
45+
set {
46+
name = "autoDiscovery.enabled"
47+
value = "true"
48+
}
49+
set {
50+
name = "rbac.create"
51+
value = "true"
52+
}
653
}
754

855
module "iam_assumable_role_admin" {

examples/irsa/main.tf

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module "eks" {
1414
name = "worker-group-1"
1515
instance_type = "t3.medium"
1616
asg_desired_capacity = 1
17+
asg_max_size = 4
1718
tags = [
1819
{
1920
"key" = "k8s.io/cluster-autoscaler/enabled"
@@ -34,3 +35,5 @@ module "eks" {
3435
GithubOrg = "terraform-aws-modules"
3536
}
3637
}
38+
39+

examples/irsa/versions.tf

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ terraform {
66
local = ">= 2.0.0"
77
random = ">= 2.1"
88
kubernetes = ">= 2.0.0"
9+
helm = "~> 2.1.2"
910
}
1011
}

examples/launch_templates_with_managed_node_groups/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Note that this example may create resources which cost money. Run `terraform des
5555
| Name | Description | Type | Default | Required |
5656
|------|-------------|------|---------|:--------:|
5757
| <a name="input_cluster_version"></a> [cluster\_version](#input\_cluster\_version) | EKS version | `string` | `"1.20"` | no |
58-
| <a name="input_example_name"></a> [example\_name](#input\_example\_name) | Example name | `string` | `"launch_templates_with_managed_node_groups"` | no |
58+
| <a name="input_example_name"></a> [example\_name](#input\_example\_name) | Example name | `string` | `"lt_with_managed_node_groups"` | no |
5959
| <a name="input_instance_types"></a> [instance\_types](#input\_instance\_types) | Instance types | `list(string)` | <pre>[<br> "t3.small"<br>]</pre> | no |
6060
| <a name="input_region"></a> [region](#input\_region) | AWS region where example will be created | `string` | `"eu-west-1"` | no |
6161

examples/launch_templates_with_managed_node_groups/main.tf

+33-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module "eks" {
88
cluster_endpoint_public_access = true
99

1010
node_groups = {
11-
example = {
11+
example1 = {
12+
name_prefix = "example1"
1213
desired_capacity = 1
1314
max_capacity = 15
1415
min_capacity = 1
@@ -19,9 +20,39 @@ module "eks" {
1920
instance_types = var.instance_types
2021

2122
additional_tags = {
22-
ExtraTag = "example"
23+
ExtraTag = "example1"
2324
}
2425
}
26+
example2 = {
27+
create_launch_template = true
28+
desired_capacity = 1
29+
max_capacity = 10
30+
min_capacity = 1
31+
32+
disk_size = 50
33+
disk_type = "gp3"
34+
disk_throughput = 150
35+
disk_iops = 3000
36+
37+
instance_types = ["t3.large"]
38+
capacity_type = "SPOT"
39+
k8s_labels = {
40+
GithubRepo = "terraform-aws-eks"
41+
GithubOrg = "terraform-aws-modules"
42+
}
43+
additional_tags = {
44+
ExtraTag = "example2"
45+
}
46+
taints = [
47+
{
48+
key = "dedicated"
49+
value = "gpuGroup"
50+
effect = "NO_SCHEDULE"
51+
}
52+
]
53+
update_config = {
54+
max_unavailable_percentage = 50 # or set `max_unavailable`
55+
}
2556
}
2657

2758
tags = {

examples/launch_templates_with_managed_node_groups/variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ variable "region" {
77
variable "example_name" {
88
type = string
99
description = "Example name"
10-
default = "launch_templates_with_managed_node_groups"
10+
default = "lt_with_managed_node_groups"
1111
}
1212

1313
variable "cluster_version" {

examples/managed_node_groups/main.tf

+18-7
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,10 @@ module "eks" {
1414

1515
node_groups = {
1616
example = {
17-
create_launch_template = true
18-
1917
desired_capacity = 1
2018
max_capacity = 10
2119
min_capacity = 1
2220

23-
disk_size = 50
24-
disk_type = "gp3"
25-
disk_throughput = 150
26-
disk_iops = 3000
27-
2821
instance_types = ["t3.large"]
2922
capacity_type = "SPOT"
3023
k8s_labels = {
@@ -46,6 +39,24 @@ module "eks" {
4639
max_unavailable_percentage = 50 # or set `max_unavailable`
4740
}
4841
}
42+
example2 = {
43+
desired_capacity = 1
44+
max_capacity = 10
45+
min_capacity = 1
46+
47+
instance_types = ["t3.medium"]
48+
k8s_labels = {
49+
Example = "managed_node_groups"
50+
GithubRepo = "terraform-aws-eks"
51+
GithubOrg = "terraform-aws-modules"
52+
}
53+
additional_tags = {
54+
ExtraTag = "example2"
55+
}
56+
update_config = {
57+
max_unavailable_percentage = 50 # or set `max_unavailable`
58+
}
59+
}
4960
}
5061

5162
map_roles = var.map_roles

0 commit comments

Comments
 (0)