K8s部署Blackbox Exporter通过Ingress子路径访问无数据问题
问题解决:Blackbox-Exporter通过Ingress子路径访问时Metrics链接失效
问题原因
Blackbox-exporter的UI默认生成的链接(如/metrics、/probe)均为根路径开头的绝对路径,当通过/blackbox/子路径访问时,点击这些链接会直接跳转到https://example.com/metrics,而非预期的https://example.com/blackbox/metrics,导致无法加载数据。
解决方案
1. 修改Blackbox-Exporter的Deployment配置
在容器启动参数中添加--web.route-prefix=/blackbox,让应用生成的所有链接自动带上/blackbox前缀:
apiVersion: apps/v1 kind: Deployment metadata: name: prometheus-blackbox-exporter namespace: test spec: replicas: 1 selector: matchLabels: app: prometheus-blackbox-exporter template: metadata: labels: app: prometheus-blackbox-exporter spec: containers: - name: prometheus-blackbox-exporter image: prom/blackbox-exporter:latest args: - --config.file=/etc/blackbox/blackbox.yml - --web.route-prefix=/blackbox # 添加该参数指定路由前缀 ports: - containerPort: 9115 volumeMounts: - name: config mountPath: /etc/blackbox volumes: - name: config configMap: name: prometheus-blackbox-exporter-config
2. 调整Ingress配置
更新Ingress规则,确保请求能正确转发到应用的子路径:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-blackbox namespace: test spec: ingressClassName: nginx rules: - host: example.com http: paths: - backend: service: name: prometheus-blackbox-exporter port: number: 9115 path: /blackbox pathType: Prefix
3. 验证配置
- 重新部署Blackbox-Exporter:
kubectl apply -f deployment.yaml -n test - 更新Ingress配置:
kubectl apply -f ingress.yaml -n test - 访问
https://example.com/blackbox/,点击UI中的Metrics或Probe链接,此时链接会自动指向https://example.com/blackbox/metrics,可正常加载数据。
内容的提问来源于stack exchange,提问作者SVD
相关产品推荐
相关产品推荐

