diff --git a/README.md b/README.md index 5ac40049603bcb2147948660e8c712b128b852ec..c8e62f6130b19db7b5b2b778501c85918d27e00b 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ local kp = // (import 'kube-prometheus/kube-prometheus-managed-cluster.libsonnet') + // (import 'kube-prometheus/kube-prometheus-node-ports.libsonnet') + // (import 'kube-prometheus/kube-prometheus-static-etcd.libsonnet') + - // (import 'kube-prometheus/kube-prometheus-thanos.libsonnet') + + // (import 'kube-prometheus/kube-prometheus-thanos-sidecar.libsonnet') + { _config+:: { namespace: 'monitoring', diff --git a/docs/developing-prometheus-rules-and-grafana-dashboards.md b/docs/developing-prometheus-rules-and-grafana-dashboards.md index 92ef040b07393adeb0b2c71316bd6372e402a98e..824c3b4a13d6f656d6593a9b191fbdac36dc5eea 100644 --- a/docs/developing-prometheus-rules-and-grafana-dashboards.md +++ b/docs/developing-prometheus-rules-and-grafana-dashboards.md @@ -17,7 +17,7 @@ local kp = // (import 'kube-prometheus/kube-prometheus-managed-cluster.libsonnet') + // (import 'kube-prometheus/kube-prometheus-node-ports.libsonnet') + // (import 'kube-prometheus/kube-prometheus-static-etcd.libsonnet') + - // (import 'kube-prometheus/kube-prometheus-thanos.libsonnet') + + // (import 'kube-prometheus/kube-prometheus-thanos-sidecar.libsonnet') + { _config+:: { namespace: 'monitoring', diff --git a/example.jsonnet b/example.jsonnet index e50e3395f442771c65c4c2db27e81a3517a006a3..7002eff26b6619042086f891c02dd85e67e85ee3 100644 --- a/example.jsonnet +++ b/example.jsonnet @@ -5,7 +5,7 @@ local kp = // (import 'kube-prometheus/kube-prometheus-managed-cluster.libsonnet') + // (import 'kube-prometheus/kube-prometheus-node-ports.libsonnet') + // (import 'kube-prometheus/kube-prometheus-static-etcd.libsonnet') + - // (import 'kube-prometheus/kube-prometheus-thanos.libsonnet') + + // (import 'kube-prometheus/kube-prometheus-thanos-sidecar.libsonnet') + { _config+:: { namespace: 'monitoring', diff --git a/jsonnet/kube-prometheus/kube-prometheus-thanos-sidecar.libsonnet b/jsonnet/kube-prometheus/kube-prometheus-thanos-sidecar.libsonnet new file mode 100644 index 0000000000000000000000000000000000000000..79f4aca974301617adf1db4bdce39308dbf315e7 --- /dev/null +++ b/jsonnet/kube-prometheus/kube-prometheus-thanos-sidecar.libsonnet @@ -0,0 +1,39 @@ +local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; +local service = k.core.v1.service; +local servicePort = k.core.v1.service.mixin.spec.portsType; + +{ + _config+:: { + versions+:: { + thanos: 'v0.5.0', + }, + imageRepos+:: { + thanos: 'improbable/thanos', + }, + thanos+:: { + objectStorageConfig: { + key: 'thanos.yaml', // How the file inside the secret is called + name: 'thanos-objectstorage', // This is the name of your Kubernetes secret with the config + }, + }, + }, + prometheus+:: { + // Add the grpc port to the Prometheus service to be able to query it with the Thanos Querier + service+: { + spec+: { + ports+: [ + servicePort.newNamed('grpc', 10901, 10901), + ], + }, + }, + prometheus+: { + spec+: { + thanos+: { + version: $._config.versions.thanos, + baseImage: $._config.imageRepos.thanos, + objectStorageConfig: $._config.thanos.objectStorageConfig, + }, + }, + }, + }, +} diff --git a/jsonnet/kube-prometheus/kube-prometheus-thanos.libsonnet b/jsonnet/kube-prometheus/kube-prometheus-thanos.libsonnet deleted file mode 100644 index 68b5c349282d34a723224ee7d462924c3da7c9c3..0000000000000000000000000000000000000000 --- a/jsonnet/kube-prometheus/kube-prometheus-thanos.libsonnet +++ /dev/null @@ -1,182 +0,0 @@ -local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; -local service = k.core.v1.service; -local servicePort = k.core.v1.service.mixin.spec.portsType; - -{ - _config+:: { - versions+:: { - thanos: 'v0.5.0', - }, - imageRepos+:: { - thanos: 'improbable/thanos', - }, - thanos+:: { - objectStorageConfig: { - key: 'thanos.yaml', // How the file inside the secret is called - name: 'thanos-objstore-config', // This is the name of your Kubernetes secret with the config - }, - }, - }, - prometheus+:: { - prometheus+: { - spec+: { - thanos+: { - version: $._config.versions.thanos, - baseImage: $._config.imageRepos.thanos, - objectStorageConfig: $._config.thanos.objectStorageConfig, - }, - }, - }, - thanosQueryDeployment: - local deployment = k.apps.v1.deployment; - local container = k.apps.v1.deployment.mixin.spec.template.spec.containersType; - local containerPort = container.portsType; - - local thanosQueryContainer = - container.new('thanos-query', $._config.imageRepos.thanos + ':' + $._config.versions.thanos) + - container.withPorts([ - containerPort.newNamed(10902, 'http'), - containerPort.newNamed(10901, 'grpc'), - ]) + - container.withArgs([ - 'query', - '--log.level=debug', - '--query.replica-label=prometheus_replica', - '--query.auto-downsampling', - '--store=dnssrv+thanos-sidecar.' + $._config.namespace + '.svc', - ]); - local podLabels = { app: 'thanos-query' }; - deployment.new('thanos-query', 1, thanosQueryContainer, podLabels) + - deployment.mixin.metadata.withNamespace($._config.namespace) + - deployment.mixin.metadata.withLabels(podLabels) + - deployment.mixin.spec.selector.withMatchLabels(podLabels) + - deployment.mixin.spec.template.spec.withServiceAccountName('prometheus-' + $._config.prometheus.name), - thanosQueryService: - local thanosQueryPort = servicePort.newNamed('http', 9090, 'http'); - service.new('thanos-query', { app: 'thanos-query' }, thanosQueryPort) + - service.mixin.metadata.withNamespace($._config.namespace) + - service.mixin.metadata.withLabels({ app: 'thanos-query' }), - thanosSidecarService: - local thanosSidecarPort = servicePort.newNamed('grpc', 10901, 'grpc'); - service.new('thanos-sidecar', { app: 'thanos-sidecar' }, thanosSidecarPort) + - service.mixin.metadata.withNamespace($._config.namespace) + - service.mixin.metadata.withLabels({ app: 'thanos-sidecar' }) + - service.mixin.spec.withSelector({ prometheus: 'k8s' }), - - thanosStoreStatefulset: - local statefulSet = k.apps.v1.statefulSet; - local volume = statefulSet.mixin.spec.template.spec.volumesType; - local container = statefulSet.mixin.spec.template.spec.containersType; - local containerEnv = container.envType; - local containerVolumeMount = container.volumeMountsType; - - local labels = { app: 'thanos' }; - - local c = - container.new('thanos-store', $._config.imageRepos.thanos + ':' + $._config.versions.thanos) + - container.withArgs([ - 'store', - '--log.level=debug', - '--data-dir=/var/thanos/store', - '--objstore.config=$(OBJSTORE_CONFIG)', - ]) + - container.withEnv([ - containerEnv.fromSecretRef( - 'OBJSTORE_CONFIG', - $._config.thanos.objectStorageConfig.name, - $._config.thanos.objectStorageConfig.key, - ), - ]) + - container.withPorts([ - { name: 'grpc', containerPort: 10901 }, - { name: 'http', containerPort: 10902 }, - ]) + - container.withVolumeMounts([ - containerVolumeMount.new('data', '/var/thanos/store', false), - ]); - - statefulSet.new('thanos-store', 1, c, [], labels) + - statefulSet.mixin.metadata.withNamespace($._config.namespace) + - statefulSet.mixin.spec.selector.withMatchLabels(labels) + - statefulSet.mixin.spec.withServiceName('thanos-store') + - statefulSet.mixin.spec.template.spec.withVolumes([ - volume.fromEmptyDir('data'), - ]), - - serviceMonitorThanosCompactor: - { - apiVersion: 'monitoring.coreos.com/v1', - kind: 'ServiceMonitor', - metadata: { - name: 'thanos-compactor', - namespace: $._config.namespace, - labels: { - 'k8s-app': 'thanos-compactor', - }, - }, - spec: { - jobLabel: 'k8s-app', - endpoints: [ - { - port: 'http', - interval: '30s', - }, - ], - selector: { - matchLabels: { - app: 'thanos-compactor', - }, - }, - }, - }, - - thanosCompactorService: - service.new( - 'thanos-compactor', - { app: 'thanos-compactor' }, - servicePort.newNamed('http', 9090, 'http'), - ) + - service.mixin.metadata.withNamespace($._config.namespace) + - service.mixin.metadata.withLabels({ app: 'thanos-compactor' }), - - thanosCompactorStatefulset: - local statefulSet = k.apps.v1.statefulSet; - local volume = statefulSet.mixin.spec.template.spec.volumesType; - local container = statefulSet.mixin.spec.template.spec.containersType; - local containerEnv = container.envType; - local containerVolumeMount = container.volumeMountsType; - - local labels = { app: 'thanos-compactor' }; - - local c = - container.new('thanos-compactor', $._config.imageRepos.thanos + ':' + $._config.versions.thanos) + - container.withArgs([ - 'compact', - '--log.level=debug', - '--data-dir=/var/thanos/store', - '--objstore.config=$(OBJSTORE_CONFIG)', - '--wait', - ]) + - container.withEnv([ - containerEnv.fromSecretRef( - 'OBJSTORE_CONFIG', - $._config.thanos.objectStorageConfig.name, - $._config.thanos.objectStorageConfig.key, - ), - ]) + - container.withPorts([ - { name: 'http', containerPort: 10902 }, - ]) + - container.withVolumeMounts([ - containerVolumeMount.new('data', '/var/thanos/store', false), - ]); - - statefulSet.new('thanos-compactor', 1, c, [], labels) + - statefulSet.mixin.metadata.withNamespace($._config.namespace) + - statefulSet.mixin.spec.selector.withMatchLabels(labels) + - statefulSet.mixin.spec.withServiceName('thanos-compactor') + - statefulSet.mixin.spec.template.spec.withVolumes([ - volume.fromEmptyDir('data'), - ]), - }, -}