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

在kube-prometheus-stack中添加自定义Prometheus采集指标失败求助

解决kube-prometheus-stack中additionalScrapeConfigs不生效的问题

1. 核对custom.yml的配置层级与格式

kube-prometheus-stack的additionalScrapeConfigs属于prometheus.prometheusSpec下的子配置,你的custom.yml必须遵循正确的嵌套结构,示例如下:

prometheus:
  prometheusSpec:
    additionalScrapeConfigs:
    - job_name: "custom-targets"
      static_configs:
      - targets: ["localhost:9090","x.x.x.x:9095","a.b.c.d:8095"]

注意:必须使用2个空格缩进(禁止用Tab),yaml格式错误会直接导致helm忽略该配置块。

2. 验证helm配置是否已正确加载

执行以下命令查看当前release生效的values,确认自定义配置是否被应用:

helm get values prometheus

如果输出中没有prometheus.prometheusSpec.additionalScrapeConfigs相关内容,说明custom.yml的结构有误,重新调整层级后再次执行upgrade。

3. 检查Prometheus配置载体并触发Pod更新

kube-prometheus-stack默认将Prometheus配置存储在Secret中,先确认Secret是否已更新:

kubectl get secret prometheus-prometheus-kube-prometheus-prometheus -o yaml | grep -A 20 "prometheus.yaml"

若Secret中已包含你的自定义scrape配置,但Pod未自动更新,手动重启Prometheus StatefulSet强制加载新配置:

kubectl rollout restart statefulset prometheus-prometheus-kube-prometheus-prometheus

4. 避开常见误区

  • 无需复制官方values中整个additionalScrapeConfigs块,仅保留你需要添加的自定义job配置即可(官方默认该字段为空数组)。
  • 确认helm upgrade命令中的release名称正确,可通过helm list查看当前集群内的helm release列表,确保与你使用的prometheus名称一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 07:09:38