官网对kubernetes_sd_config
的详细说明文档
https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config
kubernetes_sd_config
用于配置自动发现的。关于服务自动发现,还可以参考这篇实战:Prometheus kubernetes-cadvisor服务自动发现
Kubernetes SD configurations allow retrieving scrape targets from Kubernetes’ REST API and always staying synchronized with the cluster state.
role的类型有以下几种:node
, service
, pod
, endpoints
和ingress
。
当role的值为endpoints
时,官网说明:
The endpoints role discovers targets from listed endpoints of a service. For each endpoint address one target is discovered per port. If the endpoint is backed by a pod, all additional container ports of the pod, not bound to an endpoint port, are discovered as targets as well.
然后prometheus-additional.yaml
的容是:
1 | - job_name: 'kubernetes-service-endpoints' |
我理解的逻辑是:
- 首先查找ep,svc两个同时存在的
- 然后查找svc的annotations标签
__meta_kubernetes_service_annotation_prometheus_io_scrape
的值为true
的。 - 最后看到ep里面有两个
Addresses
,所以显示两个Targets。