I'm looking for an elegant solution for handling different values of helm packages on the overlay level:
- We have a base folder and, overlay folders stg and prod corresponding to environments
- I would like to use a helm chart with a long list of values.
- Part of those values are the same for all environments - common values.
- Part of those values are different in each environment.
I want to have a value file with common values and a file with additional environment-specific values.
The goal here is to avoid copy-paste common values in each directory.
What I already tried:
- Have
common_config.yamlin/base/common_config.yamland in/stg/kustomize.yamlset inhelmChartsfieldvaluesFileto../base/common_config.yamlbut it will fail when--load-restrictoris enabled (which is the default). - Use
HelmChartInflationGeneratoron base kustomize and use patching on this resource to add custom value files - but this has the same issue as above. - I'm aware that I can render helm on the base image and then use patching to change things - the issue is that it requires changing many many fields and is not maintainable.
Perhaps there is a better way to handle such scenarios.
Given that you are using Kustomize's
helmChartsand you want to avoid duplication of common values across different environments, you might consider:kustomization.yaml, the common values file and the environment-specific values file. That will allow Kustomize to merge these values when generating the final configuration for the Helm chart.That is inspired from "Generate Kubernetes Manifests with Helm Charts using Kustomize" from Tharuka Mannapperuma.
Assuming a project structure similar to this:
You would have:
common_values.yaml, for the values that common across all environments.overlay kustomizations with:
stg/kustomization.yaml:prod/kustomization.yaml:Kustomize will use the values from
common_values.yamlas the base and merge them with the values specified instg_values.yamlorprod_values.yamlfor the respective environments. That is achieved through thevaluesFilefield in thehelmChartssection of the overlaykustomization.yaml. SeeHelmChartInflationGenerator.When using
kubectl kustomize, the--load-restrictorflag can prevent loading files from outside the kustomization root.Here, your project is structured in a way where the common values file is always within the kustomization root of each environment.
When you run
kubectl kustomize overlays/stgorkubectl kustomize overlays/prodfrom theprojectdirectory, theprojectdirectory becomes the root for the kustomization. As a result, referencing../../base/common_values.yamlfrom theoverlays/stg/kustomization.yamloroverlays/prod/kustomization.yamlis allowed because thebasedirectory is within the scope of the kustomization root (project).