2019-08-08 22:09:53 +02:00
|
|
|
local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
2019-09-27 00:02:33 +02:00
|
|
|
local utils = import 'utils.libsonnet';
|
2020-03-18 15:13:47 +01:00
|
|
|
local vars = import 'vars.jsonnet';
|
2019-04-08 21:41:23 +02:00
|
|
|
|
2019-02-27 13:28:00 +01:00
|
|
|
{
|
2019-03-13 22:44:01 +01:00
|
|
|
_config+:: {
|
|
|
|
namespace: 'monitoring',
|
2019-02-27 13:28:00 +01:00
|
|
|
|
|
|
|
urls+:: {
|
2019-04-08 21:41:23 +02:00
|
|
|
prom_ingress: 'prometheus.' + vars.suffixDomain,
|
|
|
|
alert_ingress: 'alertmanager.' + vars.suffixDomain,
|
|
|
|
grafana_ingress: 'grafana.' + vars.suffixDomain,
|
|
|
|
grafana_ingress_external: 'grafana.' + vars.suffixDomain,
|
2019-02-27 13:28:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
prometheus+:: {
|
|
|
|
names: 'k8s',
|
|
|
|
replicas: 1,
|
2019-03-25 22:01:00 +01:00
|
|
|
namespaces: ['default', 'kube-system', 'monitoring'],
|
2019-02-27 13:28:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
alertmanager+:: {
|
|
|
|
replicas: 1,
|
|
|
|
},
|
|
|
|
|
|
|
|
kubeStateMetrics+:: {
|
|
|
|
collectors: '', // empty string gets a default set
|
|
|
|
scrapeInterval: '30s',
|
|
|
|
scrapeTimeout: '30s',
|
|
|
|
|
|
|
|
baseCPU: '100m',
|
|
|
|
baseMemory: '150Mi',
|
|
|
|
cpuPerNode: '2m',
|
|
|
|
memoryPerNode: '30Mi',
|
|
|
|
},
|
|
|
|
|
2019-03-13 22:44:01 +01:00
|
|
|
// 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'),
|
|
|
|
},
|
2019-02-27 13:28:00 +01:00
|
|
|
|
2019-03-13 22:44:01 +01:00
|
|
|
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: '',
|
2019-04-08 21:41:23 +02:00
|
|
|
from_address: vars.grafana.from_address,
|
2019-03-13 22:44:01 +01:00
|
|
|
from_name: 'Grafana Alert',
|
|
|
|
skip_verify: true,
|
2019-02-27 13:28:00 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-03-13 22:44:01 +01:00
|
|
|
},
|
|
|
|
//---------------------------------------
|
|
|
|
// End of _config
|
|
|
|
//---------------------------------------
|
2019-02-27 13:28:00 +01:00
|
|
|
|
2019-03-13 22:44:01 +01:00
|
|
|
prometheus+:: {
|
2020-03-18 15:13:47 +01:00
|
|
|
// Add option (from vars.yaml) to enable persistence
|
2019-03-13 22:44:01 +01:00
|
|
|
local pvc = k.core.v1.persistentVolumeClaim,
|
|
|
|
prometheus+: {
|
|
|
|
spec+: {
|
2019-10-09 22:33:29 +02:00
|
|
|
replicas: $._config.prometheus.replicas,
|
2019-05-09 03:22:07 +02:00
|
|
|
retention: '15d',
|
|
|
|
externalUrl: 'http://' + $._config.urls.prom_ingress,
|
|
|
|
}
|
|
|
|
+ (if vars.enablePersistence.prometheus then {
|
|
|
|
storage: {
|
|
|
|
volumeClaimTemplate:
|
|
|
|
pvc.new() +
|
|
|
|
pvc.mixin.spec.withAccessModes('ReadWriteOnce') +
|
|
|
|
pvc.mixin.spec.resources.withRequests({ storage: '20Gi' }),
|
|
|
|
// Uncomment below to define a StorageClass name
|
|
|
|
//+ pvc.mixin.spec.withStorageClassName('nfs-master-ssd'),
|
|
|
|
},
|
|
|
|
} else {}),
|
2019-02-27 13:28:00 +01:00
|
|
|
},
|
2019-03-13 22:44:01 +01:00
|
|
|
},
|
2019-02-27 13:28:00 +01:00
|
|
|
|
2019-03-13 22:44:01 +01:00
|
|
|
// Override deployment for Grafana data persistence
|
2019-05-09 03:22:07 +02:00
|
|
|
grafana+:: if vars.enablePersistence.grafana then {
|
2019-03-13 22:44:01 +01:00
|
|
|
deployment+: {
|
|
|
|
spec+: {
|
|
|
|
template+: {
|
|
|
|
spec+: {
|
2019-02-27 13:28:00 +01:00
|
|
|
volumes:
|
|
|
|
std.map(
|
|
|
|
function(v)
|
|
|
|
if v.name == 'grafana-storage' then
|
2019-03-13 22:44:01 +01:00
|
|
|
{
|
|
|
|
name: 'grafana-storage',
|
|
|
|
persistentVolumeClaim: {
|
|
|
|
claimName: 'grafana-storage',
|
|
|
|
},
|
2019-02-27 13:28:00 +01:00
|
|
|
}
|
|
|
|
else v,
|
|
|
|
super.volumes
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-03-13 22:44:01 +01:00
|
|
|
storage:
|
|
|
|
local pvc = k.core.v1.persistentVolumeClaim;
|
|
|
|
pvc.new() +
|
|
|
|
pvc.mixin.metadata.withNamespace($._config.namespace) +
|
|
|
|
pvc.mixin.metadata.withName('grafana-storage') +
|
2019-11-17 17:43:40 +01:00
|
|
|
pvc.mixin.spec.withAccessModes('ReadWriteOnce') +
|
2019-03-13 22:44:01 +01:00
|
|
|
pvc.mixin.spec.resources.withRequests({ storage: '2Gi' }),
|
2019-04-08 21:41:23 +02:00
|
|
|
} else {},
|
2019-02-27 13:28:00 +01:00
|
|
|
|
2019-03-13 22:44:01 +01:00
|
|
|
grafanaDashboards+:: $._config.grafanaDashboards,
|
2019-02-27 13:28:00 +01:00
|
|
|
|
|
|
|
// Create ingress objects per application
|
2019-09-27 00:02:33 +02:00
|
|
|
ingress+:: {
|
|
|
|
alertmanager:
|
2020-03-02 20:46:38 +01:00
|
|
|
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, 'ingress-TLS-secret')
|
|
|
|
else
|
|
|
|
utils.addIngressTLS(I)
|
|
|
|
else
|
|
|
|
I,
|
2019-02-27 13:28:00 +01:00
|
|
|
|
2019-03-13 22:44:01 +01:00
|
|
|
grafana:
|
2020-03-02 20:46:38 +01:00
|
|
|
local I = utils.newIngress('grafana', $._config.namespace, $._config.urls.grafana_ingress, '/', 'grafana', 'http');
|
|
|
|
if vars.TLSingress then
|
|
|
|
if vars.UseProvidedCerts then
|
|
|
|
utils.addIngressTLS(I, 'ingress-TLS-secret')
|
|
|
|
else
|
|
|
|
utils.addIngressTLS(I)
|
|
|
|
else
|
|
|
|
I,
|
2019-09-27 00:02:33 +02:00
|
|
|
|
|
|
|
prometheus:
|
2020-03-02 20:46:38 +01:00
|
|
|
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, 'ingress-TLS-secret')
|
|
|
|
else
|
|
|
|
utils.addIngressTLS(I)
|
|
|
|
else
|
|
|
|
I,
|
2019-09-27 00:02:33 +02:00
|
|
|
|
2019-03-13 22:44:01 +01:00
|
|
|
// // 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),
|
2020-03-02 20:46:38 +01:00
|
|
|
} + if vars.UseProvidedCerts then {
|
2020-03-18 15:13:47 +01:00
|
|
|
secret:
|
|
|
|
utils.newTLSSecret('ingress-TLS-secret', $._config.namespace, vars.TLSCertificate, vars.TLSKey),
|
|
|
|
} else {},
|
2019-03-13 22:44:01 +01:00
|
|
|
}
|