This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathbitnami.libsonnet
189 lines (171 loc) · 5.66 KB
/
bitnami.libsonnet
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
// Generic stuff is in kube.libsonnet - this file contains
// bitnami-specific conventions.
local kube = import "kube.libsonnet";
local perCloudSvcAnnotations(cloud, internal, service) = (
{
aws: {
"service.beta.kubernetes.io/aws-load-balancer-connection-draining-enabled": "true",
"service.beta.kubernetes.io/aws-load-balancer-connection-draining-timeout": std.toString(service.target_pod.spec.terminationGracePeriodSeconds),
// Use PROXY protocol (nginx supports this too)
"service.beta.kubernetes.io/aws-load-balancer-proxy-protocol": "*",
// Does LB do NAT or DSR? (OnlyLocal implies DSR)
// https://kubernetes.io/docs/tutorials/services/source-ip/
// NB: Don't enable this without modifying set-real-ip-from above!
// Not supported on aws in k8s 1.5 - immediate close / serves 503s.
//"service.beta.kubernetes.io/external-traffic": "OnlyLocal",
},
gke: {},
}[cloud] + if internal then {
aws: {
"service.beta.kubernetes.io/aws-load-balancer-internal": "0.0.0.0/0",
},
gke: {
"cloud.google.com/load-balancer-type": "internal",
},
}[cloud] else {}
);
local perCloudSvcSpec(cloud) = (
{
aws: {},
// Required to get real src IP address, which also allows proper
// ingress.kubernetes.io/whitelist-source-range matching
gke: { externalTrafficPolicy: "Local" },
}[cloud]
);
{
ElbService(name, cloud, internal): kube.Service(name) {
local service = self,
metadata+: {
annotations+: perCloudSvcAnnotations(cloud, internal, service),
},
spec+: { type: "LoadBalancer" } + perCloudSvcSpec(cloud),
},
Ingress(name, class=null): kube.Ingress(name) {
local ing = self,
host:: error "host required",
target_svc:: error "target_svc required",
// Default to single-service - override if you want something else.
paths:: [
{
path: "/",
backend: ing.target_svc.name_port,
pathType: "ImplementationSpecific",
},
],
secretName:: "%s-cert" % [ing.metadata.name],
// cert_provider can either be:
// - "cm-dns": cert-manager using route53 for ACME dns-01 challenge (default)
// - "cm-http": cert-manager using ACME http, requires public ingress
cert_provider:: $.CertManager.default_ingress_provider,
metadata+: $.CertManager.IngressMeta[ing.cert_provider] {
annotations+: {
// Add ingress class iff specified
[if class != null then "kubernetes.io/ingress.class" else null]: class,
},
},
spec+: {
tls: [
{
hosts: std.set([r.host for r in ing.spec.rules]),
secretName: ing.secretName,
},
],
rules: [
{
host: ing.host,
http: {
paths: ing.paths,
},
},
],
},
},
PromScrape(port): {
local scrape = self,
prom_path:: "/metrics",
metadata+: {
annotations+: {
"prometheus.io/scrape": "true",
"prometheus.io/port": std.toString(port),
"prometheus.io/path": scrape.prom_path,
},
},
},
PodZoneAntiAffinityAnnotation(pod): {
podAntiAffinity: {
preferredDuringSchedulingIgnoredDuringExecution: [
{
weight: 50,
podAffinityTerm: {
labelSelector: { matchLabels: pod.metadata.labels },
topologyKey: "failure-domain.beta.kubernetes.io/zone",
},
},
{
weight: 100,
podAffinityTerm: {
labelSelector: { matchLabels: pod.metadata.labels },
topologyKey: "kubernetes.io/hostname",
},
},
],
},
},
CertManager:: {
// Deployed cluster issuers' names:
cluster_issuers:: {
acme_dns:: "letsencrypt-prod-dns",
acme_http:: "letsencrypt-prod-http",
in_cluster:: "in-cluster-issuer",
},
default_ingress_provider:: "cm-dns",
IngressMeta:: {
"cm-dns":: {
annotations+: {
"cert-manager.io/cluster-issuer": $.CertManager.cluster_issuers.acme_dns,
},
},
"cm-http":: {
annotations+: {
"cert-manager.io/cluster-issuer": $.CertManager.cluster_issuers.acme_http,
},
},
},
// CertManager ClusterIssuer object
ClusterIssuer(name):: kube._Object("cert-manager.io/v1alpha2", "ClusterIssuer", name),
// CertManager Certificate object
Certificate(name):: kube._Object("cert-manager.io/v1alpha2", "Certificate", name) {
assert std.objectHas(self.metadata, "namespace") : "Certificate('%s') must set metadata.namespace" % self.metadata.name,
},
InCluster:: {
// Broadest usage is ["any"], limit to mTLS usage:
default_usages:: ["digital signature", "key encipherment"],
// Ref to our in-cluster ClusterIssuer
cluster_issuer:: $.CertManager.ClusterIssuer($.CertManager.cluster_issuers.in_cluster) {
spec+: {
selfSigned: {},
},
},
// Use as:
// my_cert: kube.CertManager.InCluster.Certificate("my-tls-cert", "my-namespace")
// to get a Kubernetes TLS secret named "my-tls-cert" in "my-namespace"
Certificate(name, namespace):: $.CertManager.Certificate(name) {
metadata+: { namespace: namespace },
spec+: {
secretName: name,
issuerRef: kube.CrossVersionObjectReference($.CertManager.InCluster.cluster_issuer) {
// issuerRef doesn't have the apiVersion field
apiVersion:: null,
},
commonName: name,
dnsNames: [
name,
"%s.%s" % [name, namespace],
"%s.%s.svc" % [name, namespace],
],
usages: $.CertManager.InCluster.default_usages,
},
},
},
},
}