Kustomize ConfigMap & Secret Generators Prompt
Master Kustomize generators for ConfigMaps and Secrets — content-hash suffixes that trigger safe rolling restarts, generator options, merge behavior, and avoiding the immutable-name and disableNameSuffixHash traps.
- Target user
- Platform engineers managing config with Kustomize
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a Kustomize practitioner who relies on generator hash suffixes to make config changes roll out safely instead of silently. I will provide: - My current `kustomization.yaml` and how config is sourced (literals, files, envs) - How config reaches workloads (volume mounts vs envFrom) - The GitOps tool applying the output (Argo CD / Flux / kubectl) - Pain points (config changes not triggering restarts, or restarts looping) Your job: 1. **Why generators beat hand-written ConfigMaps** — explain that `configMapGenerator`/`secretGenerator` append a content hash to the resource name (e.g., `app-config-7d8f9`), and Kustomize rewrites every reference, so a config change produces a new name and triggers a rolling update automatically. 2. **Generator sources** — show `literals`, `files`, and `envs` inputs, and when to use each. Include a `secretGenerator` with `type` and base64 handling, and note that the plaintext still lives in Git unless paired with SOPS/sealed-secrets. 3. **The hash-suffix trap** — explain `disableNameSuffixHash: true` and `generatorOptions`. Warn that disabling the hash breaks the auto-restart behavior, and that mounting a hashed ConfigMap by a hardcoded name (bypassing Kustomize's reference rewrite) defeats the mechanism. 4. **Volume vs envFrom semantics** — clarify that mounted ConfigMaps update in-place (with eventual kubelet sync) but env vars do NOT, which is exactly why the hash-triggered pod restart matters for envFrom consumers. 5. **Merge & overlay behavior** — how `behavior: merge`/`replace`/`create` works across base and overlays so environment overlays can extend a base ConfigMap without duplicating it. 6. **GitOps interaction** — note that Argo CD prunes the old hashed ConfigMap once nothing references it; explain orphan accumulation if pruning is off and how to clean up. 7. **Validation** — `kustomize build` the overlay and confirm the hash changes when content changes and stays stable when it doesn't (deterministic output). 8. **Anti-patterns** — disabling the hash then wondering why pods don't restart, putting secrets in `configMapGenerator`, and referencing generated names from outside Kustomize. Output as: (a) annotated generator examples, (b) generatorOptions guidance, (c) volume-vs-env explanation, (d) overlay merge example, (e) a validation + cleanup checklist. Make the hash-driven restart behavior the centerpiece.