From 0ce4dea19763819fd9900538217b6e4dd9b3b347 Mon Sep 17 00:00:00 2001 From: Max Glotov Date: Fri, 5 Jan 2024 16:10:39 +0600 Subject: [PATCH] move karpenter into layer2-k8s instead of using a separate module --- terraform/layer1-aws/aws-eks.tf | 1 - terraform/layer1-aws/aws-vpc.tf | 13 +- terraform/layer1-aws/outputs.tf | 4 - terraform/layer1-aws/variables.tf | 8 - .../layer2-k8s/eks-cluster-autoscaler.tf | 188 ------------ terraform/layer2-k8s/eks-karpenter.tf | 268 ++++++++++++++++++ terraform/layer2-k8s/helm-releases.yaml | 16 +- terraform/layer2-k8s/variables.tf | 10 + terraform/modules/karpenter/main.tf | 79 ------ terraform/modules/karpenter/variables.tf | 33 --- .../us-east-1/aws-base/.terraform.lock.hcl | 37 --- terragrunt/demo/us-east-1/eks-providers.tf | 35 --- .../demo/us-east-1/k8s-addons/terragrunt.hcl | 30 +- .../us-east-1/karpenter/.terraform.lock.hcl | 82 ------ .../demo/us-east-1/karpenter/terragrunt.hcl | 167 ----------- terragrunt/terragrunt.hcl | 27 -- 16 files changed, 314 insertions(+), 684 deletions(-) delete mode 100644 terraform/layer2-k8s/eks-cluster-autoscaler.tf create mode 100644 terraform/layer2-k8s/eks-karpenter.tf delete mode 100644 terraform/modules/karpenter/main.tf delete mode 100644 terraform/modules/karpenter/variables.tf delete mode 100644 terragrunt/demo/us-east-1/eks-providers.tf delete mode 100644 terragrunt/demo/us-east-1/karpenter/.terraform.lock.hcl delete mode 100644 terragrunt/demo/us-east-1/karpenter/terragrunt.hcl diff --git a/terraform/layer1-aws/aws-eks.tf b/terraform/layer1-aws/aws-eks.tf index b3e9e650..df5b5995 100644 --- a/terraform/layer1-aws/aws-eks.tf +++ b/terraform/layer1-aws/aws-eks.tf @@ -78,7 +78,6 @@ module "eks" { } } - # iam_role_additional_policies = var.eks_workers_additional_policies metadata_options = { http_endpoint = "enabled" http_tokens = "required" diff --git a/terraform/layer1-aws/aws-vpc.tf b/terraform/layer1-aws/aws-vpc.tf index 37dea51d..5663c53e 100644 --- a/terraform/layer1-aws/aws-vpc.tf +++ b/terraform/layer1-aws/aws-vpc.tf @@ -28,11 +28,12 @@ module "vpc" { database_subnets = local.database_subnets intra_subnets = local.intra_subnets - single_nat_gateway = var.single_nat_gateway - enable_nat_gateway = true - enable_vpn_gateway = false - enable_dns_hostnames = true - enable_dns_support = true + single_nat_gateway = var.single_nat_gateway + enable_nat_gateway = true + enable_vpn_gateway = false + enable_dns_hostnames = true + enable_dns_support = true + map_public_ip_on_launch = true create_database_subnet_group = false @@ -47,6 +48,7 @@ module "vpc" { private_subnet_tags = { Name = "${local.name}-private" destination = "private" + "karpenter.sh/discovery" = "private" "kubernetes.io/role/internal-elb" = "1" } @@ -58,6 +60,7 @@ module "vpc" { public_subnet_tags = { Name = "${local.name}-public" destination = "public" + "karpenter.sh/discovery" = "public" "kubernetes.io/role/elb" = "1" } diff --git a/terraform/layer1-aws/outputs.tf b/terraform/layer1-aws/outputs.tf index 10a1ebc6..d2069e4b 100644 --- a/terraform/layer1-aws/outputs.tf +++ b/terraform/layer1-aws/outputs.tf @@ -109,10 +109,6 @@ output "ssl_certificate_arn" { value = local.ssl_certificate_arn } -output "node_group_default_iam_instance_profile_id" { - value = module.eks.self_managed_node_groups["default"].iam_instance_profile_id -} - output "node_group_default_iam_role_arn" { value = module.eks.self_managed_node_groups["default"].iam_role_arn } diff --git a/terraform/layer1-aws/variables.tf b/terraform/layer1-aws/variables.tf index 2b32f86f..6e57e779 100644 --- a/terraform/layer1-aws/variables.tf +++ b/terraform/layer1-aws/variables.tf @@ -117,14 +117,6 @@ variable "eks_cluster_version" { description = "Version of the EKS K8S cluster" } -# variable "eks_workers_additional_policies" { -# type = map(string) -# default = { -# additional = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore" -# } -# description = "Additional IAM policy attached to EKS worker nodes" -# } - variable "node_group_default" { type = object({ instance_type = string diff --git a/terraform/layer2-k8s/eks-cluster-autoscaler.tf b/terraform/layer2-k8s/eks-cluster-autoscaler.tf deleted file mode 100644 index e80730b1..00000000 --- a/terraform/layer2-k8s/eks-cluster-autoscaler.tf +++ /dev/null @@ -1,188 +0,0 @@ -locals { - cluster_autoscaler = { - name = local.helm_releases[index(local.helm_releases.*.id, "cluster-autoscaler")].id - enabled = local.helm_releases[index(local.helm_releases.*.id, "cluster-autoscaler")].enabled - chart = local.helm_releases[index(local.helm_releases.*.id, "cluster-autoscaler")].chart - repository = local.helm_releases[index(local.helm_releases.*.id, "cluster-autoscaler")].repository - chart_version = local.helm_releases[index(local.helm_releases.*.id, "cluster-autoscaler")].chart_version - namespace = local.helm_releases[index(local.helm_releases.*.id, "cluster-autoscaler")].namespace - } - cluster_autoscaler_values = <