-
-
Notifications
You must be signed in to change notification settings - Fork 201
/
base_operator_stack.jsonnet
197 lines (181 loc) · 7.29 KB
/
base_operator_stack.jsonnet
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
local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
local utils = import 'utils.libsonnet';
local vars = import 'vars.jsonnet';
{
_config+:: {
namespace: vars._config.namespace,
urls+:: {
domains: [vars.suffixDomain] + vars.additionalDomains,
prom_ingress: ['prometheus.' + domain for domain in $._config.urls.domains],
alert_ingress: ['alertmanager.' + domain for domain in $._config.urls.domains],
grafana_ingress: ['grafana.' + domain for domain in $._config.urls.domains],
grafana_ingress_external: 'grafana.' + vars.suffixDomain,
},
prometheus+:: {
names: 'k8s',
replicas: 1,
namespaces: ['default', 'kube-system', 'monitoring'],
},
alertmanager+:: {
replicas: 1,
},
kubeStateMetrics+:: {
collectors: '', // empty string gets a default set
scrapeInterval: '30s',
scrapeTimeout: '30s',
baseCPU: '100m',
baseMemory: '150Mi',
cpuPerNode: '2m',
memoryPerNode: '30Mi',
},
// Add custom Grafana dashboards
grafanaDashboards+:: {
'kubernetes-cluster-dashboard.json': (import 'grafana-dashboards/kubernetes-cluster-dashboard.json'),
'prometheus-dashboard.json': (import 'grafana-dashboards/prometheus-dashboard.json'),
'coredns-dashboard.json': (import 'grafana-dashboards/coredns-dashboard.json'),
},
grafana+:: {
config: {
sections: {
session: { provider: 'memory' },
'auth.basic': { enabled: false },
'auth.anonymous': { enabled: false },
smtp: {
enabled: true,
host: 'smtp-server.monitoring.svc:25',
user: '',
password: '',
from_address: vars.grafana.from_address,
from_name: 'Grafana Alert',
skip_verify: true,
},
},
},
plugins: vars.grafana.plugins,
env: vars.grafana.env
},
},
//---------------------------------------
// End of _config
//---------------------------------------
prometheus+:: {
// Add option (from vars.yaml) to enable persistence
local pvc = k.core.v1.persistentVolumeClaim,
prometheus+: {
spec+: {
// Here one can use parameters from https://coreos.com/operators/prometheus/docs/latest/api.html#prometheusspec
replicas: $._config.prometheus.replicas,
retention: vars.prometheus.retention,
scrapeInterval: vars.prometheus.scrapeInterval,
scrapeTimeout: vars.prometheus.scrapeTimeout,
externalUrl: 'http://' + $._config.urls.prom_ingress[0],
}
+ (if vars.enablePersistence.prometheus then {
storage: {
volumeClaimTemplate:
pvc.new() +
pvc.mixin.spec.withAccessModes('ReadWriteOnce') +
pvc.mixin.spec.resources.withRequests({ storage: vars.enablePersistence.prometheusSizePV }) +
(if vars.enablePersistence.prometheusPV != null then pvc.mixin.spec.withVolumeName(vars.enablePersistence.prometheusPV)) +
(if vars.enablePersistence.storageClass != null then pvc.mixin.spec.withStorageClassName(vars.enablePersistence.storageClass)),
},
} else {}),
},
},
// Override deployment for Grafana data persistence
grafana+:: if vars.enablePersistence.grafana then {
deployment+: {
spec+: {
template+: {
spec+: {
securityContext: {
runAsUser: 472,
fsGroup: 472,
runAsNonRoot: true,
},
volumes:
std.map(
function(v)
if v.name == 'grafana-storage' then
{
name: 'grafana-storage',
persistentVolumeClaim: {
claimName: 'grafana-storage',
},
}
else v,
super.volumes
),
},
},
},
},
storage:
local pvc = k.core.v1.persistentVolumeClaim;
pvc.new() +
pvc.mixin.metadata.withNamespace($._config.namespace) +
pvc.mixin.metadata.withName('grafana-storage') +
pvc.mixin.spec.withAccessModes('ReadWriteOnce') +
pvc.mixin.spec.resources.withRequests({ storage: vars.enablePersistence.grafanaSizePV }) +
(if vars.enablePersistence.grafanaPV != null then pvc.mixin.spec.withVolumeName(vars.enablePersistence.grafanaPV)) +
(if vars.enablePersistence.storageClass != null then pvc.mixin.spec.withStorageClassName(vars.enablePersistence.storageClass)),
} else {},
grafanaDashboards+:: $._config.grafanaDashboards,
// Create ingress objects per application
ingress+:: {
alertmanager:
local I = utils.newIngress('alertmanager-main', $._config.namespace, $._config.urls.alert_ingress, '/', 'alertmanager-main', 'web');
if vars.TLSingress then
if vars.UseProvidedCerts then
utils.addIngressTLS(I, $._config.urls.alert_ingress, 'ingress-secret')
else
utils.addIngressTLS(I, $._config.urls.alert_ingress)
else
I,
grafana:
local I = utils.newIngress('grafana', $._config.namespace, $._config.urls.grafana_ingress, '/', 'grafana', 'http');
if vars.TLSingress then
if vars.UseProvidedCerts then
utils.addIngressTLS(I, $._config.urls.grafana_ingress, 'ingress-secret')
else
utils.addIngressTLS(I, $._config.urls.grafana_ingress)
else
I,
prometheus:
local I = utils.newIngress('prometheus-k8s', $._config.namespace, $._config.urls.prom_ingress, '/', 'prometheus-k8s', 'web');
if vars.TLSingress then
if vars.UseProvidedCerts then
utils.addIngressTLS(I, $._config.urls.prom_ingress, 'ingress-secret')
else
utils.addIngressTLS(I, $._config.urls.prom_ingress)
else
I,
// // Example external ingress with authentication
// 'grafana-external':
// ingress.new() +
// ingress.mixin.metadata.withName('grafana-external') +
// ingress.mixin.metadata.withNamespace($._config.namespace) +
// ingress.mixin.metadata.withLabels({'traffic-type': 'external'}) +
// ingress.mixin.metadata.withAnnotations({
// 'ingress.kubernetes.io/auth-type': 'basic',
// 'ingress.kubernetes.io/auth-secret': 'basic-auth',
// }) +
// ingress.mixin.spec.withRules(
// ingressRule.new() +
// ingressRule.withHost($._config.urls.grafana_ingress_external) +
// ingressRule.mixin.http.withPaths(
// httpIngressPath.new() +
// httpIngressPath.withPath('/') +
// httpIngressPath.mixin.backend.withServiceName('grafana') +
// httpIngressPath.mixin.backend.withServicePort('http')
// ),
// ),
// 'basic-auth-secret':
// // First generate the auth secret with gen_auth.sh script
// secret.new('basic-auth', { auth: std.base64(importstr 'auth') }) +
// secret.mixin.metadata.withNamespace($._config.namespace),
} + if vars.UseProvidedCerts then {
secret:
utils.newTLSSecret('ingress-secret', $._config.namespace, vars.TLSCertificate, vars.TLSKey),
} else {},
}