覆盖头盔中的配置映射文件

时间:2018-06-29 03:06:22

标签: kubernetes kubernetes-helm

我们有头盔图来部署我们的应用程序。我们将ActionController::Parameters文件用于应用程序属性,并将其加载到配置映射。但是用户通常使用自己的配置文件。

默认configuration.json文件打包在数据直接性下的掌舵图中。该文件读取为

configuration.json

以及值

apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
{{ (.Files.Glob .Values.appConfigFile).AsConfig | indent 4}}

如果用户直接从资源库安装我们的图表,那么如何覆盖此配置文件? appConfigFile: data/configuration.json 不会填充配置映射。

如果将图表解压缩到目录中,则可以将自定义配置文件添加到图表目录中,并使用--set appConfigFile=/path/to/custom.json的作品提供配置文件

直接从存储库中部署图表时,是否可以实现文件替代?

1 个答案:

答案 0 :(得分:5)

将自定义配置添加到值文件并使用helm install标志执行-f是解决方案。

customValues.yaml

overrideConfig: true
customConfig:{
//Add your custom json here as variable value
}

配置映射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 }}

如果需要自定义配置

helm install -f customValues.yaml repo/chartName

不确定这是否是完美的解决方案,但最终还是走了这条路。

相关问题