kubernetes 在kube-prometheus-stack中添加额外的scrapeconfigs的问题

x0fgdtte  于 2024-01-07  发布在  Kubernetes
关注(0)|答案(3)|浏览(220)

我已经通过Helm Chart安装了kube-prometheus-stack。需要为prometheus添加额外的scrape参数。创建了一个scrape map来从grok-exporter中抓取指标

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: prometheus
  5. data:
  6. prometheus.yml: |-
  7. global:
  8. scrape_interval: 15s
  9. scrape_configs:
  10. - job_name: 'grok'
  11. static_configs:
  12. - targets: ['grok-exporter:9144']

字符串
应用了这个加密Map。然后使用下面的命令从这个加密Map中创建了密钥

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


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

  1. additionalScrapeConfigsSecret:
  2. enabled: true
  3. name: grok-prometheus
  4. key: grok-prometheus.yaml


在此之后升级了 Helm 图
当我检查“kubectl get prometheus -o yaml”时,可以看到添加了additionalScrapeConfigs。

  1. spec:
  2. additionalScrapeConfigs:
  3. key: grok-prometheus.yaml
  4. name: grok-prometheus


但是我在prometheus输出中得到了下面的错误。

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


有人能帮我吗?先谢了。

f0brbegy

f0brbegy1#

看起来像是ConfigMap中的缩进问题。targets应该比static_configs深一层。试试这个YAML。

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: prometheus
  5. data:
  6. prometheus.yml: |-
  7. global:
  8. scrape_interval: 15s
  9. scrape_configs:
  10. - job_name: 'grok'
  11. static_configs:
  12. - targets: ['grok-exporter:9144']

字符串

vohkndzv

vohkndzv2#

其他ScrapeConfigs:

  • 作业名称:“cassandra”静态作业名称:
  • 目标:[“cassandra-exporter:8080”]

其他ScrapeConfigs:|

  • 作业名称:“cassandra”静态作业名称:
  • 目标:[“cassandra-exporter:8080”]
  1. https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/additional-scrape-config.md
    我尝试了这些配置,但没有什么是为我工作。我试图设置刮配置cassandra出口商。
    我已经在kube-prometheus-stack helm-chart https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/Chart.yaml的values.yaml文件中完成了以上配置
    任何其他的东西,我可以尝试或我错过了任何在上述配置。
展开查看全部
ztmd8pv5

ztmd8pv53#

秘密不应该是一个ConfigMap,而是一个刮取配置条目,如这里所述:https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/additional-scrape-config.md

  1. - job_name: 'grok'
  2. static_configs:
  3. - targets: ['grok-exporter:9144']

字符串
这里有一个更好的文档:https://github.com/prometheus-community/helm-charts/blob/8b45bdbdabd9b54766c4beb3c562b766b268a034/charts/kube-prometheus-stack/values.yaml#L2691
根据这一点,你可以在没有 Package 的情况下将刮擦添加到像这样的秘密中:

  1. additionalScrapeConfigs: |
  2. - job_name: "prometheus"
  3. static_configs:
  4. - targets: ["localhost:9090"]

展开查看全部

相关问题