Learn to use Kustomize generators for automatic Kubernetes rollouts triggered by configuration changes without manual commands.
In this tutorial, you’ll learn how to use Kustomize generators—both ConfigMap and Secret generators—to automatically trigger rollouts in Kubernetes when configuration changes. Kustomize appends a randomized suffix to generated resource names and updates all workload references at build time, ensuring seamless updates without manual kubectl rollout commands.
When you define a generator in Kustomize, it outputs a standard Kubernetes resource—either a ConfigMap or a Secret—with a unique suffix added to the name. This suffix guarantees that any change in generator inputs produces a new resource, prompting Kubernetes to detect updates and redeploy your workloads.Example: Generating a ConfigMap named db-cred with a literal key-value pair:
Kustomize ensures uniqueness by appending -jj26gh to the base name.Your Deployment or Pod spec references the generator by its base name (db-cred), and Kustomize will rewrite it to include the full suffix:
When you update the generator inputs—for instance, changing password1 to password2—Kustomize generates a new ConfigMap (e.g., db-cred-a477b) and updates your Deployment spec accordingly:
Copy
Ask AI
# Old ConfigMapapiVersion: v1kind: ConfigMapmetadata: name: db-cred-jj26ghdata: password: "password1"# New ConfigMapapiVersion: v1kind: ConfigMapmetadata: name: db-cred-a477bdata: password: "password2"
Avoid committing sensitive information in plaintext to source control. Use sealed secrets or external secret management services for production workloads.