如何将动态参数传递给运行作业的头盔图 [英] How to pass dynamic arguments to a helm chart that runs a job

查看:75
本文介绍了如何将动态参数传递给运行作业的头盔图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许我们的开发人员将动态参数传递给头盔模板(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"

是否有任何方法可以在舵图中对参数进行模板化,使得可以将任意数量的参数传递给模板.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