【问题标题】:How can I pass imagePullSecrets, as it is defined in the default template, to helm via set commands如何通过 set 命令将默认模板中定义的 imagePullSecrets 传递给 helm
【发布时间】:2021-09-04 21:32:10
【问题描述】:

当您运行 helm create mychart 时,它的 imagePullSecrets 定义如下:

spec:
  {{- with .Values.imagePullSecrets }}
  imagePullSecrets:
    {{- toYaml . | nindent 8 }}
  {{- end }

在默认值文件中,它看起来像是在传递一个空白数组:

imagePullSecrets: []

我已经有一堆使用此设置的默认模板构建的图表。以前我不需要使用 imagePullSecrets,所以我只是保持原样,但现在我有一些情况,我想在部署时通过 cli 设置它。

Helm 现在支持数组,但这似乎不起作用:

--set "mychart.imagePullSecrets[0].name={reg-creds}"

返回:

Error: UPGRADE FAILED: error validating "": error validating data: ValidationError(Deployment.spec.template.spec.imagePullSecrets[0].name): invalid type for io.k8s.api.core.v1.LocalObjectReference.name: got "array", expected "string"

然后我尝试传递一个字符串:

--set "mychart.imagePullSecrets='- name: reg-creds'"

Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(Deployment.spec.template.spec.imagePullSecrets): invalid type for io.k8s.api.core.v1.PodSpec.imagePullSecrets: got "string", expected "array"

这些错误信息令人愤怒。是否可以使用--set 设置此值,这样我就可以避免重构我的所有图表?

【问题讨论】:

    标签: kubernetes-helm helm3


    【解决方案1】:

    helm install --set syntax 独特而复杂。一个不寻常的语法是花括号中的值{foo,bar} 将值设置为数组。那么,在您的示例中,--set object.path={value} 将值设置为单元素数组;你看到的错误是它需要是一个字符串。

    这意味着这里有一个简单的解决方法是删除--set 右侧的花括号。还有一个--set-string 选项强制将值解释为字符串,即使它包含花括号或逗号。

    helm install ... --set "mychart.imagePullSecrets[0].name=reg-creds"
    #                       no curly braces around the value ^^^^^^^^^
    

    使用 YAML 文件来提供此值可能更清晰,语法也更标准。

    # image-pull-secrets.yaml
    imagePullSecrets:
      - name: reg-creds
    

    您可以将其包含在每个环境的值文件中,或将其作为独立的值文件传递。无论哪种情况,您都可以使用helm install -f 选项来提供文件。有多个 helm install -f 值文件很好。

    helm install ... -f image-pull-secrets.yaml
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      • 2013-01-03
      • 2021-12-16
      • 2018-03-03
      • 2021-09-11
      • 2020-10-16
      相关资源
      最近更新 更多