Kustomize: Render a helm chart (to patch it!)

kustomize helm render

2 min read | by Jordi Prats

The topic is hot: Kustomize or Helm? While this discussion around this topic could continue indefinitely, the good news is that both tools can be utilized in conjunction, enhancing each other's capabilities.

Helm is widely used to distribute software, it is even becoming rare to find a project that does not offer a helm chart. Let's take as an example the following instructions to install prometheus using the prometheus operator:

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prom-operator prometheus-community/kube-prometheus-stack

If we want to change something in the resulting manifest that it is not exposed through the values, our only option (with Helm) would be to fork the helm chart. On the other hand, Kustomize is better suited when we want to be able to patch manifests. By using both Helm and Kustomize together, you get more flexibility in customizing your deployments.

First we'll have to create a kustomization.yaml that will render the helm chart with some values:

helmCharts:
- name: kube-prometheus-stack
  repo: https://prometheus-community.github.io/helm-charts
  version: 43.2.1
  releaseName: prom-operator
  namespace: default
  valuesInline:
    commonLabels:
      sample: "values"

To be able to render it, we'll have to add the --enable-helm flag to kustomize build as follows:

$ kustomize build prometheus-install/ --enable-helm
(...)

It is going to download the helm chart and it's dependencies to be able to render it:

$ find prometheus-install -type d
prometheus-install/
prometheus-install/charts
prometheus-install/charts/kube-prometheus-stack
(...)
prometheus-install/charts/kube-prometheus-stack/charts/kube-state-metrics
(...)
prometheus-install/charts/kube-prometheus-stack/charts/prometheus-node-exporter
(...)
prometheus-install/charts/kube-prometheus-stack/charts/grafana
(...)

Once with this kustomization.yaml we are able to get the manifests for that installation, we can patch it with patchesStrategicMerge as usual.


Posted on 12/01/2023

Categories