Prometheus operator doesn't add external targets
What did you do? I've installed prometheus-operator and kube-prometheus with helm:
helm list --tls
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
kube-prometheus 1 Thu Nov 8 14:17:40 2018 DEPLOYED kube-prometheus-0.0.100 monitoring
prometheus-operator 1 Mon Oct 29 15:26:00 2018 DEPLOYED prometheus-operator-0.0.28 0.20.0 monitoring
Then I wanted to monitor external ETCD nodes. So I've installed node-exporter on them:
systemctl status exporter.service
● exporter.service - Prometheus exporter for hardware and OS metrics expose
Loaded: loaded (/etc/systemd/system/exporter.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2018-10-30 15:57:24 +06; 1 weeks 5 days ago
Main PID: 28750 (node_exporter)
Tasks: 4
Memory: 2.2M
CPU: 1.356s
CGroup: /system.slice/exporter.service
└─28750 /opt/nodexporter/node_exporter
Oct 30 15:57:25 k8s-prd-etcd03 node_exporter[28750]: time="2018-10-30T15:57:25+06:00" level=info msg=" - filesystem" source="node_exporter.go:52"
Oct 30 15:57:25 k8s-etcd03 node_exporter[28750]: time="2018-10-30T15:57:25+06:00" level=info msg=" - meminfo" source="node_exporter.go:52"
Oct 30 15:57:25 k8s-etcd03 node_exporter[28750]: time="2018-10-30T15:57:25+06:00" level=info msg=" - netstat" source="node_exporter.go:52"
Oct 30 15:57:25 k8s-etcd03 node_exporter[28750]: time="2018-10-30T15:57:25+06:00" level=info msg=" - filefd" source="node_exporter.go:52"
Oct 30 15:57:25 k8s-etcd03 node_exporter[28750]: time="2018-10-30T15:57:25+06:00" level=info msg=" - vmstat" source="node_exporter.go:52"
Oct 30 15:57:25 k8s-etcd03 node_exporter[28750]: time="2018-10-30T15:57:25+06:00" level=info msg=" - uname" source="node_exporter.go:52"
Oct 30 15:57:25 k8s-etcd03 node_exporter[28750]: time="2018-10-30T15:57:25+06:00" level=info msg=" - timex" source="node_exporter.go:52"
Oct 30 15:57:25 k8s-etcd03 node_exporter[28750]: time="2018-10-30T15:57:25+06:00" level=info msg=" - cpu" source="node_exporter.go:52"
Oct 30 15:57:25 k8s-etcd03 node_exporter[28750]: time="2018-10-30T15:57:25+06:00" level=info msg=" - netdev" source="node_exporter.go:52"
Oct 30 15:57:25 k8s-etcd03 node_exporter[28750]: time="2018-10-30T15:57:25+06:00" level=info msg="Listening on :9100" source="node_exporter.go:76"
And I've tried to add ETCD external nodes as prometheus targets and applied following manifest files:
cat etcd-nodes-ep.yaml
apiVersion: v1
kind: Endpoints
metadata:
labels:
nodes: etcd-nodes
name: etcd-nodes
namespace: monitoring
subsets:
- addresses:
- ip: yyy.yyy.yyy.21
nodeName: k8s-etcd01.xxxx.xx
- ip: yyy.yyy.yyy.22
nodeName: k8s-etcd02.xxxx.xx
- ip: yyy.yyy.yyy.23
nodeName: k8s-etcd03.xxxx.xx
ports:
- name: nodexp
port: 9100
protocol: TCP
cat etcd-nodes-svc.yml
apiVersion: v1
kind: Service
metadata:
labels:
nodes: etcd-nodes
name: etcd-nodes
namespace: monitoring
spec:
clusterIP: None
ports:
- name: nodexp
port: 9100
protocol: TCP
targetPort: 9100
selector:
nodes: etcd-nodes
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
cat etcd-nodes-sm.yml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
prometheus: kube-prometheus
name: etcd-nodes
namespace: monitoring
spec:
endpoints:
- interval: 30s
port: nodexp
jobLabel: nodes
namespaceSelector:
matchNames:
- monitoring
selector:
matchLabels:
nodes: etcd-nodes
What did you expect to see?
I've expected to see ETCD nodes as prometheus target on https://prometheus.xxxx.xx/targets
But I see only new prometheus config:
- job_name: monitoring/etcd-nodes/0
scrape_interval: 30s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
kubernetes_sd_configs:
- api_server: null
role: endpoints
namespaces:
names:
- monitoring
relabel_configs:
- source_labels: [__meta_kubernetes_service_label_nodes]
separator: ;
regex: etcd-nodes
replacement: $1
action: keep
- source_labels: [__meta_kubernetes_endpoint_port_name]
separator: ;
regex: nodexp
replacement: $1
action: keep
- source_labels: [__meta_kubernetes_namespace]
separator: ;
regex: (.*)
target_label: namespace
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_pod_name]
separator: ;
regex: (.*)
target_label: pod
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_service_name]
separator: ;
regex: (.*)
target_label: service
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_service_name]
separator: ;
regex: (.*)
target_label: job
replacement: ${1}
action: replace
- source_labels: [__meta_kubernetes_service_label_nodes]
separator: ;
regex: (.+)
target_label: job
replacement: ${1}
action: replace
- separator: ;
regex: (.*)
target_label: endpoint
replacement: nodexp
action: replace
Prometheus config reloader logs:
level=info ts=2018-11-12T04:46:11.442722953Z caller=reloader.go:182 msg="Prometheus reload triggered" cfg_in=/etc/prometheus/config/prometheus.yaml cfg_out=/etc/prometheus/config_out/prometheus.env.yaml rule_dir=
level=debug ts=2018-11-12T04:47:41.752278986Z caller=reloader.go:97 msg="received watch event" op=REMOVE name=/etc/prometheus/config/prometheus.yaml
level=info ts=2018-11-12T04:55:02.800763013Z caller=reloader.go:182 msg="Prometheus reload triggered" cfg_in=/etc/prometheus/config/prometheus.yaml cfg_out=/etc/prometheus/config_out/prometheus.env.yaml rule_dir=
level=info ts=2018-11-12T05:01:02.003865073Z caller=reloader.go:182 msg="Prometheus reload triggered" cfg_in=/etc/prometheus/config/prometheus.yaml cfg_out=/etc/prometheus/config_out/prometheus.env.yaml rule_dir=
level=info ts=2018-11-12T05:16:02.535123554Z caller=reloader.go:182 msg="Prometheus reload triggered" cfg_in=/etc/prometheus/config/prometheus.yaml cfg_out=/etc/prometheus/config_out/prometheus.env.yaml rule_dir=
level=info ts=2018-11-12T06:04:02.214478316Z caller=reloader.go:182 msg="Prometheus reload triggered" cfg_in=/etc/prometheus/config/prometheus.yaml cfg_out=/etc/prometheus/config_out/prometheus.env.yaml rule_dir=
Environment Kube-prometheus:
Service Monitor Selector:
Match Labels:
Prometheus: kube-prometheus
Version: v2.2.1
OS: Ubuntu 16.04 Helm v2.11.0
- Prometheus Operator version:
prometheus-operator:v0.20.0
- Kubernetes version information:
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.1", GitCommit:"d4ab47518836c750f9949b9e0d387f20fb92260b", GitTreeState:"archive", BuildDate:"2018-04-26T10:10:34Z", GoVersion:"go1.9.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.3", GitCommit:"a4529464e4629c21224b3d52edfe0ea91b072862", GitTreeState:"clean", BuildDate:"2018-09-09T17:53:03Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}
- Kubernetes cluster kind:
Installed with Kubespray v2.7.0 On VM's on vSphere Cloud
- Prometheus Operator Logs:
level=info ts=2018-11-12T06:05:21.055789504Z caller=operator.go:396 component=alertmanageroperator msg="sync alertmanager" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:05:34.33002852Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:05:34.57230299Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:06:27.662964618Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:06:29.158777046Z caller=operator.go:396 component=alertmanageroperator msg="sync alertmanager" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:06:53.867566128Z caller=operator.go:396 component=alertmanageroperator msg="sync alertmanager" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:06:54.451903781Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:06:55.042885699Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:07:00.355762964Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:07:00.574009245Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:07:00.748934624Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:07:00.944621818Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:07:01.058900907Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:07:01.584169488Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:07:01.830668089Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:07:05.08271496Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:07:05.366405298Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:07:59.498020104Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:07:59.779150151Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:08:05.147563763Z caller=operator.go:396 component=alertmanageroperator msg="sync alertmanager" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:08:24.23101099Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:08:50.385749936Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:08:50.664193587Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:09:48.998888974Z caller=operator.go:396 component=alertmanageroperator msg="sync alertmanager" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:09:56.131097825Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:09:57.131650509Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
level=info ts=2018-11-12T06:09:57.355739709Z caller=operator.go:731 component=prometheusoperator msg="sync prometheus" key=monitoring/kube-prometheus
Could you please help me with advice? Maybe I used incorrect manifests or maybe I should do something else?
Also I've tried to add external target as it described in: https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-mapping-external-services
With following manifests:
cat gpu-metrics-ep.yml
---
apiVersion: v1
kind: Endpoints
metadata:
namespace: monitoring
name: gpu-metrics
labels:
k8s-app: gpu-metrics
prometheus: kube-prometheus
subsets:
- addresses:
- ip: yyy.yyy.yyy.21
ports:
- name: metrics
port: 9100
protocol: TCP
cat gpu-metrics-svc.yml
---
apiVersion: v1
kind: Service
metadata:
name: gpu-metrics-svc
namespace: monitoring
labels:
k8s-app: gpu-metrics
prometheus: kube-prometheus
spec:
type: ExternalName
externalName: yyy.yyy.yyy.21
clusterIP: ""
ports:
- name: metrics
port: 9100
protocol: TCP
targetPort: 9100
cat gpu-metrics-sm.yml
--
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
namespace: monitoring
name: gpu-metrics-sm
labels:
k8s-app: gpu-metrics
prometheus: kube-prometheus
spec:
selector:
matchLabels:
k8s-app: gpu-metrics
prometheus: kube-prometheus
namespaceSelector:
matchNames:
- monitoring
endpoints:
- port: metrics
interval: 10s
honorLabels: true
The result was same.
wget target metrics from prometheus pod executed successfully
/prometheus $ wget http://xxx.xxx.xxx.21:9100/metrics
Connecting to xxx.xxx.xxx.21:9100 (xxx.xxx.xxx.21:9100)
metrics 100% |******************************************************************************************************************************************************************| 104k 0:00:00 ETA
/prometheus $
And adding targets works after I restarted prometheus-kube-prometheus-n pods. It is not excepted behavior.
Maybe it's possible to change prometheus behavior to adding new targets without restarting prometheus pods?
The Service itself can’t have a selector that will cause the Endpoints object’s content to be overridden.
It's strange. I deployed same endpoints, service and servicemonitor to my second cluster. Targets didn't appear for first time. I deleted prometheus-kube-prometheus-n pods. After that targets appear.
Than I deleted endpoints, service and servicemonitor and recreated them. And they appeared in https://prometheus2.xxxx.xx/targets without restarting pods.
I suppose it was an some error in prometheus-kube-prometheus-n pods. But I don't know what it exactly was.
@brancz Thank You for your advice!
I've deleted label selector from service manifest.
Just to understand correctly, your problem was solved correct?
@brancz
Now, after restarting, kube-prometheus works fine. I'm going to close this issue. But I haven't added new endpoints to it yet in order to make sure everything works correctly. Will I be able to open the request again if the attempt fails?
Thank you for your time and your responses.
Please feel free to open a new issue should you still have any :slightly_smiling_face: .
Same problem here, but i am using openshift/cluster-monitoring-operator
I tried to restart prometheus pod but i didn't have success.