如何将动态参数传递给运行作业的舵图 [英] How to pass dynamic arguments to a helm chart that runs a job
问题描述
我想允许我们的开发人员将动态参数传递给 helm 模板(Kubernetes 作业).目前我在 helm 模板中的参数有点静态(除了某些值),看起来像这样
I'd like to allow our developers to pass dynamic arguments to a helm template (Kubernetes job). Currently my arguments in the helm template are somewhat static (apart from certain values) and look like this
Args:
--arg1
value1
--arg2
value2
--sql-cmd
select * from db
如果我在没有 Kubernetes 的情况下使用 docker 容器运行任务,我会像这样传递参数:
If I were run a task using the docker container without Kubernetes, I would pass parameters like so:
docker run my-image --arg1 value1 --arg2 value2 --sql-cmd "select * from db"
有什么方法可以将 helm chart 中的参数模板化,这样可以将任意数量的参数传递给模板.
Is there any way to templatize arguments in a helm chart in such way that any number of arguments could be passed to a template.
例如.
cat values.yaml
...
arguments: --arg1 value1 --arg2 value2 --sql-cmd "select * from db"
...
或
cat values.yaml
...
arguments: --arg3 value3
...
我尝试了几种方法,但都没有成功.这是一个例子:
I've tried a few approaches but was not successful. Here is one example:
Args:
{{ range .Values.arguments }}
{{ . }}
{{ end }}
推荐答案
是的.在 values.yaml
中,你需要给它一个数组而不是一个空格分隔的字符串.
Yes. In values.yaml
you need to give it an array instead of a space delimited string.
cat values.yaml
...
arguments: ['--arg3', 'value3', '--arg2', 'value2']
...
或
cat values.yaml
...
arguments:
- --arg3
- value3
- --arg2
- value2
...
然后你像你在模板中提到的那样应该这样做:
and then you like you mentioned in the template should do it:
args:
{{ range .Values.arguments }}
- {{ . }}
{{ end }}
如果你想覆盖命令行上的参数,你可以像这样传递一个带有 --set
的数组:
If you want to override the arguments on the command line you can pass an array with --set
like this:
--set arguments={--arg1, value1, --arg2, value2, --arg3, value3, ....}
这篇关于如何将动态参数传递给运行作业的舵图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!