# Move Deployment Environment Literals Into Kustomize Generators

Yes. An agent moves the env values repeated across your Kustomize Deployments into configMapGenerator and secretGenerator entries, so a config change rolls the pods.

[Run this on Rush](https://cloud.getrush.ai/run/add-configmap-generator/kustomize/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the repository into its own cloud sandbox and renders the Kustomization before changing it. In a repository like argoproj/argocd-example-apps, `sock-shop/kustomization.yaml` is a bare list of 29 files under `sock-shop/base/`, one Deployment and one Service per microservice, with no `apiVersion` or `kind` header and no generators. Reading the Deployments, the agent finds the same configuration typed out by hand in several places: `carts-dep.yaml`, `orders-dep.yaml`, `queue-master-dep.yaml` and `shipping-dep.yaml` each carry an identical `ZIPKIN` host (`zipkin.jaeger.svc.cluster.local`) and an identical ten-flag `JAVA_OPTS` string; `catalogue-db-dep.yaml` sets `MYSQL_ROOT_PASSWORD` to `fake_password` and `MYSQL_DATABASE` to `socksdb` as plain values; `front-end-dep.yaml` sets `SESSION_REDIS` and `user-dep.yaml` sets `MONGO_HOST` to `user-db:27017`. The smaller `kustomize-guestbook/kustomization.yaml` in the same repository shows the convention the agent follows: a `kustomize.config.k8s.io/v1beta1` header and a `namePrefix`.

It adds the header to the sock-shop Kustomization and three `configMapGenerator` entries with `literals`: `java-services` for `ZIPKIN` and `JAVA_OPTS`, `catalogue-db-config` for `MYSQL_DATABASE`, and one each for the front end and the user service. The root password moves to a `secretGenerator` named `catalogue-db-credentials`, with the same value, so the rendered output still deploys. In the Deployments, the four Java services get a single `envFrom` with a `configMapRef` in place of their two literals, the MySQL container gets `envFrom` for the ConfigMap and a `secretKeyRef` for the password, and the two single-variable services get `valueFrom.configMapKeyRef`. Nothing else in those files changes: resources, probes, security contexts and node selectors stay as they are.

The point of generators over hand-written ConfigMaps is the name suffix. Kustomize appends a hash of the content to each generated object's name and rewrites every reference to it, so a change to `JAVA_OPTS` produces a new ConfigMap name, a changed pod template and a rolling update of the four Deployments that use it, instead of pods silently keeping old values until they happen to restart. The agent leaves `generatorOptions` at its default to keep that behaviour, and says so in a comment for anyone tempted to set `disableNameSuffixHash`.

To prove the change the agent runs `kustomize build sock-shop` before and after, writes both outputs to files, and compares them with the generated objects resolved: every container ends up with the same variables and values it had, the only additions being the ConfigMaps and the Secret, and the only textual difference being the references. It validates the rendered output with `kubeconform -strict`, and checks that the Argo CD `Application` for sock-shop, defined in `apps/values.yaml`, points at the directory and not at individual files, so Argo CD renders the generators itself and no other change is needed.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "In this repository's Kustomize app, move the environment variables written as literal values in the Deployments into configMapGenerator entries, and any credential into a secretGenerator, keeping the current values. Read every Deployment in the base directory first and group variables that several services share. Use envFrom or configMapKeyRef in the Deployments, keep the generated name suffix hash on, and change nothing else in the manifests. Render the Kustomization before and after, show that every container keeps the same variables and values, validate the output with kubeconform, and open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch that changes `sock-shop/kustomization.yaml` and seven Deployment files under `sock-shop/base/`, and adds no new files, because generators are declared in the Kustomization itself. The description lists each variable with the service it came from and the generator it moved to, shows the diff between the two rendered builds, and includes the `kubeconform` summary.

The run's record keeps both `kustomize build` outputs and the comparison, so a reviewer can confirm that no container lost or changed a value and that the generated names carry a suffix, without rendering anything locally.

Before merging, a reviewer decides whether `fake_password` should keep living in git as a generator literal, which is no worse than today, or move to a `files` source ignored by git or an external secret operator; and whether the Argo CD sync policy for sock-shop should prune the hand-written objects the old names leave behind, since the generated ones have new names.

## Run it on every Kustomize app you hand off

Start it from a terminal with `POST /o/{org}/sessions` and this body, with the repository in `resources`, and come back to a pull request. When you want more, a follow-up through `POST /o/{org}/sessions/{id}/messages` wakes the parked sandbox: add a `production` overlay that patches `JAVA_OPTS` with a larger heap, or do the same for the `kustomize-guestbook` app.

A platform team can start one run per GitOps repository, each in its own sandbox and each ending in its own pull request. Send a `request_id`, a UUID per repository, so a retried script gets the run it already started rather than a duplicate.

## Why run it on Rush?

The risk in this refactor is a variable that quietly disappears from one container, and the way to rule it out is to render before and after and compare every value, which is tedious by hand across 29 files. The agent does the comparison mechanically, with the generated objects resolved, and keeps the output as evidence.

The sandbox runs `kustomize build` and `kubeconform` for real and the run's record keeps both, so the pull request shows what was checked. Several repositories, or several apps in one repository, can run at once in separate sandboxes with separate pull requests.

## Frequently asked questions

### Why do the generated ConfigMaps have a hash in their names?

So that a configuration change changes the pod template. Kustomize rewrites every reference to the new name, the Deployment's template hash changes, and the pods roll. With a hand-written ConfigMap the pods keep the old values until something else restarts them. The agent keeps the suffix on and explains it in a comment.

### Is the MySQL password now a real secret?

It is a Kubernetes Secret with the same demo value the repository already published as a plain Deployment value, so the demo still deploys. Keeping a real credential out of git is a second step: point the generator at a file ignored by git, or use an external secret operator, with the same object name so the Deployment does not change.

### Will Argo CD show the app as out of sync?

Yes, once, because the ConfigMaps and the Secret are new objects and the Deployments' templates change. Argo CD renders the Kustomization itself, so no other configuration is needed; the pull request notes the one-time diff and the rollout it causes.

### Does this touch the Helm or Jsonnet guestbooks in the same repository?

No. The change is scoped to the one Kustomize app whose Deployments carry literal environment values. The agent reads the others to follow the repository's conventions, such as the Kustomization header, and leaves them as they are.

## More Kustomize jobs

- [Add Liveness and Readiness Probes to Kustomize Manifests](https://getrush.ai/run/add-health-checks/kustomize/)
- [Inflate a Helm Chart With Kustomize helmCharts](https://getrush.ai/run/add-helm-chart-inflation/kustomize/)
- [Add a Horizontal Pod Autoscaler to Kustomize Deployments](https://getrush.ai/run/add-horizontal-pod-autoscaler/kustomize/)

## More jobs like this: Hand off a long task

- [Move Hard-Coded Settings Into ConfigMaps and Secrets in Kubernetes Manifests](https://getrush.ai/run/add-configmaps-and-secrets/kubernetes/)
- [Enable the Gradle Configuration Cache for a Spring Boot Build](https://getrush.ai/run/add-configuration-cache/gradle/)
- [Add Connection Pooling to a Ktor Server with HikariCP](https://getrush.ai/run/add-connection-pooling/ktor/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
