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

Prometheus无法抓取Traefik指标 求排查缺失配置

问题修复方案

1. 修正Prometheus抓取任务的端口替换规则

你的抓取任务最后一步错误地将目标端口替换为9100,但Traefik的metrics端口是8080(对应Pod注解prometheus.io/port: "8080"),且正则表达式格式不符合Kubernetes Pod地址的规则。替换为以下正确的relabel规则:

- job_name: 'traefik'
  kubernetes_sd_configs:
    - role: pod
  relabel_configs:
    - source_labels: [__meta_kubernetes_pod_label_app]
      action: keep
      regex: traefik
    - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
      action: keep
      regex: true
    # 手动设置metrics路径,因为未配置prometheus.io/path注解
    - action: replace
      target_label: __metrics_path__
      replacement: /metrics
    # 从注解中提取端口并替换目标地址
    - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
      action: replace
      target_label: __address__
      regex: ([^:]+)(?::\d+)?;(\d+)
      replacement: $1:$2

2. 处理HostNetwork模式的网络访问问题

Traefik启用了hostNetwork: true,意味着8080端口直接绑定在节点IP上:

  • 确保Prometheus所在的网段能够访问集群节点的8080端口(检查节点安全组、防火墙规则)
  • 如果集群配置了NetworkPolicy,需添加允许Prometheus访问kube-system命名空间下8080端口的规则

3. 验证Prometheus的RBAC权限

确保Prometheus的ServiceAccount拥有发现kube-system命名空间Pod的权限,若RBAC配置限制了命名空间范围,需添加kube-system的相关权限。

4. 测试端点连通性

在Prometheus Pod内部执行curl命令,验证是否能访问Traefik的metrics端点:

# 方式1:访问Pod IP
curl http://<traefik-pod-ip>:8080/metrics
# 方式2:访问节点IP(因为用了hostNetwork)
curl http://<node-ip>:8080/metrics

若无法访问,优先排查网络连通性问题。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 10:14:57