Helm lookup Function & Existing-Resource Templating Prompt
Use Helm's lookup function to read live cluster objects at render time (existing secrets, generated passwords, CA certs) so upgrades preserve state instead of regenerating it.
- Target user
- Chart authors handling generated secrets and idempotent installs
- Difficulty
- Advanced
- Tools
- Claude, Cursor
The prompt
You are a senior Helm chart author who has used the `lookup` function to stop charts from rotating a database password on every `helm upgrade` — and who knows lookup's sharp edges in CI and dry-run. I will provide: - The resource the chart auto-generates (password, JWT secret, self-signed cert) - The install/upgrade flow and whether CI runs `helm template`/`--dry-run` - Whether the value must survive upgrades unchanged Your job: 1. **Explain lookup** — `lookup "v1" "Secret" .Release.Namespace "name"` queries the live cluster during render and returns the object (or empty). Stress that it returns empty during `helm template` and `--dry-run`, so logic must tolerate that. 2. **Preserve-or-generate pattern** — write the canonical idiom: look up the existing Secret; if found, reuse its data; else `randAlphaNum`/`genCA` to generate. Show the `if`/`else` with base64 handling so upgrades don't rotate the value. 3. **Dry-run safety** — explain why `helm template` will show a *new* random value (lookup empty) and why that's expected, not a bug — never gate CI diffs on that field. 4. **RBAC requirement** — lookup needs the Tiller-less client's credentials to read the resource; note that a restricted CI identity may get empty results and silently regenerate. 5. **Idempotency proof** — install, capture the secret, `helm upgrade`, and confirm the value is unchanged via `kubectl get secret -o jsonpath`. 6. **Alternatives** — mention when a pre-install hook + a real secrets manager (External Secrets, Sealed Secrets) is the better answer than lookup. Output as: (a) the preserve-or-generate template, (b) the upgrade idempotency test commands, (c) the dry-run caveats, (d) the top 3 ways lookup unexpectedly rotates a secret. Never rely on lookup as your only protection against secret rotation — if the render runs without cluster read access, it regenerates; consider a managed-secret backend for anything critical.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Helm Named Template & _helpers.tpl Refactor Prompt
Refactor a sprawling Helm chart into reusable named templates in _helpers.tpl, eliminating duplicated label blocks, name truncation, and copy-pasted selectors across manifests.
-
Helm Chart.lock Dependency Drift Reconciliation Prompt
Resolve Chart.yaml vs Chart.lock dependency drift and 'found in Chart.yaml, but missing in charts/ directory' failures by reasoning about version ranges, the lock digest, and helm dependency build vs update.
-
Helm Release History Pruning and max-history Prompt
Stop Helm release history from bloating etcd with hundreds of Secret/ConfigMap revisions — set --history-max, prune safely, and avoid hitting the 1MB Secret size limit or slow upgrades.
-
Zero-Downtime Secret Rotation Runbook Prompt
Rotate a Kubernetes Secret (DB password, API key, TLS cert) without dropping traffic — reason about mounted-volume vs envFrom propagation, dual-key overlap windows, and forcing a controlled rollout only where needed.
More Kubernetes & Helm prompts & error guides
Browse every Kubernetes & Helm prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.