forked from aws-samples/eks-workshop-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addons.tf
373 lines (329 loc) · 9.47 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
370
371
372
373
data "aws_eks_addon_version" "latest" {
for_each = toset(["vpc-cni"])
addon_name = each.value
kubernetes_version = var.cluster_version
most_recent = true
}
resource "aws_eks_addon" "vpc_cni" {
cluster_name = module.eks_blueprints.eks_cluster_id
addon_name = "vpc-cni"
addon_version = data.aws_eks_addon_version.latest["vpc-cni"].version
resolve_conflicts = "OVERWRITE"
configuration_values = "{\"env\":{\"ENABLE_PREFIX_DELEGATION\":\"true\", \"ENABLE_POD_ENI\":\"true\"}}"
depends_on = [
null_resource.kubectl_set_env
]
}
locals {
ebs_csi_blocker = try(module.eks_blueprints_kubernetes_addons.aws_ebs_csi_driver.release_metadata.metadata.status, "")
}
module "eks_blueprints_kubernetes_addons" {
source = "github.com/aws-ia/terraform-aws-eks-blueprints?ref=v4.16.0//modules/kubernetes-addons"
depends_on = [
aws_eks_addon.vpc_cni
]
eks_cluster_id = module.eks_blueprints.eks_cluster_id
enable_karpenter = true
enable_aws_node_termination_handler = true
enable_aws_load_balancer_controller = true
enable_cluster_autoscaler = true
enable_metrics_server = true
enable_kubecost = true
enable_amazon_eks_adot = true
enable_aws_efs_csi_driver = true
enable_aws_for_fluentbit = true
enable_self_managed_aws_ebs_csi_driver = true
enable_crossplane = true
self_managed_aws_ebs_csi_driver_helm_config = {
set = [{
name = "node.tolerateAllTaints"
value = "true"
},
{
name = "controller.replicaCount"
value = 1
},
{
name = "controller.nodeSelector.workshop-system"
value = "yes"
type = "string"
},
{
name = "controller.tolerations[0].key"
value = "systemComponent"
type = "string"
},
{
name = "controller.tolerations[0].operator"
value = "Exists"
type = "string"
},
{
name = "controller.tolerations[0].effect"
value = "NoSchedule"
type = "string"
}]
}
cluster_autoscaler_helm_config = {
version = var.helm_chart_versions["cluster_autoscaler"]
namespace = "kube-system"
set = concat([{
name = "image.tag"
value = "v${var.cluster_version}.1"
},
{
name = "replicaCount"
value = 0
}],
local.system_component_values)
}
metrics_server_helm_config = {
version = var.helm_chart_versions["metrics_server"]
set = concat([], local.system_component_values)
}
aws_load_balancer_controller_helm_config = {
version = var.helm_chart_versions["aws-load-balancer-controller"]
namespace = "aws-load-balancer-controller"
set = concat([{
name = "replicaCount"
value = 1
},
{
name = "vpcId"
value = module.aws_vpc.vpc_id
}],
local.system_component_values)
}
karpenter_helm_config = {
version = "v${var.helm_chart_versions["karpenter"]}"
timeout = 600
set = concat([{
name = "replicas"
value = "1"
type = "auto"
},
{
name = "aws.defaultInstanceProfile"
value = module.eks_blueprints.managed_node_group_iam_instance_profile_id[0]
},
{
name = "controller.resources.requests.cpu"
value = "300m"
type = "string"
},
{
name = "controller.resources.limits.cpu"
value = "300m"
type = "string"
}],
local.system_component_values)
}
kubecost_helm_config = {
set = concat([
{
name = "blocker"
value = local.ebs_csi_blocker
type = "string"
},
{
name = "prometheus.server.nodeSelector.workshop-system"
value = "yes"
type = "string"
},
{
name = "prometheus.server.tolerations[0].key"
value = "systemComponent"
type = "string"
},
{
name = "prometheus.server.tolerations[0].operator"
value = "Exists"
type = "string"
},
{
name = "prometheus.server.tolerations[0].effect"
value = "NoSchedule"
type = "string"
},
{
name = "prometheus.kube-state-metrics.nodeSelector.workshop-system"
value = "yes"
type = "string"
},
{
name = "prometheus.kube-state-metrics.tolerations[0].key"
value = "systemComponent"
type = "string"
},
{
name = "prometheus.kube-state-metrics.tolerations[0].operator"
value = "Exists"
type = "string"
},
{
name = "prometheus.kube-state-metrics.tolerations[0].effect"
value = "NoSchedule"
type = "string"
},
{
name = "prometheus.nodeExporter.tolerations[0].key"
value = "systemComponent"
type = "string"
},
{
name = "prometheus.nodeExporter.tolerations[0].operator"
value = "Exists"
type = "string"
},
{
name = "prometheus.nodeExporter.tolerations[0].effect"
value = "NoSchedule"
type = "string"
}],
local.system_component_values)
}
aws_for_fluentbit_cw_log_group_name = "/${module.eks_blueprints.eks_cluster_id}/worker-fluentbit-logs-${random_string.fluentbit_log_group.result}"
amazon_eks_adot_config = {
kubernetes_version = var.cluster_version
}
crossplane_helm_config = {
set = concat([{
name = "rbacManager.nodeSelector.workshop-system"
value = "yes"
type = "string"
},
{
name = "rbacManager.tolerations[0].key"
value = "systemComponent"
type = "string"
},
{
name = "rbacManager.tolerations[0].operator"
value = "Exists"
type = "string"
},
{
name = "rbacManager.tolerations[0].effect"
value = "NoSchedule"
type = "string"
}], local.system_component_values)
}
crossplane_aws_provider = {
enable = true
provider_aws_version = "v0.36.0"
additional_irsa_policies = ["arn:aws:iam::aws:policy/AdministratorAccess"]
}
tags = local.tags
}
module "eks_blueprints_ack_addons" {
source = "github.com/aws-ia/terraform-aws-eks-ack-addons?ref=v1.1.0"
depends_on = [
aws_eks_addon.vpc_cni
]
cluster_id = module.eks_blueprints.eks_cluster_id
# Wait for data plane to be ready
data_plane_wait_arn = module.eks_blueprints.managed_node_group_arn[0]
enable_rds = true
rds_helm_config = {
set = [{
name = "deployment.nodeSelector.workshop-system"
value = "yes"
type = "string"
},
{
name = "deployment.tolerations[0].key"
value = "systemComponent"
type = "string"
},
{
name = "deployment.tolerations[0].operator"
value = "Exists"
type = "string"
},
{
name = "deployment.tolerations[0].effect"
value = "NoSchedule"
type = "string"
}]
}
tags = local.tags
}
resource "random_string" "fluentbit_log_group" {
length = 6
special = false
}
locals {
oidc_url = replace(data.aws_eks_cluster.cluster.identity[0].oidc[0].issuer, "https://", "")
addon_context = {
aws_caller_identity_account_id = data.aws_caller_identity.current.account_id
aws_caller_identity_arn = data.aws_caller_identity.current.arn
aws_eks_cluster_endpoint = data.aws_eks_cluster.cluster.endpoint
aws_partition_id = data.aws_partition.current.partition
aws_region_name = data.aws_region.current.id
eks_cluster_id = module.eks_blueprints.eks_cluster_id
eks_oidc_issuer_url = local.oidc_url
eks_oidc_provider_arn = "arn:${data.aws_partition.current.partition}:iam::${local.aws_account_id}:oidc-provider/${local.oidc_url}"
irsa_iam_role_path = "/"
irsa_iam_permissions_boundary = ""
tags = {}
}
system_component_values = [{
name = "nodeSelector.workshop-system"
value = "yes"
type = "string"
},
{
name = "tolerations[0].key"
value = "systemComponent"
type = "string"
},
{
name = "tolerations[0].operator"
value = "Exists"
type = "string"
},
{
name = "tolerations[0].effect"
value = "NoSchedule"
type = "string"
}]
}
module "eks_blueprints_kubernetes_grafana_addon" {
source = "github.com/aws-ia/terraform-aws-eks-blueprints?ref=v4.16.0//modules/kubernetes-addons/grafana"
depends_on = [
module.eks_blueprints_kubernetes_addons
]
addon_context = local.addon_context
irsa_policies = [
aws_iam_policy.grafana.arn
]
helm_config = {
values = [templatefile("${path.module}/templates/grafana.yaml", { prometheus_endpoint = aws_prometheus_workspace.this.prometheus_endpoint, region = data.aws_region.current.name })]
}
}
resource "aws_iam_policy" "grafana" {
name = "${var.environment_name}-grafana-other"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"aps:*",
]
Effect = "Allow"
Resource = "*"
},
]
})
}
module "descheduler" {
source = "../addons/descheduler"
addon_context = local.addon_context
helm_config = {
set = concat([{
name = "blocker"
value = local.ebs_csi_blocker
type = "string"
}], local.system_component_values)
}
}