If you use Kubernetes a lot, you should be familiar with Helm and Kustomize. Both tools are used to manage Kubernetes resource lists, but they work in different ways.
Helm uses templates, a Helm Chart package that contains a number of templates and value files, and when rendered the variables in the templates are replaced with the corresponding values in the value files. Kustomize uses a template-free approach, which patches and merges YAML files, and Kustomize is also built natively into kubectl. Both tools are widely used in the Kubernetes ecosystem, and they can be used together.
To fork or not to fork
We know that many projects actually provide Helm Chart packages for applications, and that the values of template variables are controlled via value files. A long-standing question is how we should customize the upstream Helm Chart package, for example by adding or a list of Kubernetes resources from the Helm Chart package, and if it’s a generic change, the best option is of course to contribute directly to the upstream repository, but what about a custom change?
Usually we can fork the upstream Helm Chart repository ourselves and then make additional changes to the Chart package in our own repo. But doing so, obviously, creates an extra burden, especially if the Chart package only needs a small change.
In this case, we can use Kustomize to customize the existing Helm Chart without performing a fork operation.
The Helm version used in this article is 3.3.1 and Kustomize 3.8.2.
Customize with Chart Plugin
Kustomize provides a nice ecosystem of plugins that allow to extend the functionality of Kustomize. Among them is a non-built-in plugin called ChartInflator, a non-built-in plugin that allows Kustomize to render Helm Charts and perform any changes needed.
Start by installing the
For example, if we want to customize the Vault Helm Chart package, next create the ChartInflator resource list and the Helm values.yaml values file.
Now it’s time to render the Chart template by executing the command shown below.
After normal rendering we can see that an
env: dev tag has been added to all resources, this is done in real time and does not require any additional files to be maintained.
Customize with a single Chart file
Another way to customize the Chart using Kustomize is to use the
helm template command to generate a single list of resources, this way you have more control over the Chart, but it requires more work to come out and handle updating the version control of that generated file.
Often we can use Make to assist in this process, as shown in the following example.
To customize the upstream Vault Helm Chart, we can do the following.
Finally, the same
kustomize build command is used to render.
You can also see in the rendered result that all the resources have an
env: dev tag added to them.
With this approach, you need to somehow run the make command to generate the updated all-in-one resource manifest file, and it can be a bit tricky to integrate the update process with your GitOps workflow.
Customization with Helm post rendering
Post Rendering is one of the new features brought by Helm 3. In the previous 2 methods, Kustomize was the main tool used to handle generating the list of charts, but in this case Kustomize is working as Helm’s helper.
Let’s see how to use this method for Kustomize.
We can then either render directly using Helm or install Chart.
Normally we can also see that an env:dev tag is added to each resource file that is rendered at the end.
The rest is basically the same as the first approach, except that instead of using the Kustomize plugin, we use Helm’s own functionality to render the upstream Chart package directly.
We can see that each of the above methods has its own advantages and disadvantages, and which one to use depends mainly on our own working environment and workflow, but at least we have seen the efficiency of using Kustomize in combination with Helm.