improving servicemonitor definition section
This commit is contained in:
84
README.md
84
README.md
@@ -20,30 +20,42 @@ This stack is meant for cluster monitoring, so it is pre-configured to collect m
|
|||||||
|
|
||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
* [Prerequisites](#prerequisites)
|
- [kube-prometheus](#kube-prometheus)
|
||||||
* [minikube](#minikube)
|
- [Table of contents](#table-of-contents)
|
||||||
* [Quickstart](#quickstart)
|
- [Prerequisites](#prerequisites)
|
||||||
* [Customizing Kube-Prometheus](#customizing-kube-prometheus)
|
- [minikube](#minikube)
|
||||||
* [Installing](#installing)
|
- [Quickstart](#quickstart)
|
||||||
* [Compiling](#compiling)
|
- [Access the dashboards](#access-the-dashboards)
|
||||||
* [Containerized Installing and Compiling](#containerized-installing-and-compiling)
|
- [Customizing Kube-Prometheus](#customizing-kube-prometheus)
|
||||||
* [Configuration](#configuration)
|
- [Installing](#installing)
|
||||||
* [Customization Examples](#customization-examples)
|
- [Compiling](#compiling)
|
||||||
* [Cluster Creation Tools](#cluster-creation-tools)
|
- [Apply the kube-prometheus stack](#apply-the-kube-prometheus-stack)
|
||||||
* [Internal Registries](#internal-registries)
|
- [Containerized Installing and Compiling](#containerized-installing-and-compiling)
|
||||||
* [NodePorts](#nodeports)
|
- [Update from upstream project](#update-from-upstream-project)
|
||||||
* [Prometheus Object Name](#prometheus-object-name)
|
- [Update jb](#update-jb)
|
||||||
* [node-exporter DaemonSet namespace](#node-exporter-daemonset-namespace)
|
- [Update kube-prometheus](#update-kube-prometheus)
|
||||||
* [Alertmanager configuration](#alertmanager-configuration)
|
- [Compile the manifests and apply](#compile-the-manifests-and-apply)
|
||||||
* [Static etcd configuration](#static-etcd-configuration)
|
- [Configuration](#configuration)
|
||||||
* [Pod Anti-Affinity](#pod-anti-affinity)
|
- [Customization Examples](#customization-examples)
|
||||||
* [Customizing Prometheus alerting/recording rules and Grafana dashboards](#customizing-prometheus-alertingrecording-rules-and-grafana-dashboards)
|
- [Cluster Creation Tools](#cluster-creation-tools)
|
||||||
* [Exposing Prometheus/Alermanager/Grafana via Ingress](#exposing-prometheusalermanagergrafana-via-ingress)
|
- [Internal Registry](#internal-registry)
|
||||||
* [Minikube Example](#minikube-example)
|
- [NodePorts](#nodeports)
|
||||||
* [Troubleshooting](#troubleshooting)
|
- [Prometheus Object Name](#prometheus-object-name)
|
||||||
* [Error retrieving kubelet metrics](#error-retrieving-kubelet-metrics)
|
- [node-exporter DaemonSet namespace](#node-exporter-daemonset-namespace)
|
||||||
* [kube-state-metrics resource usage](#kube-state-metrics-resource-usage)
|
- [Alertmanager configuration](#alertmanager-configuration)
|
||||||
* [Contributing](#contributing)
|
- [Adding additional namespaces to monitor](#adding-additional-namespaces-to-monitor)
|
||||||
|
- [Defining the ServiceMonitor for each addional Namespace](#defining-the-servicemonitor-for-each-addional-namespace)
|
||||||
|
- [Static etcd configuration](#static-etcd-configuration)
|
||||||
|
- [Pod Anti-Affinity](#pod-anti-affinity)
|
||||||
|
- [Customizing Prometheus alerting/recording rules and Grafana dashboards](#customizing-prometheus-alertingrecording-rules-and-grafana-dashboards)
|
||||||
|
- [Exposing Prometheus/Alermanager/Grafana via Ingress](#exposing-prometheusalermanagergrafana-via-ingress)
|
||||||
|
- [Minikube Example](#minikube-example)
|
||||||
|
- [Troubleshooting](#troubleshooting)
|
||||||
|
- [Error retrieving kubelet metrics](#error-retrieving-kubelet-metrics)
|
||||||
|
- [Authentication problem](#authentication-problem)
|
||||||
|
- [Authorization problem](#authorization-problem)
|
||||||
|
- [kube-state-metrics resource usage](#kube-state-metrics-resource-usage)
|
||||||
|
- [Contributing](#contributing)
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
@@ -545,19 +557,23 @@ local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + {
|
|||||||
|
|
||||||
#### Defining the ServiceMonitor for each addional Namespace
|
#### Defining the ServiceMonitor for each addional Namespace
|
||||||
|
|
||||||
In order to Prometheus be able to discovery and scrap services inside the additional namespaces specified in previous step you need to define a ServiceMonitor resource.
|
In order to Prometheus be able to discovery and scrape services inside the additional namespaces specified in previous step you need to define a ServiceMonitor resource.
|
||||||
|
|
||||||
|
> Typically it is up to the users of a namespace to provision the ServiceMonitor resource, but in case you want to generate it with the same tooling as the rest of the cluster monitoring infrastructure, this is a guide on how to achieve this.
|
||||||
|
|
||||||
You can define ServiceMonitor resources in your `jsonnet` spec. See the snippet bellow:
|
You can define ServiceMonitor resources in your `jsonnet` spec. See the snippet bellow:
|
||||||
|
|
||||||
```
|
[embedmd]:# (examples/additional-namespaces-servicemonitor.jsonnet)
|
||||||
|
```jsonnet
|
||||||
local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + {
|
local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + {
|
||||||
_config+:: {
|
_config+:: {
|
||||||
namespace: 'monitoring',
|
namespace: 'monitoring',
|
||||||
|
|
||||||
prometheus+:: {
|
prometheus+:: {
|
||||||
namespaces+: ['my-namespace', 'my-second-namespace'],
|
namespaces+: ['my-namespace', 'my-second-namespace'],
|
||||||
|
}
|
||||||
serviceMonitorKubeScheduler: {
|
},
|
||||||
|
prometheus+:: {
|
||||||
|
serviceMonitorMyNamespace: {
|
||||||
apiVersion: 'monitoring.coreos.com/v1',
|
apiVersion: 'monitoring.coreos.com/v1',
|
||||||
kind: 'ServiceMonitor',
|
kind: 'ServiceMonitor',
|
||||||
metadata: {
|
metadata: {
|
||||||
@@ -579,8 +595,16 @@ local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
{ ['00namespace-' + name]: kp.kubePrometheus[name] for name in std.objectFields(kp.kubePrometheus) } +
|
||||||
|
{ ['0prometheus-operator-' + name]: kp.prometheusOperator[name] for name in std.objectFields(kp.prometheusOperator) } +
|
||||||
|
{ ['node-exporter-' + name]: kp.nodeExporter[name] for name in std.objectFields(kp.nodeExporter) } +
|
||||||
|
{ ['kube-state-metrics-' + name]: kp.kubeStateMetrics[name] for name in std.objectFields(kp.kubeStateMetrics) } +
|
||||||
|
{ ['alertmanager-' + name]: kp.alertmanager[name] for name in std.objectFields(kp.alertmanager) } +
|
||||||
|
{ ['prometheus-' + name]: kp.prometheus[name] for name in std.objectFields(kp.prometheus) } +
|
||||||
|
{ ['grafana-' + name]: kp.grafana[name] for name in std.objectFields(kp.grafana) }
|
||||||
```
|
```
|
||||||
|
|
||||||
> NOTE: make sure your service resources has the right labels (eg. `'app': 'myapp'`) applied. Prometheus use kubernetes labels to discovery resources inside the namespaces.
|
> NOTE: make sure your service resources has the right labels (eg. `'app': 'myapp'`) applied. Prometheus use kubernetes labels to discovery resources inside the namespaces.
|
||||||
|
40
examples/additional-namespaces-servicemonitor.jsonnet
Normal file
40
examples/additional-namespaces-servicemonitor.jsonnet
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + {
|
||||||
|
_config+:: {
|
||||||
|
namespace: 'monitoring',
|
||||||
|
prometheus+:: {
|
||||||
|
namespaces+: ['my-namespace', 'my-second-namespace'],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
prometheus+:: {
|
||||||
|
serviceMonitorMyNamespace: {
|
||||||
|
apiVersion: 'monitoring.coreos.com/v1',
|
||||||
|
kind: 'ServiceMonitor',
|
||||||
|
metadata: {
|
||||||
|
name: 'my-servicemonitor',
|
||||||
|
namespace: 'my-namespace',
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
jobLabel: 'app',
|
||||||
|
endpoints: [
|
||||||
|
{
|
||||||
|
port: 'http-metrics',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
selector: {
|
||||||
|
matchLabels: {
|
||||||
|
'app': 'myapp',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
{ ['00namespace-' + name]: kp.kubePrometheus[name] for name in std.objectFields(kp.kubePrometheus) } +
|
||||||
|
{ ['0prometheus-operator-' + name]: kp.prometheusOperator[name] for name in std.objectFields(kp.prometheusOperator) } +
|
||||||
|
{ ['node-exporter-' + name]: kp.nodeExporter[name] for name in std.objectFields(kp.nodeExporter) } +
|
||||||
|
{ ['kube-state-metrics-' + name]: kp.kubeStateMetrics[name] for name in std.objectFields(kp.kubeStateMetrics) } +
|
||||||
|
{ ['alertmanager-' + name]: kp.alertmanager[name] for name in std.objectFields(kp.alertmanager) } +
|
||||||
|
{ ['prometheus-' + name]: kp.prometheus[name] for name in std.objectFields(kp.prometheus) } +
|
||||||
|
{ ['grafana-' + name]: kp.grafana[name] for name in std.objectFields(kp.grafana) }
|
Reference in New Issue
Block a user