How to set multiple values with helm?
Asked Answered
G

5

38

Use helm install can set value when install a chart like:

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 --set know comma , and check the next string as a key. So can't use in this case when set such string?


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://helm.sh/docs/intro/using_helm/#the-format-and-limitations-of---set

Glioma answered 18/1, 2018 at 7:57 Comment(1)
Reference link is now 404Flyspeck
F
21

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

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

So, in your case it would be like this

--set aws.subnets={subnet-123456,subnet-654321}
Forewent answered 18/1, 2018 at 8:42 Comment(1)
Thank you for your answer. That doesn't work for me. I posted the result to the question. And also added the right way.Glioma
L
16

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

field:
  - value1
  - value2
  - value3 

This would be expressed in the helm CLI like so

--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 name which is why I provide the above suggestion

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"
Luxurious answered 12/4, 2019 at 15:6 Comment(3)
Unfortunately this does not work for me in helm 2.13.1: helm install deploy/traefik/chart --set externalIps[0]="a" --set externalIps[1]="b" --debug --dry-run gives back zsh: no matches found: externalIps[0]=aJoung
What about if your list items aren't a single value but a set of values, e.g. an ingress' paths list has a path, and a backend with a serviceName and servicePort. How can I do this and pass a full table of key-values, or just set one value and keep the rest?Thumping
@DavidFernandez You have to escape the square brackets to prevent your shell (zsh in your case) from interpreting them: helm install deploy/traefik/chart --set 'externalIps[0]="a"' --set 'externalIps[1]="b"' --debug --dry-runStclair
V
10

With this change being merged, Helm now supports using multiple --set command with helm install command.

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: "localhost: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.

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

Voyeurism answered 16/12, 2019 at 7:36 Comment(0)
G
4

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

--set aws.subnets="{subnet-123456,subnet-654321}"
Ganesa answered 18/9, 2019 at 11:31 Comment(1)
This does not work for me, I am getting a strange spec: [a b c] when I do helm install deploy/traefik/chart --set externalIps="{a,b,c}" --debug --dry-runJoung
Z
1

As previously mentioned, if you're trying to set a list you can use:

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

be careful not to put any space between items. And check the type you're trying to set and make sure you're using the correct format.

You can also use:

--set-json='aws.subnets=["subnet-123456", "subnet-654321"]'

More information and examples can be found here: https://helm.sh/docs/helm/helm_install/#options

Zoarah answered 7/11, 2023 at 21:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.