Dhe*_*shi 7 kubernetes kubernetes-helm
我们有头盔图来部署我们的应用程序.我们将configuration.json文件用于应用程序属性并将其加载到配置映射.但用户通常使用自己的配置文件.
默认的configuration.json文件打包在数据直接下的helm图表中.该文件读作
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
{{ (.Files.Glob .Values.appConfigFile).AsConfig | indent 4}}
Run Code Online (Sandbox Code Playgroud)
在价值观
appConfigFile: data/configuration.json
Run Code Online (Sandbox Code Playgroud)
如果用户直接从存储库安装我们的图表,该配置文件如何被覆盖?做--set appConfigFile=/path/to/custom.jsondoen't填入配置图.
如果图表未对目录进行解压缩,则可以将自定义配置文件添加到图表目录中,并使用--set appConfigFile=customData/custom.json作品提供配置文件
从存储库直接部署图表时,是否可以实现文件覆盖?
解决方案是将自定义配置添加到值文件并helm install使用-fflag 执行。
customValues.yaml
overrideConfig: true
customConfig:{
//Add your custom json here as variable value
}
Run Code Online (Sandbox Code Playgroud)
配置映射Yaml
#If custom values file passed then overrideConfig variable will be set.
#So load configmap from customConfig variable
{{ if .Values.overrideConfig}}
app-config.json : |-
{{ toJson .Values.customConfig }}
{{ else }}
# Else load from the default configuration available in charts.
{{ (.Files.Glob .Values.appConfigFile).AsConfig indent 4 }}
{{ end }}
Run Code Online (Sandbox Code Playgroud)
如果需要自定义配置
helm install -f customValues.yaml repo/chartName
Run Code Online (Sandbox Code Playgroud)
不知道这是否是完美的解决方案,但最终还是走了这条路。
| 归档时间: |
|
| 查看次数: |
3562 次 |
| 最近记录: |