Configuring Prometheus with Prometheus Operator: Difference between revisions
Jump to navigation
Jump to search
Line 43: | Line 43: | ||
Also, ServiceMonitor selector must match monitored [[Kubernetes_Service_Concepts#Service_.28ClusterIP_Service.29|Services]]' labels. | Also, ServiceMonitor selector must match monitored [[Kubernetes_Service_Concepts#Service_.28ClusterIP_Service.29|Services]]' labels. | ||
If the ServiceMonitor was configured correctly, the new monitoring target surfaces in the Prometheus server configuration, which can be inspected from the server's console (Status → Configuration). | If the ServiceMonitor was configured correctly, the new monitoring target surfaces in the Prometheus server configuration, which can be inspected from the server's [[Prometheus_Concepts#Prometheus_Console|console]] (Status → Configuration). |
Revision as of 23:09, 14 October 2020
External
- https://coreos.com/operators/prometheus/docs/0.17.0/index.html
- https://github.com/prometheus-operator/prometheus-operator
Internal
Overview
Add a Target
To add a monitoring target, deploy a ServiceMonitor custom resource:
namespace="prometheus"
cat <<EOF | kubectl -n ${namespace} apply -f -
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: pushgateway
namespace: ${namespace}
labels:
release: prometheus
spec:
endpoints:
- path: /metrics
port: "9091"
namespaceSelector:
matchNames:
- ${namespace}
selector:
matchLabels:
function: pushgateway-target
EOF
The ServiceMonitor resource must carry a label that will identify it to the Prometheus custom resource by matching the Prometheus resource "serviceMonitorSelector":
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
...
spec:
serviceMonitorSelector:
matchLabels:
release: prometheus
Also, ServiceMonitor selector must match monitored Services' labels.
If the ServiceMonitor was configured correctly, the new monitoring target surfaces in the Prometheus server configuration, which can be inspected from the server's console (Status → Configuration).