Skip to content

Commit 1ee6db9

Browse files
committed
separate cluster creation and node creation
Signed-off-by: Tarun Pothulapati <[email protected]>
1 parent a6c1890 commit 1ee6db9

File tree

1 file changed

+72
-122
lines changed

1 file changed

+72
-122
lines changed

install/infra/modules/eks/kubernetes.tf

Lines changed: 72 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ module "eks" {
8888
coredns = {
8989
resolve_conflicts = "OVERWRITE"
9090
}
91+
vpc-cni = {
92+
resolve_conflicts = "OVERWRITE"
93+
service_account_role_arn = module.vpc_cni_irsa.iam_role_arn
94+
}
9195
kube-proxy = {}
9296
}
9397

@@ -112,122 +116,65 @@ module "eks" {
112116
service containerd restart
113117
EOT
114118
}
119+
}
115120

116-
eks_managed_node_groups = {
117-
Services = {
118-
enable_bootstrap_user_data = true
119-
instance_types = [var.service_machine_type]
120-
name = "service-${var.cluster_name}"
121-
iam_role_name = format("%s-%s", substr("${var.cluster_name}-svc-ng", 0, 58), random_string.ng_role_suffix.result)
122-
subnet_ids = module.vpc.public_subnets
123-
min_size = 1
124-
max_size = 4
125-
desired_size = 2
126-
block_device_mappings = [{
127-
device_name = "/dev/sda1"
128-
129-
ebs = [{
130-
volume_size = 300
131-
volume_type = "gp3"
132-
throughput = 500
133-
iops = 6000
134-
delete_on_termination = true
135-
}]
136-
}]
137-
labels = {
138-
"gitpod.io/workload_meta" = true
139-
"gitpod.io/workload_ide" = true
140-
"gitpod.io/workload_workspace_services" = true
141-
}
142-
143-
tags = {
144-
"k8s.io/cluster-autoscaler/enabled" = true
145-
"k8s.io/cluster-autoscaler/gitpod" = "owned"
146-
}
147-
148-
pre_bootstrap_user_data = <<-EOT
149-
#!/bin/bash
150-
set -ex
151-
cat <<-EOF > /etc/profile.d/bootstrap.sh
152-
export CONTAINER_RUNTIME="containerd"
153-
export USE_MAX_PODS=false
154-
EOF
155-
# Source extra environment variables in bootstrap script
156-
sed -i '/^set -o errexit/a\\nsource /etc/profile.d/bootstrap.sh' /etc/eks/bootstrap.sh
157-
EOT
158-
}
121+
resource "null_resource" "kubeconfig" {
122+
depends_on = [module.eks]
123+
provisioner "local-exec" {
124+
command = "aws eks update-kubeconfig --region ${var.region} --name ${var.cluster_name} --kubeconfig ${var.kubeconfig}"
125+
}
159126

160-
RegularWorkspaces = {
161-
instance_types = [var.workspace_machine_type]
162-
name = "ws-regular-${var.cluster_name}"
163-
iam_role_name = format("%s-%s", substr("${var.cluster_name}-regular-ws-ng", 0, 58), random_string.ng_role_suffix.result)
164-
subnet_ids = module.vpc.public_subnets
165-
min_size = 1
166-
max_size = 50
167-
block_device_mappings = [{
168-
device_name = "/dev/sda1"
169-
170-
ebs = [{
171-
volume_size = 512
172-
volume_type = "gp3"
173-
throughput = 500
174-
iops = 6000
175-
delete_on_termination = true
176-
}]
177-
}]
178-
desired_size = 2
179-
enable_bootstrap_user_data = true
180-
labels = {
181-
"gitpod.io/workload_workspace_regular" = true
182-
}
183-
184-
tags = {
185-
"k8s.io/cluster-autoscaler/enabled" = true
186-
"k8s.io/cluster-autoscaler/gitpod" = "owned"
187-
}
188-
189-
pre_bootstrap_user_data = <<-EOT
190-
#!/bin/bash
191-
set -ex
192-
cat <<-EOF > /etc/profile.d/bootstrap.sh
193-
export CONTAINER_RUNTIME="containerd"
194-
export USE_MAX_PODS=false
195-
EOF
196-
# Source extra environment variables in bootstrap script
197-
sed -i '/^set -o errexit/a\\nsource /etc/profile.d/bootstrap.sh' /etc/eks/bootstrap.sh
198-
EOT
199-
}
127+
lifecycle {
128+
create_before_destroy = true
129+
}
130+
}
131+
132+
// Install Calico Here
133+
134+
module "service-nodes" {
135+
depends_on = [module.eks]
136+
137+
source = "terraform-aws-modules/eks/aws//modules/eks-managed-node-group"
138+
version = "18.30.0"
139+
140+
cluster_name = var.cluster_name
141+
cluster_version = var.cluster_version
142+
cluster_endpoint = module.eks.cluster_endpoint
143+
cluster_auth_base64 = module.eks.cluster_certificate_authority_data
144+
145+
enable_bootstrap_user_data = true
146+
instance_types = [var.service_machine_type]
147+
name = "service-${var.cluster_name}"
148+
create_iam_role = false
149+
iam_role_arn = module.vpc_cni_irsa.iam_role_arn
150+
iam_role_name = format("%s-%s", substr("${var.cluster_name}-svc-ng", 0, 58), random_string.ng_role_suffix.result)
151+
subnet_ids = module.vpc.public_subnets
152+
min_size = 1
153+
max_size = 4
154+
desired_size = 2
155+
block_device_mappings = [{
156+
device_name = "/dev/sda1"
157+
158+
ebs = [{
159+
volume_size = 300
160+
volume_type = "gp3"
161+
throughput = 500
162+
iops = 6000
163+
delete_on_termination = true
164+
}]
165+
}]
166+
labels = {
167+
"gitpod.io/workload_meta" = true
168+
"gitpod.io/workload_ide" = true
169+
"gitpod.io/workload_workspace_services" = true
170+
}
171+
172+
tags = {
173+
"k8s.io/cluster-autoscaler/enabled" = true
174+
"k8s.io/cluster-autoscaler/gitpod" = "owned"
175+
}
200176

201-
HeadlessWorkspaces = {
202-
instance_types = [var.workspace_machine_type]
203-
name = "ws-headless-${var.cluster_name}"
204-
iam_role_name = format("%s-%s", substr("${var.cluster_name}-headless-ws-ng", 0, 58), random_string.ng_role_suffix.result)
205-
subnet_ids = module.vpc.public_subnets
206-
min_size = 1
207-
max_size = 50
208-
block_device_mappings = [{
209-
device_name = "/dev/sda1"
210-
211-
ebs = [{
212-
volume_size = 512
213-
volume_type = "gp3"
214-
throughput = 500
215-
iops = 6000
216-
delete_on_termination = true
217-
}]
218-
}]
219-
desired_size = 2
220-
enable_bootstrap_user_data = true
221-
labels = {
222-
"gitpod.io/workload_workspace_headless" = true
223-
}
224-
225-
tags = {
226-
"k8s.io/cluster-autoscaler/enabled" = true
227-
"k8s.io/cluster-autoscaler/gitpod" = "owned"
228-
}
229-
230-
pre_bootstrap_user_data = <<-EOT
177+
pre_bootstrap_user_data = <<-EOT
231178
#!/bin/bash
232179
set -ex
233180
cat <<-EOF > /etc/profile.d/bootstrap.sh
@@ -237,18 +184,21 @@ module "eks" {
237184
# Source extra environment variables in bootstrap script
238185
sed -i '/^set -o errexit/a\\nsource /etc/profile.d/bootstrap.sh' /etc/eks/bootstrap.sh
239186
EOT
240-
}
241-
}
242187
}
243188

244-
resource "null_resource" "kubeconfig" {
245-
depends_on = [module.eks]
246-
provisioner "local-exec" {
247-
command = "aws eks update-kubeconfig --region ${var.region} --name ${var.cluster_name} --kubeconfig ${var.kubeconfig}"
248-
}
189+
module "vpc_cni_irsa" {
190+
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
191+
version = "~> 4.12"
249192

250-
lifecycle {
251-
create_before_destroy = true
193+
role_name_prefix = "VPC-CNI-IRSA"
194+
attach_vpc_cni_policy = true
195+
vpc_cni_enable_ipv4 = true
196+
197+
oidc_providers = {
198+
main = {
199+
provider_arn = module.eks.oidc_provider_arn
200+
namespace_service_accounts = ["kube-system:aws-node"]
201+
}
252202
}
253203
}
254204

0 commit comments

Comments
 (0)