从 helm 命令行设置嵌套数据结构?

Setting nested data structures from helm command line?

我正在安装 prometheus-redis-exporter Helm chart。它的 Deployment 对象有一种注入注释的方法:

# deployment.yaml
...
  template:
    metadata:
      annotations:
{{ toYaml .Values.annotations | indent 8 }}

通常,如果我提供一个值文件,我可以这样做:

# values.yaml
annotations:
  foo: bar
  bash: baz

然后安装图表:

helm install --values values.yaml

但是,在某些情况下,在命令行上使用 --set 指定这些值对我来说更简单,我只是不确定如何指定这样的嵌套集。

如何在命令行上安装 helm chart 时设置上述 annotations 对象:

helm install --set <what_goes_here>

helm 文档有一个部分 The Format and Limitations of --set,其中包含您要查找的内容。

--set outer.inner=value 结果:

outer:
  inner: value

因此,您的整个 helm 命令如下所示:

helm install --set annotations.foo=bar,annotations.bash=baz stable/prometheus-redis-exporter

补充一下,如果您希望用“.”覆盖某个键。在密钥名称中,在“.”之前添加一个反斜杠(“\”)。

例如,值(取自 grafana):

grafana.ini:
  server:
    root_url: https://my.example.com

要编辑 root_url 值,我们将传递 --set grafana\.ini.server.root_url=https://your.example.com