You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Blackbox-exporter与Google Managed Prometheus配置集成?

Google Managed Prometheus 与 Blackbox-exporter 集成方案(亲测可行)

完全可以通过 PodMonitoring 实现 Blackbox-exporter 的自动 Ingress 探测,替代原有 Probe 资源的功能,以下是具体配置步骤和问题排查要点:

1. 配置 Blackbox-exporter 自动发现 Ingress

首先要让 Blackbox-exporter 能自动抓取集群内所有 Ingress 主机,需要修改其 ConfigMap 配置,添加 Kubernetes 服务发现规则:

apiVersion: v1
kind: ConfigMap
metadata:
  name: blackbox-exporter-config
  namespace: your-namespace  # 替换为 Blackbox 所在命名空间
data:
  config.yml: |
    modules:
      http_2xx:
        prober: http
        http:
          valid_status_codes: [200,301,302]
          method: GET
          follow_redirects: true

    scrape_configs:
    - job_name: 'blackbox-ingress'
      kubernetes_sd_configs:
      - role: ingress
      relabel_configs:
      - source_labels: [__meta_kubernetes_ingress_host]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: blackbox-exporter:9115  # 替换为你的 Blackbox Service 名称+端口

关键权限补充

Blackbox-exporter 需要读取集群 Ingress 资源的权限,给其对应的 ServiceAccount 绑定集群角色:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: blackbox-ingress-reader
rules:
- apiGroups: ["networking.k8s.io"]
  resources: ["ingresses"]
  verbs: ["list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: blackbox-ingress-reader-binding
subjects:
- kind: ServiceAccount
  name: blackbox-exporter
  namespace: your-namespace
roleRef:
  kind: ClusterRole
  name: blackbox-ingress-reader
  apiGroup: rbac.authorization.k8s.io

2. 配置 GMP 的 PodMonitoring 采集指标

创建 PodMonitoring 资源,让 GMP 定期采集 Blackbox-exporter 暴露的探测指标:

apiVersion: monitoring.googleapis.com/v1
kind: PodMonitoring
metadata:
  name: blackbox-exporter-monitoring
  namespace: your-namespace
spec:
  selector:
    matchLabels:
      app: blackbox-exporter  # 替换为你的 Blackbox Pod 标签
  endpoints:
  - port: http
    path: /metrics
    interval: 30s

3. 排查指标不全问题

如果端口转发后看不到所有 Ingress 的探测指标,从这几个方向排查:

  • 检查 Blackbox 的 ConfigMap 中 scrape_configs 配置是否正确,尤其是 kubernetes_sd_configs 的 role: ingress 是否存在
  • 确认 Blackbox 的 ServiceAccount 已绑定正确的集群角色,能正常读取 Ingress 列表
  • 验证 __address__ 的替换值是 Blackbox Service 的正确地址,否则无法发起探测
  • 检查 modules 中的探测规则是否符合需求,比如是否允许了需要的 HTTP 状态码、是否开启重定向跟随

4. 验证配置

部署完所有资源后等待 5-10 分钟,在 GMP 的 Metrics Explorer 中查询 probe_success{job="blackbox-ingress"},应该能看到所有 Ingress 主机的探测状态指标。

内容的提问来源于stack exchange,提问作者Rick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 22:42:49