我们有一个带有外部dns的设置,用于基于服务注释创建和绑定dns条目.
例如,我们为警报管理器提供了如下服务:
apiVersion: v1
kind: Service
metadata:
name: prometheus-kube-prometheus-alertmanager
namespace: prometheus
labels:
...
heritage: Helm
prometheus-monitor-https: 'true'
release: prometheus
self-monitor: 'true'
annotations:
external-dns.alpha.kubernetes.io/hostname: alertmanager.ourdomain.com
external-dns.alpha.kubernetes.io/ttl: '60'
spec:
ports:
- name: web
protocol: TCP
port: 80
targetPort: 9093
nodePort: 31126
selector:
alertmanager: prometheus-kube-prometheus-alertmanager
app.kubernetes.io/name: alertmanager
type: LoadBalancer
sessionAffinity: None
externalTrafficPolicy: Cluster(缩写)
我想使用带有注释数据的黑盒导出程序,因此我们不必在这里手动添加监视,而是依赖kubernetes提供要监视的信息。
为此,我编写了一个服务程序,但它与服务不匹配,并调用了黑匣子出口商。
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: blackbox-exporter-monitor-https-external
namespace: prometheus
spec:
namespaceSelector:
any: true
selector:
matchLabels:
prometheus-monitor-https: any
targetLabels:
- environment
- instance
endpoints:
- metricRelabelings:
- sourceLabels: [__meta_kubernetes_service_annotation_external_dns_alpha_kubernetes_io_hostname]
targetLabel: __param_target
replacement: "https://$1"
- sourceLabels: [__param_target]
targetLabel: instance
- targetLabel: __param_scheme
replacement: https
- targetLabel: __address__
replacement: prometheus-blackbox-exporter:9115
path: /probe
params:
debug:
- "true"
module:
- "http_2xx"我不明白为什么它不应该与服务相匹配。你有什么提示吗?
发布于 2021-12-08 20:47:21
该服务有标签prometheus-monitor-https: 'true',而ServiceMonitor有一个selector.matchLabels of prometheus-monitor-https: any。
如果您将此更改为ServiceMonitor的ServiceMonitor等于prometheus-monitor-https: 'true',那么我认为它应该可以工作。matchLabels查找标签键值对的预期匹配。
我还看到你写了namespaceSelector is any: true。很高兴知道namespaceSelector以不同的方式工作。它需要它应该在其中找到的名称空间的标签。在您的示例中,它将查找带有标签any: true的命名空间。但我认为您实际上希望选择所有的名称空间,这等于根本不指定namespaceSelector。
https://stackoverflow.com/questions/70278726
复制相似问题