We have helm charts to deploy our application. We use a configuration.json
file for application properties and load them to config map. But users typically use their own configuration file.
Default configuration.json file is packaged inside helm charts under data directoty. This file is read as
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
{{ (.Files.Glob .Values.appConfigFile).AsConfig | indent 4}}
And in values
appConfigFile: data/configuration.json
If users install our charts directly from repository how can this configuration file be overriden? doing --set appConfigFile=/path/to/custom.json
doen't populate config map.
If charts are untarred to a directory they can add the custom configuration file into charts directory and give the configuration file using --set appConfigFile=customData/custom.json
works
Can file overrides be achieved when charts are deployed from repository directly?
You can use a --values flag in your Helm commands to override the values in a chart and pass in a new file. Specify the name of the new file after the --values flag in the Helm command. Example: helm upgrade --install <service> -f values.
tpl? Helm allows for the use of Go templating in resource files for Kubernetes. A file named _helpers.tpl is usually used to define Go template helpers with this syntax: {{- define "yourFnName" -}} {{- printf "%s-%s" .Values.name .Values.version | trunc 63 -}} {{- end -}}
Sometimes, though, Helm users want to make sure that the pods are restarted. That's where the --force flag comes in. Instead of modifying the Deployment (or similar object), it will delete and re-create it. This forces Kubernetes to delete the old pods and create new ones.
Adding custom configuration to a values file and execute helm install
using -f
flag is a solution.
customValues.yaml
overrideConfig: true
customConfig:{
//Add your custom json here as variable value
}
Config map 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 }}
If custom configuration is needed
helm install -f customValues.yaml repo/chartName
Not sure if this is the perfect solution, but ended up taking this route.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With