TExcelTAD
Home › Kubernetes Packaging: Helm & Kustomize › Helm Rendered Through Kustomize

Helm Rendered Through Kustomize

Sooner or later a chart you install doesn't expose the field you need: a toleration, a topology spread constraint, an extra label your policy engine demands. Forking the chart means maintaining a copy forever. The alternative is to treat the chart's output as just another input and patch it with Kustomize. There are three ways to wire that up.

Approach How Notes
helmCharts in a kustomization Kustomize runs helm template for you (kustomize build --enable-helm) one command; Argo CD supports it with a flag; Helm releases and hooks are gone
render, commit, patch CI runs helm template … > rendered.yaml; the kustomization lists the file the "rendered manifests" pattern: reviewers see exact YAML diffs
post-renderer helm install --post-renderer <plugin> pipes the output through Kustomize keeps Helm releases, hooks and rollback (Helm 4: plugins only)

helmCharts with a local chart

Without a repo, Kustomize looks for the chart in chartHome (default charts/) next to the kustomization. The overlay renders linkly's chart with inline values, then adds a topology spread constraint the chart doesn't support:

bash · try it yourself
mkdir -p prod/charts/linkly/templates && cd prod
printf 'apiVersion: v2\nname: linkly\nversion: 1.0.0\nappVersion: "1.4.0"\n' > charts/linkly/Chart.yaml
printf 'replicaCount: 2\n' > charts/linkly/values.yaml
cat > charts/linkly/templates/deployment.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-linkly
spec:
  replicas: {{ .Values.replicaCount }}
  selector: {matchLabels: {app.kubernetes.io/instance: {{ .Release.Name }}}}
  template:
    metadata: {labels: {app.kubernetes.io/instance: {{ .Release.Name }}}}
    spec:
      containers:
        - name: linkly
          image: ghcr.io/acme/linkly:{{ .Chart.AppVersion }}
EOF
mkdir -p charts/linkly/templates/tests
cat > charts/linkly/templates/tests/smoke.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata:
  name: {{ .Release.Name }}-smoke
  annotations: {helm.sh/hook: test}
spec:
  restartPolicy: Never
  containers: [{name: curl, image: curlimages/curl:8.17.0, args: ["http://{{ .Release.Name }}-linkly/readyz"]}]
EOF
cat > kustomization.yaml <<'EOF'
namespace: linkly-prod
helmCharts:
  - name: linkly
    releaseName: web
    namespace: linkly-prod
    valuesInline:
      replicaCount: 4
patches:
  - target: {kind: Deployment, name: web-linkly}
    patch: |-
      - op: add
        path: /spec/template/spec/topologySpreadConstraints
        value:
          - maxSkew: 1
            topologyKey: topology.kubernetes.io/zone
            whenUnsatisfiable: ScheduleAnyway
            labelSelector: {matchLabels: {app.kubernetes.io/instance: web}}
