Using Post-Renderers

1. Understanding Post-Renderers

ConceptDetail
WhatExternal binary that receives rendered YAML on stdin, returns modified YAML on stdout
WhenAfter Helm renders, before resources sent to Kubernetes API
WhyApply cluster-specific patches without forking the chart

2. Configuring Post-Renderer Command

FlagUse
--post-renderer ./kustomize.shPath to executable
--post-renderer-args arg1 --post-renderer-args arg2Pass arguments

3. Using Kustomize as Post-Renderer

Example: kustomize.sh wrapper

#!/usr/bin/env bash
set -euo pipefail
cat </dev/stdin > base/all.yaml
kustomize build .
LayoutFiles
Working dirkustomization.yaml + patches/ + kustomize.sh
kustomization.yamlLists base/all.yaml + patches

4. Applying Custom Patches

Example: Strategic-merge patch via Kustomize

# kustomization.yaml
resources: [base/all.yaml]
patches:
  - path: patches/add-sidecar.yaml
    target: { kind: Deployment, name: api }

5. Adding Labels and Annotations

Example: Cluster-wide labels

# kustomization.yaml
resources: [base/all.yaml]
commonLabels:
  cluster: us-east-1
commonAnnotations:
  managed-by: gitops

6. Modifying Generated Resources

Use caseTool
Inject sidecarsKustomize patch / yq
Set image registryKustomize images: transformer
Strip fieldsyq del()
Add namespaceKustomize namespace:

7. Chaining Multiple Post-Renderers

PatternImplementation
Single wrapperShell script pipes through multiple tools
Examplecat | yq '...' | kustomize build .

8. Debugging Post-Renderer Output

Example: Capture intermediate output

helm template api ./chart \
  --post-renderer ./kustomize.sh \
  --debug > final.yaml
diff <(helm template api ./chart) final.yaml

9. Handling Post-Renderer Errors

BehaviorDetail
Non-zero exitHelm aborts; stderr surfaced to user
Invalid YAMLHelm rejects before sending to API
DebugRun wrapper standalone with sample input

10. Integrating Post-Renderers in CI/CD

Example: Pipeline step

helm upgrade --install api ./chart \
  -f values-prod.yaml \
  --post-renderer ./overlays/$ENV/kustomize.sh \
  --atomic --timeout 10m