-
Notifications
You must be signed in to change notification settings - Fork 24
/
addons.tf
369 lines (346 loc) · 13.7 KB
/
addons.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# Derived from Data On EKS under Apache License 2.0.
# Source: https://github.com/awslabs/data-on-eks/tree/main/ai-ml/jupyterhub
# See LICENSE file in the root directory of this source code or at http://www.apache.org/licenses/LICENSE-2.0.html.
# Use this data source to get the ARN of a certificate in AWS Certificate Manager (ACM)
# data "aws_acm_certificate" "issued" {
# count = var.jupyter_hub_auth_mechanism == "cognito" ? 1 : 0
# domain = var.acm_certificate_domain
# statuses = ["ISSUED"]
# }
data "aws_ecrpublic_authorization_token" "token" {
provider = aws.ecr
}
locals {
cognito_custom_domain = var.cognito_custom_domain
}
#---------------------------------------------------------------
# IRSA for EBS CSI Driver
#---------------------------------------------------------------
module "ebs_csi_driver_irsa" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "~> 5.20"
role_name_prefix = format("%s-%s", local.name, "ebs-csi-driver-")
attach_ebs_csi_policy = true
oidc_providers = {
main = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = ["kube-system:ebs-csi-controller-sa"]
}
}
tags = local.tags
}
module "eks_blueprints_addons" {
source = "aws-ia/eks-blueprints-addons/aws"
version = "~> 1.2"
cluster_name = module.eks.cluster_name
cluster_endpoint = module.eks.cluster_endpoint
cluster_version = module.eks.cluster_version
oidc_provider_arn = module.eks.oidc_provider_arn
#---------------------------------------
# Amazon EKS Managed Add-ons
#---------------------------------------
eks_addons = {
aws-ebs-csi-driver = {
service_account_role_arn = module.ebs_csi_driver_irsa.iam_role_arn
}
coredns = {
preserve = true
}
vpc-cni = {
preserve = true
}
kube-proxy = {
preserve = true
}
}
#---------------------------------------
# Kubernetes Add-ons
#---------------------------------------
#---------------------------------------------------------------
# CoreDNS Autoscaler helps to scale for large EKS Clusters
# Further tuning for CoreDNS is to leverage NodeLocal DNSCache -> https://kubernetes.io/docs/tasks/administer-cluster/nodelocaldns/
#---------------------------------------------------------------
enable_cluster_proportional_autoscaler = true
cluster_proportional_autoscaler = {
timeout = "300"
values = [templatefile("${path.module}/helm/coredns-autoscaler/values.yaml", {
target = "deployment/coredns"
})]
description = "Cluster Proportional Autoscaler for CoreDNS Service"
}
#---------------------------------------
# Metrics Server
#---------------------------------------
enable_metrics_server = false
metrics_server = {
timeout = "300"
values = [templatefile("${path.module}/helm/metrics-server/values.yaml", {})]
}
#---------------------------------------
# Cluster Autoscaler
#---------------------------------------
enable_cluster_autoscaler = true
cluster_autoscaler = {
timeout = "300"
create_role = true
values = [templatefile("${path.module}/helm/cluster-autoscaler/values.yaml", {
aws_region = var.region,
eks_cluster_id = module.eks.cluster_name
})]
}
#---------------------------------------
# Karpenter Autoscaler for EKS Cluster
#---------------------------------------
enable_karpenter = true
karpenter_enable_spot_termination = true
karpenter = {
timeout = "300"
repository_username = data.aws_ecrpublic_authorization_token.token.user_name
repository_password = data.aws_ecrpublic_authorization_token.token.password
values = [<<EOT
controller:
image:
repository: public.ecr.aws/karpenter/controller
tag: "0.35.0"
digest: "sha256:48d1246f6b2066404e300cbf3e26d0bcdc57a76531dcb634d571f4f0e050cb57"
EOT
]
}
#---------------------------------------
# AWS Load Balancer Controller
#---------------------------------------
enable_aws_load_balancer_controller = true
#---------------------------------------
# Prometheus and Grafana stack
#---------------------------------------
#---------------------------------------------------------------
# Install Monitoring Stack with Prometheus and Grafana
# 1- Grafana port-forward `kubectl port-forward svc/kube-prometheus-stack-grafana 8080:80 -n kube-prometheus-stack`
# 2- Grafana Admin user: admin
# 3- Get admin user password: `aws secretsmanager get-secret-value --secret-id <output.grafana_secret_name> --region $AWS_REGION --query "SecretString" --output text`
#---------------------------------------------------------------
enable_kube_prometheus_stack = false
kube_prometheus_stack = {
values = [templatefile("${path.module}/helm/kube-prometheus-stack/values.yaml", {})]
chart_version = "48.1.1"
set_sensitive = [
{
name = "grafana.adminPassword"
value = data.aws_secretsmanager_secret_version.admin_password_version.secret_string
}
],
}
#---------------------------------------
# AWS for FluentBit
#---------------------------------------
enable_aws_for_fluentbit = true
aws_for_fluentbit_cw_log_group = {
use_name_prefix = false
name = "/${local.name}/aws-fluentbit-logs" # Add-on creates this log group
retention_in_days = 30
}
aws_for_fluentbit = {
values = [templatefile("${path.module}/helm/aws-for-fluentbit/values.yaml", {
region = local.region,
cloudwatch_log_group = "/${local.name}/aws-fluentbit-logs"
cluster_name = module.eks.cluster_name
})]
}
#---------------------------------------
# Additional Helm Charts
#---------------------------------------
helm_releases = {
storageclass = {
name = "storageclass"
description = "A Helm chart for storage configurations"
chart = "${path.module}/helm/storageclass"
}
karpenter-resources-cpu = {
name = "karpenter-resources-cpu"
description = "A Helm chart for karpenter CPU based resources"
chart = "${path.module}/helm/karpenter-resources"
values = [
<<-EOT
clusterName: ${module.eks.cluster_name}
karpenterRole: ${split("/", module.eks_blueprints_addons.karpenter.node_iam_role_arn)[1]}
capacityTypes: ["spot"]
EOT
]
}
karpenter-resources-cpu-on-demand = {
name = "karpenter-resources-cpu-on-demand"
description = "A Helm chart for karpenter CPU based resources"
chart = "${path.module}/helm/karpenter-resources"
values = [
<<-EOT
name: cpu-on-demand
clusterName: ${module.eks.cluster_name}
instanceSizes: ["xlarge", "2xlarge", "4xlarge", "8xlarge", "16xlarge", "24xlarge"]
instanceFamilies: ["c5", "m5", "r5"]
karpenterRole: ${split("/", module.eks_blueprints_addons.karpenter.node_iam_role_arn)[1]}
capacityTypes: ["on-demand"]
EOT
]
}
# karpenter-resources-ts = {
# name = "karpenter-resources-ts"
# description = "A Helm chart for karpenter GPU based resources - compatible with GPU time slicing"
# chart = "${path.module}/helm/karpenter-resources"
# values = [
# <<-EOT
# name: gpu-ts
# clusterName: ${module.eks.cluster_name}
# karpenterRole: ${split("/", module.eks_blueprints_addons.karpenter.node_iam_role_arn)[1]}
# instanceSizes: ["xlarge", "2xlarge", "4xlarge", "8xlarge", "16xlarge", "24xlarge"]
# instanceFamilies: ["g5"]
# taints:
# - key: hub.jupyter.org/dedicated
# value: "user"
# effect: "NoSchedule"
# - key: nvidia.com/gpu
# effect: "NoSchedule"
# amiFamily: Ubuntu
# EOT
# ]
# }
karpenter-resources-mig = {
name = "karpenter-resources-gpu"
description = "A Helm chart for karpenter GPU based resources - compatible with g4dn instances"
chart = "${path.module}/helm/karpenter-resources"
values = [
<<-EOT
name: gpu
clusterName: ${module.eks.cluster_name}
karpenterRole: ${split("/", module.eks_blueprints_addons.karpenter.node_iam_role_arn)[1]}
instanceSizes: ["2xlarge"]
instanceFamilies: ["g4dn"]
taints:
- key: hub.jupyter.org/dedicated
value: "user"
effect: "NoSchedule"
- key: nvidia.com/gpu
effect: "NoSchedule"
amiFamily: Ubuntu
EOT
]
}
# karpenter-resources-inf = {
# name = "karpenter-resources-inf"
# description = "A Helm chart for karpenter Inferentia based resources"
# chart = "${path.module}/helm/karpenter-resources"
# values = [
# <<-EOT
# name: inferentia
# clusterName: ${module.eks.cluster_name}
# karpenterRole: ${split("/", module.eks_blueprints_addons.karpenter.node_iam_role_arn)[1]}
# instanceSizes: ["8xlarge", "24xlarge"]
# instanceFamilies: ["inf2"]
# taints:
# - key: aws.amazon.com/neuroncore
# value: "true"
# effect: "NoSchedule"
# - key: aws.amazon.com/neuron
# value: "true"
# effect: "NoSchedule"
# - key: hub.jupyter.org/dedicated
# value: "user"
# effect: "NoSchedule"
# EOT
# ]
# }
# karpenter-resources-trn = {
# name = "karpenter-resources-trn"
# description = "A Helm chart for karpenter Trainium based resources"
# chart = "${path.module}/helm/karpenter-resources"
# values = [
# <<-EOT
# name: trainium
# clusterName: ${module.eks.cluster_name}
# karpenterRole: ${split("/", module.eks_blueprints_addons.karpenter.node_iam_role_arn)[1]}
# instanceSizes: ["32xlarge"]
# instanceFamilies: ["trn1"]
# taints:
# - key: aws.amazon.com/neuroncore
# value: "true"
# effect: "NoSchedule"
# - key: aws.amazon.com/neuron
# value: "true"
# effect: "NoSchedule"
# - key: hub.jupyter.org/dedicated
# value: "user"
# effect: "NoSchedule"
# EOT
# ]
# }
}
tags = local.tags
}
#---------------------------------------------------------------
# Data on EKS Kubernetes Addons
#---------------------------------------------------------------
module "eks_data_addons" {
source = "aws-ia/eks-data-addons/aws"
version = "~> 1.0" # ensure to update this to the latest/desired version
oidc_provider_arn = module.eks.oidc_provider_arn
#---------------------------------------------------------------
# Enable Neuron Device Plugin
#---------------------------------------------------------------
enable_aws_neuron_device_plugin = false
#---------------------------------------------------------------
# Enable GPU operator
#---------------------------------------------------------------
enable_nvidia_gpu_operator = true
nvidia_gpu_operator_helm_config = {
values = [templatefile("${path.module}/helm/nvidia-gpu-operator/values.yaml", {})]
version = "23.9.2"
}
#---------------------------------------------------------------
# JupyterHub Add-on
#---------------------------------------------------------------
enable_jupyterhub = true
jupyterhub_helm_config = {
values = [templatefile("${path.module}/envs/${terraform.workspace}/managed-jupyterhub.yaml", {
client_id = var.github_client_id
client_secret = var.github_client_secret
ssl_cert_arn = try(var.aws_certificate_arn, "")
jupyterhub_domain = var.jupyterhub_domain
jupyter_single_user_sa_name = kubernetes_service_account_v1.jupyterhub_single_user_sa.metadata[0].name
region = var.region
singleuser_image_repo = var.singleuser_image_repo
singleuser_image_tag = var.singleuser_image_tag
danditoken = var.danditoken
dandi_api_domain = var.dandi_api_domain
})]
version = "3.3.5"
}
#---------------------------------------------------------------
# Kubecost Add-on
#---------------------------------------------------------------
enable_kubecost = false
kubecost_helm_config = {
values = [templatefile("${path.module}/helm/kubecost/values.yaml", {})]
repository_username = data.aws_ecrpublic_authorization_token.token.user_name
repository_password = data.aws_ecrpublic_authorization_token.token.password
}
}
#---------------------------------------------------------------
# Grafana Admin credentials resources
#---------------------------------------------------------------
data "aws_secretsmanager_secret_version" "admin_password_version" {
secret_id = aws_secretsmanager_secret.grafana.id
depends_on = [aws_secretsmanager_secret_version.grafana]
}
resource "random_password" "grafana" {
length = 16
special = true
override_special = "@_"
}
#tfsec:ignore:aws-ssm-secret-use-customer-key
resource "aws_secretsmanager_secret" "grafana" {
name_prefix = "${local.name}-grafana-"
recovery_window_in_days = 0 # Set to zero for this example to force delete during Terraform destroy
}
resource "aws_secretsmanager_secret_version" "grafana" {
secret_id = aws_secretsmanager_secret.grafana.id
secret_string = random_password.grafana.result
}