Autoscaling Self-Hosted CI Runners with KEDA
How KEDA drives event-based autoscaling for self-hosted CI runners, covering ScaledObject config, ARC integration, and failure mode mitigation.

KEDA can scale self-hosted GitHub Actions runners on the number of queued jobs rather than on CPU, but only if it is given a target it is able to scale. The design that holds up is a KEDA ScaledJob driven by KEDA’s github-runner scaler. When the scaler finds queued workflow jobs, KEDA starts Kubernetes Jobs, and each Job runs one ephemeral runner that registers with GitHub, takes one workflow job and exits. This article covers that design, the manifests for it and the ways it fails. If you already run Actions Runner Controller (ARC), you do not need KEDA at all, for reasons set out below.
The problem it solves is familiar. A fixed pool of self-hosted runners sized for the busiest hour sits idle for the rest of the day, and a pool sized for the average leaves jobs waiting during release pushes. GitHub’s documentation presents autoscaling as the way to match self-hosted runner capacity to demand, and recommends ephemeral runners when you autoscale (self-hosted runners reference).
#Why CPU is the wrong signal for runners
The Kubernetes Horizontal Pod Autoscaler (HPA) is usually set up to scale on CPU or memory. A runner waiting for work uses almost no CPU, and CI demand arrives as a burst of queued jobs, so CPU tells the autoscaler nothing about how many runners are needed. The HPA also works on its own loop, set by kube-controller-manager’s --horizontal-pod-autoscaler-sync-period, which is 15 seconds by default. The number you want to scale on is the count of jobs waiting for a runner, and that is what KEDA’s github-runner scaler reports.
#How the github-runner scaler sees the queue
The scaler polls the GitHub REST API. It does not receive webhooks, and KEDA’s setup steps for the GitHub App tell you to disable webhooks on it. On each check it lists the owner’s repositories (unless you name them in repos), lists the workflow runs in each repository, lists the jobs in each queued run, and counts the jobs whose labels match the scaler’s labels. By default it also scales on the default labels self-hosted, linux and x64; setting noDefaultLabels to "true" turns that off. In an organisation that already has other self-hosted runners, the default means the scaler also counts their jobs that ask only for those default labels, so set it to "true" and select these runners by their custom label. When the count reaches targetWorkflowQueueLength (default 1), it scales up.
GitHub also sends a workflow_job webhook as each job is queued, starts and completes, and you can build your own scaling service on it. KEDA plays no part in that path: you write and run the receiver yourself, and GitHub notes that relying on webhook delivery for scaling decisions can introduce delays and reliability concerns.
#Why a ScaledJob and not a ScaledObject
A KEDA ScaledObject scales an existing workload by creating an HPA that sets its replica count. The target can be a Deployment, a StatefulSet or a custom resource, but KEDA states that a custom resource target must define the /scale subresource. The legacy ARC RunnerDeployment CRD (actions.summerwind.dev/v1alpha1) defines only a status subresource, so a ScaledObject pointed at it cannot scale it. An earlier version of this article showed exactly that configuration, and it does not work.
A ScaledObject can scale a plain Deployment of runner pods, but KEDA warns that when the HPA scales down there is no way to control which replica is terminated, so it can stop a runner part-way through a job. KEDA’s answer for long-running work is the ScaledJob: instead of resizing a Deployment, it creates Kubernetes Jobs for the work it finds, and each Job runs to completion. An ephemeral runner fits that model. GitHub assigns it a single job and de-registers it after that job, and the pod then exits.
#If you already run Actions Runner Controller
ARC scales runners itself, so putting KEDA on top only duplicates it. The mode GitHub supports is runner scale sets, installed with the gha-runner-scale-set-controller Helm chart and one gha-runner-scale-set release per scale set. A listener pod holds a long-poll connection to GitHub, and as jobs are assigned ARC creates ephemeral runner pods, registered with just-in-time configuration, between the minRunners and maxRunners you set. The older summerwind mode is now legacy and maintained by the community only; GitHub supports only the scale-set version. In that legacy mode a RunnerDeployment is scaled by ARC’s own HorizontalRunnerAutoscaler, not by KEDA. KEDA makes sense when you want runners without ARC, or when KEDA already scales your other workloads.
#Rolling it out
Pilot it on one runner label used by a non-critical repository. To roll back, delete the ScaledJob and point that workflow’s runs-on back at your existing runners.
- Install KEDA from its Helm chart into its own namespace: add the
kedacorerepository, thenhelm install keda kedacore/keda --namespace keda --create-namespace. KEDA’s metrics server servesexternal.metrics.k8s.io, and KEDA documents that only one active metrics server can serve that API in a cluster, so check first that nothing else holds it (kubectl get apiservice | grep external.metrics). - Create a GitHub App in your organisation with webhooks disabled and the permissions KEDA lists: repository Actions (read-only), Administration (read and write) and Metadata (read-only), and organisation Self-hosted runners (read and write). Install it on the organisation and note the App ID and the installation ID. The scaler also accepts a personal access token, but GitHub suggests considering an App for automation, because an App installation’s rate limit grows with the organisation.
- Store the App’s private key as a Kubernetes Secret in the runner namespace, never in a ConfigMap.
- Apply the TriggerAuthentication and ScaledJob below.
- Make sure the cluster can add nodes. Without a node autoscaler such as Cluster Autoscaler or Karpenter, the Jobs KEDA creates will sit in Pending once the existing nodes are full.

