Merging helm input values using kustomize
Helm is a popular package manager for Kubernetes applications.It bundles Kubernetes manifests for a given application to a set used for deployments. Furthermore, helm providesdependency management as well as a templating engine (go templates with sprig-functions).
Kustomize is a configuration management tool that is used to merge and patch Kubernetes manifests.
Using kustomize to merge helm input values
When combining helm and kustomize (e.g. to patch helm output manifests) it is a likely scenario that one has the need to reproduceHelms merge logic regarding multiple input files. This is useful to o e.g. separate basic settings from stage-dependent settings.A usual strategy with kustomize is to use bases and overlays.
To apply this to the values of a helm chart one has to use the file-based HelmChartInflationGenerator, it has the format of a k8s custom resource (but is not one):
apiVersion: builtin kind: HelmChartInflationGenerator metadata: name: just-for-kustomize-matching releaseName: helm-release-name name: chart-name version: chart-version repo: repo-url valuesInline: {}
This then has to be combined it with the transformed transformers pattern (also works for generators, "everything is a transformer").So the file structure would look like this:
base
|---helm
| |---values.yaml
| |---kustomization.yaml
dev
|---kustomization.yaml
|---helm
|---values.yaml
|---kustomization.yaml
The two values.yaml have to be in the form of the builtin/HelmChartInflationGenerator
described above. Now follows the content of the relevant yaml files:
# base/helm/kustomization.yaml # just include the raw base values yaml resources: - values.yaml # dev/helm/kustomization.yaml # merge the HelmChartInflationGenerator generator input using patch strategic merge bases: - ../../base/helm/kustomization.yaml patchStrategicMerge: - values.yaml # dev/kustomization.yaml # use output of the helm subfolder kustomize call as generator input generators: - helm