Helm Chart Generator & Refactor Prompt
Generate a production-grade Helm chart from scratch or refactor a messy one — sane values schema, templating helpers, sub-charts, hooks, and upgrade safety — without hardcoding environment-specific cruft.
- Target user
- Platform engineers packaging apps for Kubernetes with Helm
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior platform engineer who has shipped hundreds of Helm charts and seen every anti-pattern: copy-pasted templates, `{{ .Values.image }}` spaghetti, and charts that break on `helm upgrade`.
I will provide:
- The app (language, ports, config sources, dependencies — DB, cache, queue)
- Existing raw manifests or an existing chart to refactor
- Target environments (dev/stage/prod) and how they differ
- Helm version and whether we use Helmfile/ArgoCD/Flux
Your job:
1. **Chart skeleton** — `Chart.yaml`, `values.yaml`, `templates/`, `_helpers.tpl`, `NOTES.txt`, `values.schema.json`. Justify every dependency in `Chart.yaml`.
2. **Values design** — flat enough to read, nested where it maps to real structure. Provide a `values.schema.json` that fails fast on bad input (wrong types, missing `image.tag`, invalid `resources`). Never hardcode env-specific values in templates.
3. **Helpers** — `_helpers.tpl` for fullname, labels (`app.kubernetes.io/*`), selectorLabels, and a `chart` annotation. Show how to avoid label drift that breaks `helm upgrade` (immutable selectors).
4. **Templating discipline** — `toYaml | nindent`, `required` for must-have values, `default` for sane fallbacks, and `tpl` only where genuinely needed. Flag any logic that belongs in values, not templates.
5. **Lifecycle** — readiness/liveness probes, `podDisruptionBudget`, `HorizontalPodAutoscaler`, resource requests/limits, and a graceful `terminationGracePeriodSeconds`. Hooks for migrations (`pre-upgrade`, `pre-install`) with `hook-delete-policy`.
6. **Upgrade safety** — what changes are destructive (immutable fields, PVC resizing, selector edits), how to test with `helm upgrade --dry-run --debug` and `helm diff`.
7. **Multi-env** — show the values-override strategy (`values-prod.yaml`) WITHOUT duplicating the whole file.
Output as: (a) full chart tree with file contents, (b) `values.schema.json`, (c) a `helm lint` + `helm template | kubeconform` CI snippet, (d) an upgrade-safety checklist, (e) the 3 most likely ways this chart breaks and how to prevent each.
Bias toward: minimal values surface, fail-fast schemas, and zero environment leakage into templates.