Using Post-Renderers
1. Understanding Post-Renderers
| Concept | Detail |
|---|---|
| What | External binary that receives rendered YAML on stdin, returns modified YAML on stdout |
| When | After Helm renders, before resources sent to Kubernetes API |
| Why | Apply cluster-specific patches without forking the chart |
2. Configuring Post-Renderer Command
| Flag | Use |
|---|---|
--post-renderer ./kustomize.sh | Path to executable |
--post-renderer-args arg1 --post-renderer-args arg2 | Pass 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 .
| Layout | Files |
|---|---|
| Working dir | kustomization.yaml + patches/ + kustomize.sh |
| kustomization.yaml | Lists 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 case | Tool |
|---|---|
| Inject sidecars | Kustomize patch / yq |
| Set image registry | Kustomize images: transformer |
| Strip fields | yq del() |
| Add namespace | Kustomize namespace: |
7. Chaining Multiple Post-Renderers
| Pattern | Implementation |
|---|---|
| Single wrapper | Shell script pipes through multiple tools |
| Example | cat | 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
| Behavior | Detail |
|---|---|
| Non-zero exit | Helm aborts; stderr surfaced to user |
| Invalid YAML | Helm rejects before sending to API |
| Debug | Run wrapper standalone with sample input |