Sub topic 9
Autoscaling a Fleet of Fresh Runners
This chapter assumes you know the ephemeral and just-in-time (JIT) runner ideas from the previous chapters. It also assumes basic Kubernetes (pods, namespaces, Helm) and that you can read a GitHub Actions workflow. You will learn how a fleet creates one fresh runner per job, how Actions Runner Controller (ARC) does this, and which failure modes to watch for.
Why a fixed pool does not work
An ephemeral runner takes one job and is removed. If you have 40 jobs queued, you need 40 runners over time. If the queue is empty, you want none. A hand-sized pool fails in both directions:
- A pool that is too small leaves jobs waiting in the queue.
- A pool that is too large wastes money on idle machines.
- A pool that is refilled by a cron job or a human tends to fall back to reusing runners, which brings back the problems of persistent runners.
Autoscaling closes that gap. A controller watches demand and creates a runner for each job. Because each runner is ephemeral or JIT, it vanishes after that job. The fleet's size follows the queue.
The two signals a scaler can use
A scaler needs to know that a job is waiting. GitHub offers two ways to learn this.
| Signal | How it works | Strength | Weakness |
|---|---|---|---|
| `workflow_job` webhook | GitHub sends an HTTP POST when a job is `queued`, `in_progress`, or `completed`. | Simple to build. Works with any platform. | Deliveries can be delayed, dropped, or arrive out of order. You must expose an endpoint and verify the signature. |
| Scale set long poll | A listener process opens an outbound connection to the Actions service and asks for work. | No inbound endpoint. GitHub tells the listener how many jobs it needs capacity for. | Requires the scale set client API, which ARC wraps for you. |
A webhook-based scaler follows this loop. On queued, it calls the generate-jitconfig endpoint and starts a VM or container with the returned configuration. On completed, it makes sure the compute is gone. The in_progress event is useful for metrics. Because webhooks can be lost, a safe scaler also reconciles periodically. It compares the queued jobs from the API against its running runners and fixes the difference.
Actions Runner Controller and runner scale sets
ARC is GitHub's Kubernetes operator for autoscaling runners. Its current mode is called runner scale sets. It uses two Helm charts:
gha-runner-scale-set-controllerinstalls the controller once per cluster.gha-runner-scale-setinstalls one scale set, which is a named group of runners tied to a repository, organization, or enterprise.
For each scale set, ARC runs a small listener pod. The listener keeps an outbound long-poll connection to GitHub. Your cluster needs no public endpoint and no webhook receiver.
The flow for one job looks like this:
Three details matter in practice:
- The controller keeps an
EphemeralRunnerSetfor each scale set. Its replica count is the number of runners wanted. The listener changes that count, and the controller reconciles pods to match. - Each runner is an
EphemeralRunnerresource backed by a pod. The controller obtains JIT configuration for it, so no long-lived registration token is placed inside the pod. - When the job ends, the runner process exits, the pod finishes, and the controller removes it. The next job gets a brand-new pod from the image.
Installing a scale set
Install the controller first. Then create the runner namespace and a secret holding GitHub credentials, and install the scale set.
helm install arc \
--namespace arc-systems \
--create-namespace \
oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller
kubectl create namespace arc-runners
kubectl create secret generic arc-github-secret \
--namespace arc-runners \
--from-literal=github_token='REPLACE_WITH_TOKEN'A personal access token is acceptable for a first test. For production, prefer a GitHub App. For an App, the secret holds github_app_id, github_app_installation_id, and github_app_private_key instead of github_token. An App's permissions are narrower and not tied to a person's account.
Put the scale set settings in a values file:
githubConfigUrl: "https://github.com/OWNER/REPO"
githubConfigSecret: arc-github-secret
runnerScaleSetName: "arc-runner-set"
minRunners: 0
maxRunners: 20
containerMode:
type: "dind"Then install it:
helm install arc-runner-set \
--namespace arc-runners \
-f values.yaml \
oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-setThe settings that shape autoscaling behavior are:
minRunnerssets how many idle runners are kept warm. With0, the fleet scales to nothing when idle, which is cheapest but adds pod start time to the first job. A small positive number trades money for latency.maxRunnersis the ceiling. Jobs beyond it wait in the queue instead of creating more pods.runnerScaleSetNameis the name that workflows use to select the scale set.
A warm runner is idle, but it is still fresh. It has not run any job. Warm capacity does not break the one-job rule, because each warm runner still takes exactly one job and is then replaced.
Selecting a scale set from a workflow
With scale sets, the scale set name is the value for runs-on. You do not list self-hosted, linux, and other labels the way you did for individually registered runners.
name: test
on: pull_request
permissions:
contents: read
jobs:
test:
runs-on: arc-runner-set
steps:
- uses: actions/checkout@v4
- run: make testContainer modes and the isolation trade-off
Many jobs build or run containers. A runner pod therefore needs some way to do that, and ARC offers two modes:
dind(Docker in Docker) runs a Docker daemon next to the runner. It is the most compatible mode, but the daemon container is typically privileged, which weakens the boundary between the job and the node.kubernetesmode runs container steps as separate pods through runner container hooks. It avoids a privileged daemon but needs a storage class for a shared work volume. Some actions that assume a local Docker socket do not work in it.
A pod is a container boundary, not a VM boundary. If jobs come from code you do not fully trust, consider dedicated nodes for runner pods, or a VM-based approach. The isolation chapter covers this choice in detail.
Failure modes to plan for
Autoscaling moves the risk around, so check these points:
- Cold starts. With
minRunners: 0, the first job waits for node capacity, an image pull, and runner startup. Pre-pull large images with a node image cache, or keep a small warm pool. - Quota and capacity limits. If the cluster cannot schedule pods, the scale set requests runners that sit in
Pending. Jobs wait, and nothing looks broken in GitHub. Alert on pending runner pods. - Rate limits. Every runner needs a JIT configuration call. A burst of hundreds of jobs can hit API rate limits, so use
maxRunnersto bound the burst. - Orphans. If a pod is killed mid-job, GitHub marks the job failed once the runner stops responding. Make sure that your controller or scaler removes the dead runner record and does not leave it listed as offline.
- Stuck queues. A queued job that no runner picks up fails after a time limit, currently 24 hours for self-hosted jobs. Do not rely on that limit as monitoring.
- Credentials of the scaler. The token or App key that lets the controller create runners is itself a high-value secret. Give it only the runner administration permissions it needs, and scope it to the repository or organization it serves.
Building your own scaler
You can skip ARC and write a scaler from the workflow_job webhook. It must do these things correctly:
- Verify the
X-Hub-Signature-256header against your webhook secret before trusting the body. - Match the job's
labelsto your fleet. Ignore events for jobs that are not yours. - Call
generate-jitconfigwith the same labels and start fresh compute with that configuration. - Handle duplicates. Webhooks can be redelivered, so key your work on the job ID.
- Reconcile on a timer against the list of queued jobs and your running instances.
This is more work than it appears, which is why most teams on Kubernetes use ARC. Teams on VMs often use a maintained project built for their cloud.
Exercise
A team sets minRunners: 0 and maxRunners: 10 on a scale set. Over a busy hour, 25 jobs are queued at once. How many runners exist at the peak, what happens to the other jobs, and why is each runner still safe to treat as fresh?
Show answer
At most 10 runners exist at once. The remaining jobs stay queued and start as earlier runners finish and the scale set creates new ones. Each runner is ephemeral and gets its own JIT configuration, so it takes exactly one job and its pod is deleted afterward. A later job always starts in a new pod, so no files, processes, or credentials carry over.
Exercise
Why does a scale set that uses long polling need no public inbound endpoint, while a webhook-based scaler does?
Show answer
In a scale set, the listener makes an outbound connection to GitHub and asks for work, so GitHub never has to reach into your network. A webhook scaler receives HTTP POSTs from GitHub, so it needs a reachable endpoint and signature verification.