#The manifests
Create the namespace and the Secret from the private key file you downloaded for the App:
1kubectl create namespace gha-runners
2kubectl create secret generic gha-app-credentials \
3 --namespace gha-runners \
4 --from-file=appKey=./app-private-key.pemThe TriggerAuthentication hands the private key to the scaler as its appKey parameter and must sit in the same namespace as the ScaledJob. The App ID and installation ID are not secrets: they go in the trigger’s metadata as applicationID and installationID, as in KEDA’s own GitHub App example.
1apiVersion: keda.sh/v1alpha1
2kind: TriggerAuthentication
3metadata:
4 name: gha-app-auth
5 namespace: gha-runners
6spec:
7 secretTargetRef:
8 - parameter: appKey
9 name: gha-app-credentials
10 key: appKeyThe ScaledJob below runs at most 40 runner Jobs for the organisation example-org, checks the queue every 30 seconds and creates nothing when the queue is empty. The runner image is myoung34/github-runner, a community image that KEDA’s documentation uses in its ScaledJob examples. With RUNNER_SCOPE set to org and APP_ID and APP_PRIVATE_KEY set, its entrypoint gets a token for the App’s installation on ORG_NAME, requests a registration token and registers the runner; EPHEMERAL adds the runner’s --ephemeral flag.
1apiVersion: keda.sh/v1alpha1
2kind: ScaledJob
3metadata:
4 name: gha-runner
5 namespace: gha-runners
6spec:
7 jobTargetRef:
8 template:
9 spec:
10 restartPolicy: Never
11 containers:
12 - name: runner
13 image: myoung34/github-runner:2.338.2-ubuntu-noble
14 env:
15 - name: RUNNER_SCOPE
16 value: "org"
17 - name: ORG_NAME
18 value: "example-org"
19 - name: LABELS
20 value: "k8s-linux"
21 - name: EPHEMERAL
22 value: "true"
23 - name: DISABLE_AUTO_UPDATE
24 value: "true"
25 - name: APP_ID
26 value: "123456"
27 - name: APP_PRIVATE_KEY
28 valueFrom:
29 secretKeyRef:
30 name: gha-app-credentials
31 key: appKey
32 resources:
33 requests:
34 cpu: "1500m"
35 memory: "3Gi"
36 limits:
37 cpu: "2"
38 memory: "4Gi"
39 pollingInterval: 30
40 minReplicaCount: 0
41 maxReplicaCount: 40
42 successfulJobsHistoryLimit: 5
43 failedJobsHistoryLimit: 5
44 scalingStrategy:
45 strategy: "eager"
46 triggers:
47 - type: github-runner
48 metadata:
49 owner: "example-org"
50 runnerScope: "org"
51 labels: "k8s-linux"
52 targetWorkflowQueueLength: "1"
53 enableEtags: "true"
54 applicationID: "123456"
55 installationID: "7890123"
56 authenticationRef:
57 name: gha-app-authSeveral choices in it matter:
- The trigger’s
labelsand the runner’sLABELSname the same custom label, and workflows pick these runners withruns-on: [self-hosted, k8s-linux]. If the two drift apart, KEDA starts pods for jobs those runners never match. runnerScopecan beorg,entorrepo.reposis optional at any scope: leave it out and the scaler queries every repository the owner has, which costs an extra listing request on each check; name the repositories and that call is skipped.enableEtagsmakes conditional requests, and a304 Not Modifiedresponse does not count against the rate limit.- The scaler counts queued jobs only. Once a runner takes a job, that job leaves the queue but its Kubernetes Job is still running, and KEDA’s default strategy creates
maxScale - runningJobCountnew Jobs, so busy runners are subtracted from new demand. KEDA describes this case, where work stays queued while there are free slots belowmaxReplicaCount, as the reason for theeagerstrategy. Test the strategy against your own queue before you rely on it. DISABLE_AUTO_UPDATEstops every new pod updating the runner when it is assigned its job, which GitHub notes otherwise repeats with ephemeral runners in containers. The cost is that you must update yourself: GitHub stops assigning jobs to a runner that is not updated within 63 days of a newer runner version becoming available, so move the image tag forward on a schedule.
If a long-lived Deployment of runners suits you better, a ScaledObject can target it by name with minReplicaCount, maxReplicaCount and the same trigger. You then carry the scale-down risk described above. KEDA’s other suggestion for long-running work is to delay termination with terminationGracePeriodSeconds or a preStop hook; whether that saves a running job depends on how your runner image handles SIGTERM. For the wider design questions behind internal CI platforms, see our architectural patterns.
#What goes wrong
#The first job after a quiet spell waits
With minReplicaCount: 0, the first queued job waits for KEDA’s next check (up to pollingInterval), then for pod scheduling, the image pull, runner registration and possibly a new node. Measure that in your own cluster. If pull request checks cannot wait, raise minReplicaCount on the ScaledJob: KEDA keeps that many Jobs running at all times, so one or two idle runners are ready to take work.

