All jobs

Move Hard-Coded Settings Into ConfigMaps and Secrets in Kubernetes Manifests

Yes. An agent moves credentials and options written into your Deployments into a Secret and a ConfigMap, wires them in with envFrom, and validates every manifest.

Run this on RushOpens 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 reads the manifests and the code they run. In a repository like dockersamples/example-voting-app, k8s-specifications/ holds nine files: Deployments and ClusterIP Services for db (postgres:15-alpine) and redis, Deployments and NodePort Services for vote (port 31000) and result (port 31001), and a worker Deployment. db-deployment.yaml sets POSTGRES_USER and POSTGRES_PASSWORD to postgres as plain value fields. The other three Deployments set no environment at all, which only works because the code hard-codes everything: vote/app.py connects to the host redis and reads OPTION_A and OPTION_B from the environment with Cats and Dogs as defaults, result/server.js opens postgres://postgres:postgres@db/postgres as a literal connection string, and worker/Program.cs opens Server=db;Username=postgres;Password=postgres; and the Redis host redis the same way.

The agent splits the work by what takes effect immediately and what needs a new image. It adds k8s-specifications/db-secret.yaml, a Secret named db-credentials with POSTGRES_USER and POSTGRES_PASSWORD under stringData, and vote-configmap.yaml, a ConfigMap with OPTION_A and OPTION_B. db-deployment.yaml loses its two literal values and gains envFrom with a secretRef; vote-deployment.yaml gains envFrom with a configMapRef. Both work with the images the manifests already pull from Docker Hub, because Postgres and the vote app read those variables today.

For result and worker the values live in code, so the agent changes the code to read POSTGRES_HOST, POSTGRES_USER and POSTGRES_PASSWORD (and REDIS_HOST for the worker and the vote app) from the environment, keeping the current literals as defaults so the behaviour is identical when nothing is set. In server.js that is process.env with a fallback; in Program.cs it is Environment.GetEnvironmentVariable with the same fallbacks, in both places the connection string is built. The two Deployments then get envFrom with the Secret plus env entries for the hosts. The pull request says plainly that these two changes reach the cluster only after the call-docker-build-result.yaml and call-docker-build-worker.yaml workflows publish new images from main, and that until then the defaults keep the current behaviour, so applying the manifests early breaks nothing.

It validates without a cluster: every file in k8s-specifications/ goes through kubeconform -strict -summary, the new envFrom and env blocks are checked against the current API schemas, node --check result/server.js confirms the JavaScript parses, and the worker project is compiled with the .NET SDK, installed in the sandbox if it is missing. It also mirrors the new variables into docker-compose.yml for result and worker so Compose and Kubernetes name the same settings, and leaves the Compose db service, which already uses environment, as it is.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Move the hard-coded configuration in this repository's Kubernetes manifests into a Secret and a ConfigMap. Read every file in the manifests folder and the services' source first. Put database credentials in a Secret and user-facing options in a ConfigMap, wire them into the Deployments with envFrom, and where a service hard-codes a host or credential in code, read it from the environment with the current value as the default. Say in the pull request which changes take effect with the published images and which need a new image build. Validate every manifest offline 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 adds k8s-specifications/db-secret.yaml and k8s-specifications/vote-configmap.yaml, edits the four Deployments that need environment, changes result/server.js, worker/Program.cs and docker-compose.yml, and touches no Service. The description has a table of each variable, where it came from, where it now lives and which image reads it, followed by the kubeconform summary and the compile output from the sandbox.

The run's record keeps every command: the schema validation of all eleven files, the Node syntax check and the .NET build, so a reviewer can confirm the manifests are valid for the API versions they declare without applying them anywhere.

Before merging, a reviewer decides how the Secret is managed for a real cluster, since the file in git still holds the demo password the repository already published in plain text; a sealed or external secret with the same name slots in without touching the Deployments. They also merge the image workflows' output before expecting result and worker to read the new variables.

Run it on every repository you hand off

This is a one-time clean-up you start from a terminal with POST /o/{org}/sessions and this body, then leave; the pull request arrives when the agent is done. A follow-up through POST /o/{org}/sessions/{id}/messages wakes the parked sandbox for the next step: a second ConfigMap for the result app's port, a Kustomize overlay per environment, or the same treatment for docker-stack.yml.

A platform team with many service repositories can send one request per repository, each in its own sandbox with its own pull request. A request_id, a UUID per repository, keeps a rerun of the script from starting a second run on a repository that already has one.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

The hard part of this change is not writing a Secret; it is finding every place a value is baked in, across YAML, Python, JavaScript and C#, and knowing which of them a running cluster will pick up today. The agent reads all of it, keeps the current values as defaults so nothing changes until you want it to, and writes down which image has to be rebuilt.

The sandbox runs the schema validation, the syntax check and the compile for real and keeps the output in the run's record, so the pull request shows what was checked rather than asking you to trust it. Several repositories can be done at once, each with its own run and its own evidence.

Frequently asked questions

Will this break what is running in my cluster?

No. The database and vote changes use variables those images already read, and the result and worker code keeps the old values as defaults until the new environment is present. Applying the new manifests against the published images gives the same behaviour as before.

Why is the password still in a file in git?

Because it already was, in db-deployment.yaml as a plain value, and the agent does not invent a secret store you have not chosen. The Secret manifest gives the credential one name and one place; swapping the file for a sealed, external or SOPS-managed Secret with the same name needs no change to the Deployments.

Why do the worker and the result app still contain the old connection string?

As the default when the variable is unset, so the Compose setup and anyone running the code locally see no change. The Deployments set the variables explicitly, and the pull request lists the exact lines so you can drop the defaults later if you prefer a hard failure.

Does the agent apply anything to a cluster?

No. It validates each manifest against the Kubernetes API schemas with kubeconform, which needs no cluster, and leaves applying to your pipeline. Nothing is pushed to a registry either; the image workflows in the repository do that when the pull request merges.

More Kubernetes jobs

More jobs like this: Hand off a long task

Keep reading