forked from particuleio/terraform-kubernetes-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkerd2.tf
319 lines (282 loc) · 9.45 KB
/
linkerd2.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
locals {
linkerd2 = merge(
local.helm_defaults,
{
name = local.helm_dependencies[index(local.helm_dependencies.*.name, "linkerd2")].name
chart = local.helm_dependencies[index(local.helm_dependencies.*.name, "linkerd2")].name
repository = local.helm_dependencies[index(local.helm_dependencies.*.name, "linkerd2")].repository
chart_version = local.helm_dependencies[index(local.helm_dependencies.*.name, "linkerd2")].version
namespace = "linkerd"
create_ns = true
enabled = false
trust_anchor_pem = null
cluster_dns_domain = "cluster.local"
ha = true
},
var.linkerd2
)
values_linkerd2 = <<-VALUES
installNamespace: false
namespace: ${local.linkerd2.namespace}
cniEnabled: true
enableEndpointSlices: true
identity:
issuer:
scheme: kubernetes.io/tls
identityTrustAnchorsPEM: |
${indent(2, local.linkerd2.enabled ? local.linkerd2["trust_anchor_pem"] == null ? tls_self_signed_cert.linkerd_trust_anchor.0.cert_pem : local.linkerd2["trust_anchor_pem"] : "")}
proxyInjector:
externalSecret: true
caBundle: |
${indent(4, local.linkerd2.enabled ? tls_self_signed_cert.webhook_issuer_tls.0.cert_pem : "")}
profileValidator:
externalSecret: true
caBundle: |
${indent(4, local.linkerd2.enabled ? tls_self_signed_cert.webhook_issuer_tls.0.cert_pem : "")}
VALUES
values_linkerd2_ha = <<-VALUES
#
# The below is taken from: https://github.com/linkerd/linkerd2/blob/main/charts/linkerd2/values-ha.yaml
#
enablePodAntiAffinity: true
# proxy configuration
proxy:
# A better default for log collectors that require structured data
logFormat: json
resources:
cpu:
request: 100m
memory:
limit: 250Mi
request: 20Mi
# controller configuration
controllerReplicas: 3
controllerResources: &controller_resources
cpu: &controller_resources_cpu
limit: ""
request: 100m
memory:
limit: 250Mi
request: 50Mi
destinationResources: *controller_resources
# identity configuration
identityResources:
cpu: *controller_resources_cpu
memory:
limit: 250Mi
request: 10Mi
# heartbeat configuration
heartbeatResources: *controller_resources
# proxy injector configuration
proxyInjectorResources: *controller_resources
webhookFailurePolicy: Fail
# service profile validator configuration
spValidatorResources: *controller_resources
VALUES
linkerd2_manifests = {
linkerd-identity-issuer = <<-VALUES
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: linkerd-identity-issuer
namespace: ${local.linkerd2.namespace}
spec:
secretName: linkerd-identity-issuer
revisionHistoryLimit: 3
duration: 8h
renewBefore: 4h
issuerRef:
name: linkerd-trust-anchor
kind: Issuer
commonName: identity.linkerd.cluster.local
dnsNames:
- identity.linkerd.cluster.local
isCA: true
privateKey:
algorithm: ECDSA
usages:
- cert sign
- crl sign
- server auth
- client auth
VALUES
linkerd-proxy-injector = <<-VALUES
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: linkerd-proxy-injector
namespace: ${local.linkerd2.namespace}
spec:
secretName: linkerd-proxy-injector-k8s-tls
revisionHistoryLimit: 3
duration: 8h
renewBefore: 4h
issuerRef:
name: webhook-issuer
kind: Issuer
commonName: linkerd-proxy-injector.${local.linkerd2.namespace}.svc
dnsNames:
- linkerd-proxy-injector.${local.linkerd2.namespace}.svc
isCA: false
privateKey:
algorithm: ECDSA
usages:
- server auth
VALUES
linkerd-sp-validator = <<-VALUES
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: linkerd-sp-validator
namespace: ${local.linkerd2.namespace}
spec:
secretName: linkerd-sp-validator-k8s-tls
revisionHistoryLimit: 3
duration: 8h
renewBefore: 4h
issuerRef:
name: webhook-issuer
kind: Issuer
commonName: linkerd-sp-validator.${local.linkerd2.namespace}.svc
dnsNames:
- linkerd-sp-validator.${local.linkerd2.namespace}.svc
isCA: false
privateKey:
algorithm: ECDSA
usages:
- server auth
VALUES
linkerd-trust-anchor = <<-VALUES
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: linkerd-trust-anchor
namespace: ${local.linkerd2.namespace}
spec:
ca:
secretName: linkerd-trust-anchor
VALUES
webhook-issuer = <<-VALUES
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: webhook-issuer
namespace: ${local.linkerd2.namespace}
spec:
ca:
secretName: webhook-issuer-tls
VALUES
}
}
resource "tls_private_key" "linkerd_trust_anchor" {
count = local.linkerd2["enabled"] && local.linkerd2["trust_anchor_pem"] == null ? 1 : 0
algorithm = "ECDSA"
ecdsa_curve = "P256"
}
resource "tls_self_signed_cert" "linkerd_trust_anchor" {
count = local.linkerd2["enabled"] && local.linkerd2["trust_anchor_pem"] == null ? 1 : 0
private_key_pem = tls_private_key.linkerd_trust_anchor.0.private_key_pem
validity_period_hours = 87600
early_renewal_hours = 78840
is_ca_certificate = true
subject {
common_name = "root.linkerd.cluster.local"
}
allowed_uses = [
"cert_signing",
"crl_signing",
]
}
resource "kubernetes_secret" "linkerd_trust_anchor" {
count = local.linkerd2["enabled"] && local.linkerd2["trust_anchor_pem"] == null ? 1 : 0
metadata {
name = "linkerd-trust-anchor"
namespace = local.linkerd2.create_ns ? kubernetes_namespace.linkerd2.0.metadata[0].name : local.linkerd2.namespace
}
data = {
"tls.crt" = tls_self_signed_cert.linkerd_trust_anchor.0.cert_pem
"tls.key" = tls_private_key.linkerd_trust_anchor.0.private_key_pem
}
type = "kubernetes.io/tls"
}
resource "tls_private_key" "webhook_issuer_tls" {
count = local.linkerd2["enabled"] ? 1 : 0
algorithm = "ECDSA"
ecdsa_curve = "P256"
}
resource "tls_self_signed_cert" "webhook_issuer_tls" {
count = local.linkerd2["enabled"] ? 1 : 0
private_key_pem = tls_private_key.webhook_issuer_tls.0.private_key_pem
validity_period_hours = 87600
early_renewal_hours = 78840
is_ca_certificate = true
subject {
common_name = "webhook.linkerd.cluster.local"
}
allowed_uses = [
"cert_signing",
"crl_signing",
]
}
resource "kubernetes_secret" "webhook_issuer_tls" {
count = local.linkerd2["enabled"] ? 1 : 0
metadata {
name = "webhook-issuer-tls"
namespace = local.linkerd2.create_ns ? kubernetes_namespace.linkerd2.0.metadata[0].name : local.linkerd2.namespace
}
data = {
"tls.crt" = tls_self_signed_cert.webhook_issuer_tls.0.cert_pem
"tls.key" = tls_private_key.webhook_issuer_tls.0.private_key_pem
}
type = "kubernetes.io/tls"
}
resource "kubernetes_namespace" "linkerd2" {
count = local.linkerd2["enabled"] && local.linkerd2["create_ns"] ? 1 : 0
metadata {
labels = {
name = local.linkerd2["namespace"]
"linkerd.io/is-control-plane" = "true"
"config.linkerd.io/admission-webhook" = "disabled"
"linkerd.io/control-plane-ns" = local.linkerd2.namespace
}
annotations = {
"linkerd.io/inject" = "disabled"
}
name = local.linkerd2["namespace"]
}
}
resource "helm_release" "linkerd2" {
count = local.linkerd2["enabled"] ? 1 : 0
repository = local.linkerd2["repository"]
name = local.linkerd2["name"]
chart = local.linkerd2["chart"]
version = local.linkerd2["chart_version"]
timeout = local.linkerd2["timeout"]
force_update = local.linkerd2["force_update"]
recreate_pods = local.linkerd2["recreate_pods"]
wait = local.linkerd2["wait"]
atomic = local.linkerd2["atomic"]
cleanup_on_fail = local.linkerd2["cleanup_on_fail"]
dependency_update = local.linkerd2["dependency_update"]
disable_crd_hooks = local.linkerd2["disable_crd_hooks"]
disable_webhooks = local.linkerd2["disable_webhooks"]
render_subchart_notes = local.linkerd2["render_subchart_notes"]
replace = local.linkerd2["replace"]
reset_values = local.linkerd2["reset_values"]
reuse_values = local.linkerd2["reuse_values"]
skip_crds = local.linkerd2["skip_crds"]
verify = local.linkerd2["verify"]
values = compact([
local.values_linkerd2,
local.linkerd2["extra_values"],
local.linkerd2.ha ? local.values_linkerd2_ha : null
])
namespace = local.linkerd2["create_ns"] ? kubernetes_namespace.linkerd2.*.metadata.0.name[count.index] : local.linkerd2["namespace"]
depends_on = [
helm_release.linkerd2-cni
]
}
resource "kubectl_manifest" "linkerd" {
for_each = local.linkerd2.enabled ? local.linkerd2_manifests : {}
yaml_body = each.value
}