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

x0fgdtte  于 4个月前  发布在  Kubernetes
关注(0)|答案(3)|浏览(90)

我已经通过Helm Chart安装了kube-prometheus-stack。需要为prometheus添加额外的scrape参数。创建了一个scrape map来从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']

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

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


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

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


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

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


但是我在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


有人能帮我吗?先谢了。

f0brbegy

f0brbegy1#

看起来像是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']

字符串

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

- 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
根据这一点,你可以在没有 Package 的情况下将刮擦添加到像这样的秘密中:

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

相关问题