在 kube-prometheus-stack 中添加额外的 scrapeconfig 时出现问题

问题描述 投票:0回答:3

我已经通过 Helm Chart 安装了 kube-prometheus-stack。 需要为普罗米修斯添加额外的抓取配置。 创建了一个配置映射来从 grok-exporter 中抓取指标

 apiVersion: v1
 kind: ConfigMap
 metadata:
   name: prometheus
 data:
   prometheus.yml: |-
     global:
       scrape_interval: 15s
     scrape_configs:
     - job_name: 'grok'
       static_configs:
     - targets: ['grok-exporter:9144']

应用了此配置图。 然后使用以下命令从此配置映射创建秘密

       ""kubectl create secret generic grok-prometheus --from-file=grok-prometheus.yaml"

秘密已创建。 然后在kube-prometheus-stack的values.yaml中添加additionalScrapeConfigSecrets。

 additionalScrapeConfigsSecret:
   enabled: true
   name: grok-prometheus
   key: grok-prometheus.yaml

升级 helmchart 后

当我检查“kubectl get prometheus -o yaml”时,可以看到添加了额外的ScrapeConfig。

  spec:
additionalScrapeConfigs:
  key: grok-prometheus.yaml
  name: grok-prometheus

但是我在普罗米修斯输出中收到以下错误。

- lastTransitionTime: "2022-07-30T16:45:41Z"
  message: |-
    creating config failed: generating config failed: generate additional scrape configs: unmarshalling additional scrape configs failed: yaml: unmarshal errors:
      line 1: cannot unmarshal !!map into []yaml.MapSlice
  reason: ReconciliationFailed
  status: "False"
  type: Reconciled

任何人都可以帮我解决这个问题吗? 预先感谢。

kubernetes kubernetes-helm logstash-grok configmap kube-prometheus-stack
3个回答
0
投票

似乎是 ConfigMap 中的缩进问题。

targets
应比
static_configs
深一级。试试这个 YAML。

 apiVersion: v1
 kind: ConfigMap
 metadata:
   name: prometheus
 data:
   prometheus.yml: |-
     global:
       scrape_interval: 15s
     scrape_configs:
     - job_name: 'grok'
       static_configs:
       - targets: ['grok-exporter:9144']

0
投票

秘密不应该是 ConfigMap,而应该是抓取配置条目,如下所示: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/additional-scrape-config.md

- job_name: 'grok'
   static_configs:
 - targets: ['grok-exporter:9144']

这里有一个更好的文档: https://github.com/prometheus-community/helm-charts/blob/8b45bdbdabd9b54766c4beb3c562b766b268a034/charts/kube-prometheus-stack/values.yaml#L2691

根据此,您可以添加抓取配置,而无需打包成这样的秘密:

additionalScrapeConfigs: |
  - job_name: "prometheus"
  static_configs:
  - targets: ["localhost:9090"]

0
投票

额外的ScrapeConfigs:

  • job_name:“卡桑德拉” 静态配置:
    • 目标:[“cassandra-exporter:8080”]

其他Scrape配置:|

  • job_name:“卡桑德拉” 静态配置:
    • 目标:[“cassandra-exporter:8080”]
  1. https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/additional-scrape-config.md

我尝试了这些配置,但没有任何效果。我正在尝试为 cassandra-exporter 设置抓取配置。

我已经在kube-prometheus-stack helm-chart的values.yaml文件中完成了上述配置https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/ Chart.yaml

我可以尝试其他任何事情,还是我缺少上述配置中的任何内容。

© www.soinside.com 2019 - 2024. All rights reserved.