#Jobs sit queued and no runner starts
Look at the ScaledJob’s events and the KEDA operator logs first. Likely causes are an App installation that does not cover the repository, a missing permission, a label that differs between the trigger and the workflow’s runs-on, or the rate limit. GitHub keeps a job with no matching runner queued until a 24-hour timeout expires, so a broken scaler looks like slow CI rather than an error.
#The API budget runs out
Each check costs one request per repository to list its workflow runs and one per queued run to list its jobs, plus the repository listing when repos is empty. KEDA’s own example is 100 repositories and 10 queued runs: 110 requests per check, every 30 seconds by default. Runner pods add their own calls at start to get a token and register. An App installation’s limit is 5,000 requests an hour, rising with the number of repositories and users to at most 12,500, or 15,000 on a GitHub Enterprise Cloud organisation. When it is rate limited, the scaler waits until the reset time GitHub returns and reports its cached queue length meanwhile, so scaling stalls rather than fails. Name repositories in repos, keep enableEtags on and avoid a very short pollingInterval.
#Registration tokens expire
A runner registration token expires one hour after GitHub issues it. This image requests its token as the container starts and uses it straight away, so expiry only matters if you pre-generate tokens and pass them in. For tighter registration, the REST API can generate a just-in-time runner configuration instead; GitHub describes JIT runners as performing at most one job before being removed, and ARC’s scale-set mode registers its runners this way.
#Mixed job sizes waste nodes
One resource request for every runner gives a lint job and a heavy integration test the same pod. Run a separate ScaledJob per workload class, each with its own label (for example k8s-small and k8s-large), resource requests and node selector or taints, so a burst in one class cannot use up the other’s maxReplicaCount.
#Cost, isolation and security
Scaling to zero removes idle runner pods when nobody is pushing, at the price of the cold start above. Measure both on your own workload rather than assuming a saving.
Ephemeral runners help with security, but GitHub is plain about the limits. Self-hosted runners should almost never be used for public repositories, because anyone can open a pull request that runs on them; on private repositories, anyone who can open a pull request can reach the runner’s environment, its secrets and the GITHUB_TOKEN. GitHub recommends ephemeral runners for autoscaling because each is assigned one job, which helps limit what a job can see from earlier ones and reduces the risk of a compromised runner taking new work. A fresh pod is only clean if the node and anything mounted into it are clean too: GitHub warns that reusing hardware for JIT runners can expose information from the environment.
Runners registered at organisation level can take jobs from many repositories, so a compromise reaches further. GitHub suggests runner groups to restrict which repositories can use which runners. Give each team or trust level its own runner group, label, ScaledJob and namespace, with network policies between the namespaces and image signature checks enforced at admission for the runner namespaces.
Two control loops now decide how quickly a job starts: KEDA creating pods, and the node autoscaler adding nodes when the pods do not fit. In a burst their delays add up, so measure the time from queued to started before you promise anyone a CI turnaround.
Built this way, KEDA scales runners on the queue, the one signal that matters, and each runner lives for one job. The work moves from sizing a pool to watching the API budget, the node autoscaler and the runner image’s update schedule.
Evidence trail
Sources and verification
Primary documentation and external technical references used in this article.
About this page
Credited to
Dates
Published
Last updated
Was this useful?
Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.
Engineering insights, direct to you.
Receive the latest Systems Engineering tutorials, production guides, Engineering Labs and operational best practices.
Comments
Add a thoughtful note on Autoscaling Self-Hosted CI Runners with KEDA. Comments are checked for spam and held for moderation before appearing.