string 如何使用 helm 设置多个值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48316330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:38:55  来源:igfitidea点击:

How to set multiple values with helm?

stringshellkubernetescommand-line-interfacekubernetes-helm

提问by online

Use helminstall can set value when install a chart like:

使用helminstall 可以在安装图表时设置值,例如:

helm install --set favoriteDrink=slurm ./mychart

Now want to set value like:

现在想设置如下值:

helm install --set aws.subnets="subnet-123456, subnet-654321" ./mychart

But failed:

但失败了:

Error: failed parsing --set data: key " subnet-654321" has no value

It seems that helm's --setknow comma ,and check the next string as a key. So can't use in this case when set such string?

看来helm--set知识逗号,,并检查下一个字符串作为重点。那么在设置这样的字符串时不能在这种情况下使用吗?



Tested this way

这样测试

helm install charts/mychart \
    --set aws.subnets={subnet-123456,subnet-654321}

Got error:

有错误:

Error: This command needs 1 argument: chart name

This way works

这种方式有效

helm install charts/mychart \
    --set aws.subnets="subnet-123456\,subnet-654321"

Reference

参考

https://github.com/kubernetes/helm/blob/master/docs/using_helm.md#the-format-and-limitations-of---set

https://github.com/kubernetes/helm/blob/master/docs/using_helm.md#the-format-and-limitations-of---set

回答by Javier Salmeron

According to https://github.com/kubernetes/helm/issues/1987#issuecomment-280497496, you set multiple values using curly braces, for example:

根据https://github.com/kubernetes/helm/issues/1987#issuecomment-280497496,您可以使用花括号设置多个值,例如:

--set foo={a,b,c}

So, in your case it would be like this

所以,在你的情况下,它会是这样的

--set aws.subnets={subnet-123456,subnet-654321}

回答by Marc

The CLI format and limitations can vary depending on what would be expected in a YAML version. For example, if the YAML manifest requires fieldsto be populated with a list of values the YAML would look like this:

CLI 格式和限制可能会有所不同,具体取决于 YAML 版本中的预期内容。例如,如果 YAML 清单需要fields填充一个值列表,YAML 将如下所示:

field:
  - value1
  - value2
  - value3 

This would be expressed in the helm CLI like so

这将在 helm CLI 中这样表达

--set field[0]=value1 --set field[1]=value2 --set field[2]=value3

The documentation also refers to --set field={value1,value2,value3}working. In some cases that results in Error: This command needs 1 argument: chart namewhich is why I provide the above suggestion

该文档还涉及--set field={value1,value2,value3}工作。在某些情况下,Error: This command needs 1 argument: chart name这就是我提供上述建议的原因

There are also limitations to what characters may be used per the documentation:

对于每个文档可以使用的字符也有限制:

You can use a backslash to escape the characters; --set name="value1\,value2"will become:

name: "value1,value2"

您可以使用反斜杠来转义字符;--set name="value1\,value2"会变成:

name: "value1,value2"

回答by Amit Yadav

With thischange being merged, Helmnow supports using multiple --setcommand with helm installcommand.

随着这种变化被合并,头盔现在支持使用多个--set带有命令helm install的命令。

Taking from the link mentioned above:

从上面提到的链接中获取:

Manually tested, and looks awesome!

手动测试,看起来棒极了!

?  helm install --dry-run --debug docs/examples/alpine \
  --set foo=bar \
  --set bar=baz,baz=lurman \
  --set foo=banana

SERVER: "local4host:44134"
CHART PATH: /Users/mattbutcher/Code/Go/src/k8s.io/helm/docs/examples/alpine
NAME:   masked-monkey
REVISION: 1
RELEASED: Thu Jan 12 17:09:07 2017
CHART: alpine-0.1.0
USER-SUPPLIED VALUES:
bar: baz
baz: lurman
foo: banana

COMPUTED VALUES:
Name: my-alpine
bar: baz
baz: lurman
foo: banana
...

As expected, the last --set overrode the first --set.

正如预期的那样,最后一个 --set 覆盖了第一个 --set。

P.S: Upgrade your Helm version in case this doesn't work for you. It worked perfectly for me with Helm-v3.0.1.

PS:如果这对您不起作用,请升级您的 Helm 版本。它对我来说非常适合Helm-v3.0.1

回答by acca

Regarding this comment How to set multiple values with helm?I used quotes and this worked:

关于此评论How to set multiple values with helm? 我使用了引号,这有效:

--set aws.subnets="{subnet-123456,subnet-654321}"