0

I've Installed kube-prometheus-stack through helm chart. Need to add additional scrape configs for prometheus. Created a configmap to scrape the metrics from 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']

Applied this configmap. Then created the secret from this configmap using the below command

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

Secret is created. Then Added additionalScrapeConfigSecrets in the values.yaml of kube-prometheus-stack.

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

After this upgraded the helmchart

when I check the "kubectl get prometheus -o yaml" able to see the additionalScrapeConfigs are added.

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

But I got the below error in prometheus output.

- 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

Can anyone help me with this. Thanks in advance.

Hema Sri
  • 11
  • 2

2 Answers2

0

Seems like indentation issue in the ConfigMap. targets should be one level deeper than static_configs. Try this 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']
Emruz Hossain
  • 4,764
  • 18
  • 26
0

The secret should not be a ConfigMap, but a instead the scrape config entry, like documented here: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/additional-scrape-config.md

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

Here is a better documentation: https://github.com/prometheus-community/helm-charts/blob/8b45bdbdabd9b54766c4beb3c562b766b268a034/charts/kube-prometheus-stack/values.yaml#L2691

According to this, you could add scrape configs without packaging into a secret like this:

additionalScrapeConfigs: |
  - job_name: "prometheus"
  static_configs:
  - targets: ["localhost:9090"]
Adam Malik
  • 345
  • 1
  • 7