【问题标题】:Helm - how can I use custom values file in subchart, when installing parent chartHelm - 安装父图表时如何在子图表中使用自定义值文件
【发布时间】:2021-06-12 23:15:18
【问题描述】:

问题

假设我有一个图表 example 和一个子图表 example-subvalues.extra.yamlexample-sub 的自定义值。

文件结构:

example
 |-.helmignore
 |-templates
 | |-deployment.yaml
 |-charts
 | |-example-sub
 | | |-values.extra.yaml
 | | |-.helmignore
 | | |-templates
 | | | |-deployment.yaml
 | | |-charts
 | | |-values.yaml
 | | |-Chart.yaml
 |-values.yaml
 |-Chart.yaml

那么在安装父图表example时不能使用values.extra.yaml

重新创建问题:

example/charts/example-sub/templates/deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ $.Values.name }}
  custom: {{ $.Values.custom }}
  

example/charts/example-sub/values.extra.yaml:

custom: my-custom

安装图表时,custom 值缺失:

$ helm template --debug example . -f charts/example-sub/values.extra.yaml 
install.go:173: [debug] Original chart version: ""

---
# Source: example/charts/example-sub/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-sub-deploy
  custom:
---
# Source: example/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-deploy

在安装子图表时,它可以工作:

helm template --debug example-sub charts/example-sub -f charts/example-sub/values.extra.yaml
install.go:173: [debug] Original chart version: ""

---
# Source: example-sub/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-sub-deploy
  custom: my-custom

问题

如何使用自定义值文件`values.extra.yaml'安装图表example,包括其子图表example-sub

【问题讨论】:

    标签: kubernetes-helm


    【解决方案1】:

    正如official documentation of Helm 中提到的,您需要在父图表中创建一个与子图表完全命名的部分,并在内部提供自定义值。

    例如:

    example
    |- charts
    | |-example-sub
    

    ./example/values.yaml 下的值文件应该是:

    example-sub:
      custom: my-custom
    

    按照此示例,您还可以通过 CLI 使用 --set example-sub.custom=my-custom 设置值

    【讨论】:

    • 感谢@totem,我尝试了解决方案 - 它似乎打破了子图表独立的概念,因为helm template --debug example-sub charts/example-sub -f charts/example-sub/values.extra.yaml 无法加载值..
    • 实际上对我来说这种情况有效。 helm template ./charts/sub-sample -f ./charts/sub-sample/custom-values.yaml。也许还有另一个问题?您使用的是哪个版本的 helm?
    猜你喜欢
    • 2019-11-23
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 2019-08-15
    • 2020-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多