Sub topic 9
Autoscaling a fleet of fresh runners
This chapter assumes you know how ephemeral runners and just-in-time (JIT) configuration work from the previous chapters. It also assumes basic Kubernetes use (namespaces, secrets, Helm).
Why autoscale
An ephemeral runner takes one job and is then removed. Someone has to create the next runner. At a few jobs a day you could do that by hand. At hundreds of jobs a day you need a system that watches for queued jobs, starts one fresh runner per job, and removes it afterwards. That system is an autoscaler.
Two properties matter. Capacity should follow demand, so you don't pay for idle machines. Each job should also get a clean runner, so no state or credentials carry over from one job to the next.
The scaling loop
Most autoscalers share the same loop:
- A workflow run queues a job whose
runs-onmatches your runners. - The autoscaler learns about the queued job, either by polling GitHub or through a webhook.
- It requests a JIT configuration from the REST API.
- It starts a new VM or container and passes it that configuration.
- The runner takes the job, finishes it, and exits.
- The autoscaler destroys the VM or container.
Actions Runner Controller
Actions Runner Controller (ARC) is GitHub's supported autoscaler for Kubernetes. Its runner scale set mode uses a listener that long-polls GitHub for job demand. For each job it creates an ephemeral runner pod and deletes the pod afterwards.
Install the controller once per cluster:
helm install arc \
--namespace arc-systems \
--create-namespace \
oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controllerThen create a secret that holds a credential ARC uses to register runners. A GitHub App is preferred in production. A personal access token is simpler for a first test:
kubectl create namespace arc-runners
kubectl create secret generic arc-github-secret \
--namespace arc-runners \
--from-literal=github_token="$GITHUB_PAT"Define the scale set in a values file:
githubConfigUrl: https://github.com/OWNER/REPO
githubConfigSecret: arc-github-secret
minRunners: 0
maxRunners: 10Install it with a release name. That name becomes the runner label:
helm install arc-runner-set \
--namespace arc-runners \
-f values.yaml \
oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-setA workflow targets the scale set by that name:
name: test
on: pull_request
permissions:
contents: read
jobs:
test:
runs-on: arc-runner-set
steps:
- uses: actions/checkout@v4
- run: make testTuning the limits
| Setting | Effect | Trade-off |
|---|---|---|
| `minRunners: 0` | No idle pods | Each job waits for pod startup |
| `minRunners: N` | N warm runners | Faster starts, but you pay for idle capacity |
| `maxRunners` | Hard cap on parallel jobs | Protects the cluster. Jobs queue when the cap is reached |
Warm runners are still ephemeral. When one takes a job, it is removed afterwards and a replacement is started.
Failure modes
- Slow starts. Pulling a large runner image on every pod adds minutes. Pre-pull images on nodes or keep them small.
- Quota exhaustion. If
maxRunnersexceeds what the cluster can schedule, pods stay pending and jobs queue. - Orphaned runners. If the autoscaler dies mid-job, a runner may stay registered in GitHub. Ephemeral registration limits the damage, but check the runner list regularly.
- Shared credentials. The autoscaler's own token can register runners. Keep it in the controller namespace and out of job pods.
Exercise
A team sets minRunners: 0 and maxRunners: 5. Twelve jobs are queued at once. How many run at the same time, what happens to the rest, and does any job reuse a runner that has already finished a job?
Show answer
Five jobs run at once, because maxRunners caps parallelism. The other seven stay queued until a pod finishes and capacity frees up. No job reuses a finished runner, because each runner is ephemeral and is removed after its single job. A new pod is created for each waiting job.