In deployment.yaml in:
containers:
- name: {{ .Values.stand }}-container
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
{{- if $.Values.command }}
command:
{{ .Values.command.cmd }}
{{- end }}
{{- if or $.Values.env $.Values.envSecrets }}
I tried adding:
{{- if $.Values.command }}
command:
{{ .Values.command.cmd }}
{{- end }}
Then I tried to pass the command:
helm install NAME nexus/stand
--set 'command.cmd[0]=- /bin/sh' \
--set 'command.cmd[1]=- -с' \
--set 'command.cmd[2]=- |' \
--set 'command.cmd[3]=while true; do' \
--set 'command.cmd[4]=sleep 60;' \
--set 'command.cmd[5]=done'
but nothing works.
How to via --set pass?
command:
- /bin/sh
- -c
- |
while true; do
sleep 60;
done
Thank you.
CodePudding user response:
Helm does not support setting non-existent array elements, you can assign values by passing the entire array or set the corresponding number of elements first, and then modify it by --set cmd[i]=xxx.
First of all, in the deployment.yaml file, the Values.command.cmd
field should not be quoted directly, as an array needs to be quoted in the following way: {{ toYaml … }}
deployment.yaml
containers:
- name: {{ .Values.stand }}-container
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
{{- if $.Values.command }}
command:
{{ toYaml .Values.command.cmd | nindent 12 }}
{{- end }}
{{- if or $.Values.env $.Values.envSecrets }}
Then if you use the values.yaml file method to pass in the parameters, you should write like this here:
values.yaml
command:
cmd:
- /bin/sh
- -c
- while true; dp sleep 60; done
Finally, if you want to set by --set
, you need to pass array values you can use curly braces (unix shell require quotes):
--set test={"/bin/sh"\,"-c"\,"while true; do sleep 60; done"}
Notice!!!
The separator of the array elements ,
you must remember to add a \