如何在 helm install 中通过 `--set` 参数传递 `prometheus.io/scrape` 值

cil*_*ler 5 kubernetes-helm

使用https://github.com/helm/charts/tree/master/stable/elasticsearch-exporter并尝试通过--set参数传递下面的部分,但到目前为止还没有运气。

podAnnotations: 
  prometheus.io/scrape: "true"
  prometheus.io/port: "9108"
Run Code Online (Sandbox Code Playgroud)

到目前为止,我试过helm install --name prometheus-elasticsearch-exporter stable/elasticsearch-exporter

--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}
Run Code Online (Sandbox Code Playgroud)

不幸的是,这些都没有奏效。

更多细节可以在这里找到

Ami*_*pta 6

请尝试以下操作:

--set-string podAnnotations."prometheus\.io/scrape"=true \
--set-string podAnnotations."prometheus\.io/port"=9108
Run Code Online (Sandbox Code Playgroud)

您需要正确转义注释键字符串,如您链接的文档中所述:

同样,您也可以转义点序列,这在图表使用该toYaml函数解析注释、标签和节点选择器时可能会派上用场。的语法--set nodeSelector."kubernetes\.io/role"=master变为

nodeSelector:
  kubernetes.io/role: master
Run Code Online (Sandbox Code Playgroud)

您应该使用set-string而不是set因为您希望注释值是字符串而不是 booleantrue和 number 9018

这是我使用这些标志的结果:

$ 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
Run Code Online (Sandbox Code Playgroud)