How to pass `prometheus.io/scrape` value through `--set` parameter in helm install

8/10/2019

Using https://github.com/helm/charts/tree/master/stable/elasticsearch-exporter and trying to pass the part below via --set parameter but so far no luck.

podAnnotations: 
  prometheus.io/scrape: "true"
  prometheus.io/port: "9108"

so far I tried helm install --name prometheus-elasticsearch-exporter stable/elasticsearch-exporter with

--set podAnnotations."prometheus.io/scrape"=true,podAnnotations."prometheus.io/port"=9108

--set podAnnotations[0]."prometheus.io/scrape"=true,podAnnotations[0]."prometheus.io/port"=9108

--set podAnnotations."prometheus\.io\/scrape"=true,podAnnotations."prometheus\.io\/port"=9108

--set podAnnotations={"prometheus.io/scrape":true,"prometheus.io/port":9108}

--set podAnnotations={"prometheus.io/scrape"=true\,"prometheus.io/port"=9108}

and unfortunately, none of those worked.

More details can be found in here

-- cilerler
kubernetes-helm

1 Answer

8/10/2019

Try the following:

--set-string podAnnotations."prometheus\.io/scrape"=true \
--set-string podAnnotations."prometheus\.io/port"=9108

You need to escape the annotation key strings correctly, as described precisely in the doc you linked:

Similarly, you can escape dot sequences as well, which may come in handy when charts use the toYaml function to parse annotations, labels and node selectors. The syntax for --set nodeSelector."kubernetes\.io/role"=master becomes

nodeSelector:
  kubernetes.io/role: master

You should use set-string instead of set because you want the annotation values to be strings rather than boolean true and number 9018.

Here's the result I'm getting using those flags:

$ helm template . \
  --set-string podAnnotations."prometheus\.io/scrape"=true \
  --set-string podAnnotations."prometheus\.io/port"=9108 \
  | grep -C 5 annotations
  template:
    metadata:
      labels:
        app: elasticsearch-exporter
        release: "release-name"
      annotations:
        prometheus.io/port: "9108"
        prometheus.io/scrape: "true"

    spec:
      restartPolicy: Always
-- Amit Kumar Gupta
Source: StackOverflow