prometheus-operator: New serviceMonitor does not show up in prometheus
What did you do?
Added a new serviceMonitor in values.yaml for kube-prometheus
- name: kube-prometheus-nginx-ingress
selector:
matchLabels:
app: nginx-ingress
endpoints:
- port: metrics
interval: 30s
namespaceSelector:
any: true
What did you expect to see?
I’d expect to see kube-prometheus-nginx-ingress
show up under targets in Prometheus and that Prometheus started scarping the targets.
What did you see instead? Under which circumstances?
No new targets where added and kube-prometheus-nginx-ingress
does not show up in the prometheus configuration. The serviceMonitor is created but not “applied”.
$ kubectl get servicemonitor kube-prometheus-nginx-ingress
NAME AGE
kube-prometheus-nginx-ingress 11m
Environment
- Kubernetes version information:
kubectl version
Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.3", GitCommit:"f0efb3cb883751c5ffdbe6d515f3cb4fbe7b7acd", GitTreeState:"clean", BuildDate:"2017-11-08T18:39:33Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.6", GitCommit:"6260bb08c46c31eea6cb538b34a9ceb3e406689c", GitTreeState:"clean", BuildDate:"2017-12-21T06:23:29Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
-
Kubernetes cluster kind:
KOPS on AWS
-
Manifests:
prometheus:
rbacEnable: false
alertingEndpoints: []
config:
specifiedInValues: true
value: {}
externalUrl: ""
image:
repository: quay.io/prometheus/prometheus
tag: v2.0.0
ingress:
enabled: false
annotations: {}
fqdn: ""
tls: []
nodeSelector: {}
paused: false
replicaCount: 1
resources: {}
retention: 24h
routePrefix: /
rulesSelector: {}
rules:
specifiedInValues: true
value: {}
service:
annotations: {}
clusterIP: ""
externalIPs: []
loadBalancerIP: ""
loadBalancerSourceRanges: []
nodePort: 30900
type: ClusterIP
serviceMonitorsSelector: {}
serviceMonitors:
- name: kube-prometheus-nginx-ingress
selector:
matchLabels:
app: nginx-ingress
endpoints:
- port: metrics
interval: 30s
namespaceSelector:
any: true
- Prometheus Operator Logs:
ts=2018-01-14T22:23:58Z caller=operator.go:980 component=prometheusoperator msg="updating config skipped, no configuration change"
ts=2018-01-14T22:24:09Z caller=operator.go:671 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
ts=2018-01-14T22:24:09Z caller=operator.go:980 component=prometheusoperator msg="updating config skipped, no configuration change"
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 25 (21 by maintainers)
I finally figure out what’s the issue 💣
In your prometheus crd you have the serviceMonitorSelector below
That means the operator will just look for serviceMonitors with this labels. On the
kube-prometheus-nginx-ingress
serviceMonitor you have all the labels below, exceptprometheus: kube-prometheus
.My guesss is when you created the serviceMonitorSelector, the helm chart didn’t inject the same labels used by others serviceMonitors that are working. The quick fix is to change the kube-prometheus-nginx-ingress serviceMonitor and manually add the label
prometheus: kube-prometheus
. Let me know if this fix your issue so I’ll address a PR to fix that.I had same problem, solved by changing
serviceMonitorsSelector
Prometheus object generated by helm:
kube-prometheus.yaml
Solution:
Change
serviceMonitorSelector
in prometheus resource (usingkubectl edit prometheus -n monitoring kube-prometheus
)Adding Metrics example:
Service to expose nginx metrics
Service monitor
After adding this you should be able to see new target in prometheus UI: https://you-prometheus-ui/targets
Adding nginx dashboard to grafana:
"pluginName": "Prometheus"
->"pluginName": "prometheus"
"datasource": "Prometheus"
->"datasource": "prometheus"
You should see something like:
@brancz Would it be nice to add docs how to integrate with most common services like ingress?
#895 fixed this issue