Skip to content

Commit 19899d2

Browse files
committed
[single-cluster/eks] Add cluster-autoscaler
This commit adds the `cluster-autoscaler` component into the terraform scripts through the latest helm chart. This also uses the `cluster_autoscaler_irsa_role` module to create the relevant policy, and role which is also created as a service account and then attached to the cluster-atuoscaler component Signed-off-by: Tarun Pothulapati <[email protected]>
1 parent bf9157a commit 19899d2

File tree

4 files changed

+101
-3
lines changed

4 files changed

+101
-3
lines changed

install/infra/modules/eks/output.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ output "secretAccessKey" {
2424
value = try("${aws_iam_access_key.edns[0].secret}", "")
2525
}
2626

27+
output "oidc_provider_arn" {
28+
sensitive = false
29+
value = module.eks.oidc_provider_arn
30+
}
31+
32+
output "cluster_id" {
33+
sensitive = false
34+
value = module.eks.cluster_id
35+
}
36+
2737
output "cert_manager_issuer" {
2838
value = try({
2939
region = var.region
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
variable "kubeconfig" {
2+
description = "Path to the KUBECONFIG file to connect to the cluster"
3+
default = "./kubeconfig"
4+
}
5+
6+
variable "region" {}
7+
variable "cluster_name" {}
8+
variable "cluster_id" {}
9+
variable "oidc_provider_arn" {}
10+
11+
provider "helm" {
12+
kubernetes {
13+
config_path = var.kubeconfig
14+
}
15+
}
16+
17+
module "cluster_autoscaler_irsa_role" {
18+
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
19+
version = "~> 4.12"
20+
21+
role_name_prefix = "cluster-autoscaler"
22+
attach_cluster_autoscaler_policy = true
23+
cluster_autoscaler_cluster_ids = [var.cluster_id]
24+
25+
oidc_providers = {
26+
ex = {
27+
provider_arn = var.oidc_provider_arn
28+
namespace_service_accounts = ["kube-system:cluster-autoscaler"]
29+
}
30+
}
31+
}
32+
33+
# AWS cluster auto-scaler Deployment using Helm
34+
resource "helm_release" "cluster_autoscaler" {
35+
name = "cluster-autoscaler"
36+
repository = "https://kubernetes.github.io/autoscaler"
37+
chart = "cluster-autoscaler"
38+
version = "9.20.1"
39+
namespace = "kube-system"
40+
41+
values = [
42+
jsonencode({
43+
cloudProvider = "aws"
44+
awsRegion = var.region
45+
autoDiscovery = {
46+
clusterName = var.cluster_name
47+
}
48+
49+
serviceAccount = {
50+
name = "cluster-autoscaler"
51+
annotations = {
52+
"eks\\.amazonaws\\.com/role-arn" = module.cluster_autoscaler_irsa_role.iam_role_arn
53+
}
54+
create = true
55+
}
56+
securityContext = {
57+
fsGroup = 65534
58+
}
59+
extraArgs = {
60+
skip-nodes-with-local-storage = false
61+
balance-similar-node-groups = true
62+
}
63+
64+
})
65+
]
66+
67+
}

install/infra/single-cluster/aws/Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ plan-cluster:
2626
@terraform plan -target=module.eks
2727

2828
.PHONY: plan-tools
29-
plan-tools: plan-cm-edns plan-cluster-issuer
29+
plan-tools: plan-cm-edns plan-cluster-issuer plan-cluster-autoscaler
30+
31+
.PHONY: plan-cluster-autoscaler
32+
plan-cluster-autoscaler:
33+
@terraform plan -target=module.cluster-autoscaler
3034

3135
.PHONY: plan-cm-edns
3236
plan-cm-edns:
@@ -41,7 +45,11 @@ apply-cluster:
4145
@terraform apply -target=module.eks --auto-approve
4246

4347
.PHONY: apply-tools
44-
apply-tools: install-cm-edns install-cluster-issuer
48+
apply-tools: install-cm-edns install-cluster-issuer install-cluster-autoscaler
49+
50+
.PHONY: install-cluster-autoscaler
51+
install-cluster-autoscaler:
52+
@terraform apply -target=module.cluster-autoscaler --auto-approve
4553

4654
.PHONY: install-cm-edns
4755
install-cm-edns:
@@ -56,7 +64,11 @@ destroy-cluster:
5664
@terraform destroy -target=module.eks --auto-approve
5765

5866
.PHONY: destroy-tools
59-
destroy-tools: destroy-cluster-issuer destroy-cm-edns
67+
destroy-tools: destroy-cluster-issuer destroy-cm-edns destroy-cluster-autoscaler
68+
69+
.PHONY: destroy-cluster-autoscaler
70+
destroy-cluster-autoscaler:
71+
@terraform destroy -target=module.cluster-autoscaler --auto-approve
6072

6173
.PHONY: destroy-cm-edns
6274
destroy-cm-edns:

install/infra/single-cluster/aws/tools.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ module "cluster-issuer" {
2020
secretAccessKey = module.eks.secretAccessKey
2121
issuer_name = "route53"
2222
}
23+
24+
module "cluster-autoscaler" {
25+
source = "../../modules/tools/aws-cluster-autoscaler"
26+
kubeconfig = var.kubeconfig
27+
region = var.region
28+
cluster_name = var.cluster_name
29+
cluster_id = module.eks.cluster_id
30+
oidc_provider_arn = module.eks.oidc_provider_arn
31+
}

0 commit comments

Comments
 (0)