How to add extraScrapeConfigs to Prometheus helm chart from --set argument?

3/26/2019

I want to deploy Prometheus from the official helm chart on the stable repo.

Also, I want to add my own scrape config.

I can successfully add extra configs directly from the values.yml file of the chart, after downloading and altering it, but when I try to pass it as argument with --set nothing happens.

This works [in values.yml]:

# adds additional scrape configs to prometheus.yml
# must be a string so you have to add a | after extraScrapeConfigs:
# example adds prometheus-blackbox-exporter scrape config
extraScrapeConfigs: |
  - job_name: 'sample-job'
    scrape_interval: 1s
    metrics_path: /
    kubernetes_sd_configs:
      - role: endpoints

this does not:

sudo helm upgrade --install prometheus \
--set rbac.create=true \
--set server.persistentVolume.enabled=false \
--set alertmanager.persistentVolume.enabled=false \
--set alertmanager.enabled=false \
--set kubeStateMetrics.enabled=false \
--set nodeExporter.enabled=false \
--set pushgateway.enabled=false \
--set extraScrapeConfigs="|
  - job_name: 'sample-pods'
    scrape_interval: 1s
    metrics_path: /
    kubernetes_sd_configs:
      - role: endpoints
" \
stable/prometheus

Is it possible someway?

I found this SO question How to use --set to set values with Prometheus chart? , but I cannot find a way to apply it to my case.

-- Kostas Demiris
kubernetes-helm
prometheus

1 Answer

3/28/2019

When we are going to inject a multi-line text into values we need to deal with indentation in YAML.

For your particular case it is:

sudo helm upgrade --install prometheus \
--set rbac.create=true \
--set server.persistentVolume.enabled=false \
--set alertmanager.persistentVolume.enabled=false \
--set alertmanager.enabled=false \
--set kubeStateMetrics.enabled=false \
--set nodeExporter.enabled=false \
--set pushgateway.enabled=false \
--set extraScrapeConfigs="- job_name: 'sample-pods'
  scrape_interval: 1s
  metrics_path: /
  kubernetes_sd_configs:
    - role: endpoints" \
stable/prometheus

The more elegant way is to use --set-file key=filepath construction instead of --set:

1. We create extraScrapeConfigs.yaml and put there our value as is:

- job_name: 'sample-pods'
  scrape_interval: 1s
  metrics_path: /
  kubernetes_sd_configs:
    - role: endpoints

2. We deploy stable/prometheus helm chart:

sudo helm upgrade --install prometheus \
--set rbac.create=true \
--set server.persistentVolume.enabled=false \
--set alertmanager.persistentVolume.enabled=false \
--set alertmanager.enabled=false \
--set kubeStateMetrics.enabled=false \
--set nodeExporter.enabled=false \
--set pushgateway.enabled=false \
--set-file extraScrapeConfigs=extraScrapeConfigs.yaml \
stable/prometheus
-- nickgryg
Source: StackOverflow