EOF
kustomize build . 2>&1 | tail -1
echo "--- with --enable-helm:"
kustomize build --enable-helm . | yq -N '.kind + "/" + .metadata.name'
kustomize build --enable-helm . | yq 'select(.kind == "Deployment") | (.spec.replicas, .spec.template.spec.topologySpreadConstraints[0].topologyKey)'
`: must specify --enable-helm
--- with --enable-helm:
Deployment/web-linkly
Pod/web-smoke
4
topology.kubernetes.io/zone

Observations:

  • Without --enable-helm Kustomize refuses (must specify --enable-helm): running an external program is opt-in. kubectl kustomize --enable-helm works the same way; kubectl apply -k has no such flag.
  • The chart's test Pod came out as an ordinary object. Kustomize runs helm template, which includes hooks and tests, and the result has no release to attach them to. Hooks would be applied at the same time as everything else. Set skipTests: true (and skipHooks: true if the chart's hooks are useless without Helm) on the helmCharts entry. (One more quirk: Kustomize expects the chart to have a values.yaml, even an empty one.)
bash · try it yourself
mkdir -p prod/charts/linkly/templates/tests && cd prod
printf 'apiVersion: v2\nname: linkly\nversion: 1.0.0\n' > charts/linkly/Chart.yaml
echo '{}' > charts/linkly/values.yaml
printf 'apiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: {{ .Release.Name }}-config\n' > charts/linkly/templates/cm.yaml
printf 'apiVersion: v1\nkind: Pod\nmetadata:\n  name: {{ .Release.Name }}-smoke\n  annotations: {helm.sh/hook: test}\nspec:\n  containers: [{name: c, image: busybox:1.37}]\n' > charts/linkly/templates/tests/smoke.yaml
printf 'helmCharts:\n  - name: linkly\n    releaseName: web\n    skipTests: true\n' > kustomization.yaml
kustomize build --enable-helm . | yq -N '.kind + "/" + .metadata.name'
ConfigMap/web-config

helmCharts with a registry chart

With repo and version, Kustomize pulls the chart itself into charts/<name>-<version>/ (a cache it reuses on the next build). It can't pass --plain-http, so for this course's local HTTP-only registry the session pulls the chart into that folder first, which is also how you vendor a chart for offline or reproducible builds:

bash · try it yourself
mkdir -p src/linkly/templates
printf 'apiVersion: v2\nname: linkly\nversion: 1.0.0\n' > src/linkly/Chart.yaml
printf 'replicaCount: 2\nlogLevel: info\n' > src/linkly/values.yaml
cat > src/linkly/templates/configmap.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-config
data:
  LOG_LEVEL: {{ .Values.logLevel | quote }}
  REPLICAS: {{ .Values.replicaCount | quote }}
EOF
helm package src/linkly -d src >/dev/null
helm push src/linkly-1.0.0.tgz oci://localhost:5000/charts --plain-http >/dev/null 2>&1
mkdir staging && cd staging
printf 'logLevel: debug\n' > values-staging.yaml
cat > kustomization.yaml <<'EOF'
helmCharts:
  - name: linkly
    repo: oci://localhost:5000/charts
    version: 1.0.0
    releaseName: web
    valuesFile: values-staging.yaml
    valuesInline: {replicaCount: 1}
EOF
helm pull oci://localhost:5000/charts/linkly --version 1.0.0 --plain-http --untar --untardir charts/linkly-1.0.0 >/dev/null 2>&1
find charts -name Chart.yaml
kustomize build --enable-helm . | yq '.data'
charts/linkly-1.0.0/linkly/Chart.yaml
LOG_LEVEL: debug
REPLICAS: "1"

valuesFile replaces the chart's defaults file, valuesInline is merged on top (valuesMerge: override|merge|replace controls how), and additionalValuesFiles adds more -f files. Against a real HTTPS registry the pre-pull is unnecessary:

yaml
helmCharts:
  - name: linkly
    repo: oci://ghcr.io/acme/charts
    version: 1.0.0
    releaseName: web

Choosing between the three

  • Plain Helm (no Kustomize) when the chart exposes everything you need: least moving parts, and you keep hooks, tests and rollback.
  • Post-renderer when you need a patch and Helm's release features (hooks for migrations, helm rollback).
  • helmCharts when a GitOps tool applies plain manifests anyway and Helm releases add nothing, as with many third-party add-ons.
  • Rendered manifests in Git when reviewers must see the exact objects that will change; CI re-renders and fails if the committed output is stale.

Test yourself

What does kustomize build print for a kustomization with helmCharts but without --enable-helm?

  1. The chart's output
  2. An error: Helm support must be enabled explicitly
  3. Only the patches
  4. An empty list

What happens to a chart's test Pod rendered through helmCharts?

  1. It runs after install, as with Helm
  2. It becomes an ordinary object in the output unless skipTests is set
  3. Kustomize deletes it
  4. It is converted into a Job

You need to patch a chart and still use a pre-upgrade migration hook. Which approach?

  1. helmCharts
  2. A Helm post-renderer
  3. Rendered manifests in Git
  4. kubectl patch after install