在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:
{{ .Values.command.cmd }}
{{- end }}
{{- if or $.Values.env $.Values.envSecrets }}
我尝试添加:
{{- if $.Values.command }}
command:
{{ .Values.command.cmd }}
{{- end }}
然后我尝试传递命令:
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'
但没有任何作用。
如何通过--set pass?
command:
- /bin/sh
- -c
- |
while true; do
sleep 60;
done
谢谢你。
Helm 不支持设置不存在的数组元素,可以通过传递整个数组来赋值或者先设置相应数量的元素,然后通过 --set cmd[i]=xxx 修改。
首先,在deployment.yaml文件中,
Values.command.cmd
字段不应该直接引用,因为数组需要通过以下方式引用:{{ toYaml … }}
部署.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 }}
那么如果使用values.yaml文件方法传入参数的话,这里应该这样写:
values.yaml
command:
cmd:
- /bin/sh
- -c
- while true; do sleep 60; done
最后,如果你想通过
--set
设置,你需要传递数组值,你可以使用大括号(unix shell需要引号):
--set command.cmd={"/bin/sh"\,"-c"\,"while true; do sleep 60; done"}
注意!!!
数组元素的分隔符
,
一定要记得加上\