1. Values 对象

Values对象: 从 values.yaml 文件和用户提供的文件传入模板的值。默认情况下,Values 是空的。

在 values.yaml 中定义好变量后,就可以在模板中引用该配置项

$ cat mychart/templates/configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: myapp-configmap
data:
  myvalue: "Hello World"
  drink: {{ .Values.favorite.drink  }}
  food: {{ .Values.favorite.food  }}

渲染后的结果

# Source: mychart/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: myapp-configmap
data:
  drink: "coffee"
  food: "pizza"

1.1.1. .Values 对象 接受命令行传入的参数

helm 在安装和升级时,还可以通过命令行参数的传入或修改 values.yaml 中的值。

在安装和升级时可以支持传入多种数据类型

--set stringArray              set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)

--set-file stringArray         set values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2)

--set-string stringArray       set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)

对于 .Values 对象 识别 values.yaml 和命令行传入参数的方法是一样的。

可以指定 --set 参数多次,最右边的参数优先级最高,比如,bar 和 newbar 都设置了一个名为 foo 的可以,newbar 的值优先:

$ helm install --set foo=bar --set foo=newbar  myredis ./mychart

详细参见:

Copyright © 温玉 2021 | 浙ICP备2020032454号 all right reserved,powered by Gitbook该文件修订时间: 2022-03-27 08:08:50

results matching ""

    No results matching ""