Skip to content

Helm patch with Kustomize

Helm charts often miss required fields, leading to frequent forking to add necessary elements. This example shows how to patch a Helm chart without forking, using the external tool kustomize.

Suppose we have the chart hello. (It was created by $ helm create hello). The deployment doesn't have priorityClassName in this chart.

For example, we'll add priorityClassName: high for the deployment.

Describe your patch with Kustomize

kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - all.yaml
patches:
  - target:
      group: apps
      version: v1
      kind: Deployment
      name: world-hello
    patch: |
      - op: replace
        path: /spec/template/spec/priorityClassName
        value: high

Kustomize has official trick script for helm.

kustomize.sh
#!/bin/bash

cat <&0 > all.yaml

kustomize build . && rm all.yaml

Ask helmwave use kustomize

helmwave.yml
releases:
  - name: world
    chart: ./hello
    namespace: my-namespace
    post_renderer:
      - ./kustomize.sh

Result

helmwave build
cat .helmwave/manifest/world@my-namespace.yml| grep priorityClassName
      priorityClassName: high