All jobs

Add a Horizontal Pod Autoscaler to a Helm Chart

Yes. An agent adds an autoscaling/v2 HPA template to your Helm chart behind a values flag, wires resource requests, lints and renders the chart, and opens a PR.

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 chart before it adds a template. In a chart like charts/hello-world in helm/examples, Chart.yaml is apiVersion: v2, version: 0.1.0 and appVersion: "1.16.0"; values.yaml sets replicaCount: 1, an image block (nginx, pullPolicy: IfNotPresent, empty tag), nameOverride, fullnameOverride, a serviceAccount block and a service block (ClusterIP, port 80), and nothing else. There is no autoscaling key and no resources key. templates/deployment.yaml sets replicas: {{ .Values.replicaCount }}, one container with a named http port on 80 and liveness and readiness probes on /, and no resources block at all. templates/_helpers.tpl defines hello-world.fullname, hello-world.labels and hello-world.selectorLabels, which the new template reuses.

Two things in the repository shape the change. First, ct.yaml points chart-testing at charts, and .github/workflows/lint-test.yaml runs ct lint on every pull request and ct install on a kind cluster when a chart changed, so the pull request will be installed for real by CI. Second, .github/workflows/release.yaml runs chart-releaser on every push to main, which publishes a chart only when version in Chart.yaml has changed; a template change without a version bump would ship nothing. The agent bumps version and says why in the pull request.

It then writes templates/hpa.yaml: an autoscaling/v2 HorizontalPodAutoscaler wrapped in {{- if .Values.autoscaling.enabled }}, with scaleTargetRef naming the Deployment through hello-world.fullname, minReplicas and maxReplicas from values, and a CPU Resource metric with averageUtilization from targetCPUUtilizationPercentage, plus an optional memory metric when targetMemoryUtilizationPercentage is set. In deployment.yaml it wraps the replicas line in {{- if not .Values.autoscaling.enabled }}, so the HPA and the Deployment never fight over the count, and adds resources: {{- toYaml .Values.resources | nindent 12 }}, because a utilization target is a percentage of the container's request and an HPA on a container with no request has nothing to compute. values.yaml gains autoscaling: {enabled: false, minReplicas: 1, maxReplicas: 5, targetCPUUtilizationPercentage: 80} and resources: {} with a commented example, so existing installs render exactly as before. A fail guard in hpa.yaml refuses to render when autoscaling is on and resources.requests.cpu is empty, with a message that names the value to set.

The agent checks its work with helm lint charts/hello-world, then helm template once with defaults (the HPA is absent, replicas: 1 is present) and once with --set autoscaling.enabled=true --set resources.requests.cpu=100m (the HPA renders, replicas is gone), and runs kubeconform on both outputs against the autoscaling/v2 schema. It runs ct lint --config ct.yaml as the repository's own workflow would, and keeps every output in the run's record.

Start it with one API call

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

{
  "agent": "claude",
  "input": "Add a HorizontalPodAutoscaler to the Helm chart in this repository. Read Chart.yaml, values.yaml, templates/deployment.yaml and templates/_helpers.tpl first. Write templates/hpa.yaml as an autoscaling/v2 HPA rendered only when autoscaling.enabled is true, targeting the chart's Deployment, with minReplicas, maxReplicas and a CPU utilization target from values and an optional memory target. In the Deployment, render replicas only when autoscaling is off and add a resources block from values. Add the new values with autoscaling disabled by default so existing installs do not change, and fail rendering when autoscaling is on but no CPU request is set. Bump the chart version. Check with helm lint, helm template with and without autoscaling enabled, kubeconform on the rendered output, and ct lint if the repository has a ct.yaml. Open a pull request that shows both rendered outputs.",
  "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 touching four files: a new templates/hpa.yaml, two edits in templates/deployment.yaml (the conditional replicas and the resources block), new autoscaling and resources keys in values.yaml, and the version bump in Chart.yaml. The description shows the helm template output for both settings side by side and the kubeconform and ct lint results, and explains why the version changed.

Because the chart changed, the repository's Lint and Test Charts workflow runs ct lint and then ct install on a kind cluster against the pull request, so the chart is installed with its default values before anyone reads the diff. The run's record keeps the sandbox-side commands and their output for the same change.

Before merging, a reviewer checks that the clusters the chart targets run metrics-server (an HPA without it stays at minReplicas and reports unknown metrics), that the default maxReplicas and the utilization target fit the service, and whether resources.requests should get real defaults for this image rather than stay empty.

Run it on every new chart in the repository

In the console, an automation in the Project that has the repository, with a github trigger on pull_request.opened and pull_request.synchronize and branch_patterns for your default branch, starts one run per pull request, with the pull request as its context. The prompt tells the run to add the HPA template when the pull request adds a chart directory and push to the pull request's branch, or to comment with the patch when the chart already scales.

From your own server, the same work is one POST /o/{org}/sessions per chart repository with this body and the repository in resources, and a webhook on the API key reports run.completed or run.failed with the session_url to read the pull request link.

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

Why run it on Rush?

An HPA template is a dozen lines, but the mistakes around it are the expensive part: a Deployment that still sets replicas resets the count on every helm upgrade, a utilization target with no CPU request never scales, and a chart repository that releases on version bumps ships nothing when the bump is forgotten. The agent reads deployment.yaml, values.yaml and the release workflow before writing, and renders the chart both ways to prove each case.

The proof travels with the change. helm template, kubeconform and ct lint run in the sandbox and their output stays in the run's record, and the repository's own chart-testing workflow installs the result on a kind cluster. Several charts in one repository, or several repositories, can get the same change at the same time in separate sandboxes.

Frequently asked questions

Will existing installs of the chart change?

No. autoscaling.enabled defaults to false, so the HPA does not render, replicas renders as before, and resources: {} renders an empty block, which Kubernetes treats the same as none. The pull request shows the default render to make this visible.

Why remove replicas from the Deployment when autoscaling is on?

Both the Deployment spec and the HPA want to own the replica count. If the Deployment keeps replicas, every helm upgrade writes that number back and the HPA's scaling is undone. Rendering replicas only when autoscaling is off is the pattern helm create scaffolds for the same reason.

Does it need a cluster to check the change?

Not in the sandbox: helm template and kubeconform validate the rendered manifests offline. The repository's chart-testing workflow then installs the chart on a kind cluster in CI, and the pull request links to that run.

Can the HPA scale on a custom or external metric?

Yes, by adding an entry to autoscaling.metrics in input; the template renders whatever metric list values provide. Pods or External metrics also need an adapter such as prometheus-adapter on the cluster, which the pull request would call out.

More Helm jobs

The same job on other stacks

Keep reading