Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[single-cluster/eks] Add cluster-autoscaler #12577

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions install/infra/modules/eks/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ output "secretAccessKey" {
value = try("${aws_iam_access_key.edns[0].secret}", "")
}

output "oidc_provider_arn" {
sensitive = false
value = module.eks.oidc_provider_arn
}

output "cluster_id" {
sensitive = false
value = module.eks.cluster_id
}

output "cert_manager_issuer" {
value = try({
region = var.region
Expand Down
70 changes: 70 additions & 0 deletions install/infra/modules/tools/aws-cluster-autoscaler/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
variable "kubeconfig" {
description = "Path to the KUBECONFIG file to connect to the cluster"
default = "./kubeconfig"
}

variable "region" {}
variable "cluster_name" {}
variable "cluster_id" {}
variable "oidc_provider_arn" {}

provider "helm" {
kubernetes {
config_path = var.kubeconfig
}
}

module "cluster_autoscaler_irsa_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "~> 4.12"

role_name_prefix = "cluster-autoscaler"
attach_cluster_autoscaler_policy = true
cluster_autoscaler_cluster_ids = [var.cluster_id]

oidc_providers = {
ex = {
provider_arn = var.oidc_provider_arn
namespace_service_accounts = ["kube-system:cluster-autoscaler"]
}
}
}

# AWS cluster auto-scaler Deployment using Helm
resource "helm_release" "cluster_autoscaler" {
name = "cluster-autoscaler"
repository = "https://kubernetes.github.io/autoscaler"
chart = "cluster-autoscaler"
version = "9.20.1"
namespace = "kube-system"

values = [
jsonencode({
cloudProvider = "aws"
awsRegion = var.region
autoDiscovery = {
clusterName = var.cluster_name
}

rbac = {
serviceAccount = {
name = "cluster-autoscaler"
annotations = {
"eks.amazonaws.com/role-arn" = module.cluster_autoscaler_irsa_role.iam_role_arn
}
create = true
}
}

securityContext = {
fsGroup = 65534
}
extraArgs = {
skip-nodes-with-local-storage = false
balance-similar-node-groups = true
}

})
]

}
18 changes: 15 additions & 3 deletions install/infra/single-cluster/aws/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ plan-cluster:
@terraform plan -target=module.eks

.PHONY: plan-tools
plan-tools: plan-cm-edns plan-cluster-issuer
plan-tools: plan-cm-edns plan-cluster-issuer plan-cluster-autoscaler

.PHONY: plan-cluster-autoscaler
plan-cluster-autoscaler:
@terraform plan -target=module.cluster-autoscaler

.PHONY: plan-cm-edns
plan-cm-edns:
Expand All @@ -41,7 +45,11 @@ apply-cluster:
@terraform apply -target=module.eks --auto-approve

.PHONY: apply-tools
apply-tools: install-cm-edns install-cluster-issuer
apply-tools: install-cm-edns install-cluster-issuer install-cluster-autoscaler
Pothulapati marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: install-cluster-autoscaler
install-cluster-autoscaler:
@terraform apply -target=module.cluster-autoscaler --auto-approve

.PHONY: install-cm-edns
install-cm-edns:
Expand All @@ -56,7 +64,11 @@ destroy-cluster:
@terraform destroy -target=module.eks --auto-approve

.PHONY: destroy-tools
destroy-tools: destroy-cluster-issuer destroy-cm-edns
destroy-tools: destroy-cluster-issuer destroy-cm-edns destroy-cluster-autoscaler

.PHONY: destroy-cluster-autoscaler
destroy-cluster-autoscaler:
@terraform destroy -target=module.cluster-autoscaler --auto-approve

.PHONY: destroy-cm-edns
destroy-cm-edns:
Expand Down
9 changes: 9 additions & 0 deletions install/infra/single-cluster/aws/tools.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ module "cluster-issuer" {
secretAccessKey = module.eks.secretAccessKey
issuer_name = "route53"
}

module "cluster-autoscaler" {
source = "../../modules/tools/aws-cluster-autoscaler"
kubeconfig = var.kubeconfig
region = var.region
cluster_name = var.cluster_name
cluster_id = module.eks.cluster_id
oidc_provider_arn = module.eks.oidc_provider_arn
}