Skip to main content
Systems Engineering

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.

Autoscaling Self-Hosted CI Runners with KEDA
KBY Technologies12 min read

In this guide

Share

A fixed pool of ten self-hosted CI runners sits idle for eighteen hours a day, then chokes under a queue of ninety concurrent jobs during a release freeze. This is the default failure mode of static runner provisioning, and it is the single biggest source of wasted compute spend in mid-to-large engineering organisations running their own GitHub Actions or GitLab CI infrastructure. Provision for peak and you burn budget on idle EC2 instances or bare-metal nodes. Provision for average and every release day becomes a queueing disaster with jobs stacking for forty minutes before a runner picks them up. Neither static sizing model survives contact with real-world commit patterns, which are bursty, unpredictable, and heavily skewed towards business hours and release windows.

The fix is event-driven autoscaling for self-hosted CI runners, decoupled entirely from CPU or memory metrics and instead driven by the actual backlog of queued jobs. This article covers the architecture, implementation, and failure surface of using KEDA (Kubernetes Event-Driven Autoscaling) to scale self-hosted CI runners against a live job queue, using GitHub Actions as the reference platform, though the same pattern applies almost unchanged to GitLab CI and Buildkite.

#The Problem: Static Runner Pools Bleed Money and Time

Traditional self-hosted CI runner deployments fall into one of two categories: a fixed-size VM pool managed by Terraform, or a Kubernetes Deployment with a static replica count. Both suffer from the same architectural flaw — they scale on a schedule or a manual trigger, not on actual demand. The consequence is a bimodal cost curve: overspend on idle capacity outside peak hours, and underspend (in the form of engineer wait time) during bursts.

Horizontal Pod Autoscaler (HPA) is the obvious first attempt at a fix, but HPA scales on resource utilisation — CPU and memory — which is the wrong signal entirely for CI runners. A runner pod sits at near-zero CPU while polling for a job, then spikes during execution. By the time HPA reacts to the CPU spike, the job has often already finished. You need a queue-depth signal, not a resource-utilisation signal, and that is precisely the gap KEDA closes.

#Architectural Breakdown: Event-Driven Scaling for Self-Hosted CI Runners

#
Why Kubernetes HPA Falls Short for Self-Hosted CI Runners

HPA’s control loop polls the metrics-server every fifteen seconds by default and reacts to a rolling average. Self-hosted CI runners, by contrast, generate a step-function demand pattern — zero to ninety concurrent jobs in the time it takes a monorepo’s CI graph to fan out. Metric lag under HPA means jobs queue for minutes while the autoscaler catches up to a signal that was never the right one in the first place.

#
KEDA as the Control Plane

KEDA introduces a ScaledObject custom resource that translates an external event source — in this case, a GitHub Actions job queue exposed via webhook or the github-runner scaler — directly into replica count. Rather than measuring resource utilisation after the fact, KEDA measures the thing that actually matters: how many jobs are currently queued and unassigned. This is the correct architectural pattern for self-hosted CI runners because it treats the runner fleet as a consumer group against a work queue, structurally identical to autoscaling a Kafka consumer group against partition lag.

The full pipeline looks like this: GitHub fires a workflow_job webhook event on queue → an ingestion service (or the KEDA github-runner scaler polling the Actions API) records queued job count → KEDA’s metrics adapter exposes this as an external metric → the ScaledObject’s HPA shim scales the target runner resource accordingly. This decouples the scaling decision entirely from node-level telemetry, which is what makes it viable for self-hosted CI runners with highly variable job durations.

self-hosted CI runners

#Implementation Logic

The rollout sequence for a production-grade KEDA-driven runner fleet follows five stages. Pilot it on a single non-critical runner label or repository first, and record the current runner replica counts and manifests (for example with kubectl get -o yaml) so you can roll back by reapplying them and deleting the ScaledObject:

  • Deploy actions-runner-controller (ARC) into a dedicated arc-systems namespace, using ephemeral runners rather than long-lived registered runners — ephemeral runners de-register automatically after one job, which avoids stale registration drift. The examples below use the legacy summerwind RunnerDeployment API; the newer gha-runner-scale-set mode has its own built-in scaling and is configured differently.
  • Install KEDA via Helm into its own namespace. KEDA registers an APIService for external.metrics.k8s.io. Before installing, check that no other external metrics adapter already holds that APIService (kubectl get apiservice | grep external.metrics), since two adapters will conflict.
  • Configure a GitHub App (or a personal access token, which the KEDA scaler also supports) with the permissions listed in the KEDA github-runner scaler documentation, scoped to the specific organisation or repository set that ARC will service. Store the private key as a Kubernetes Secret, never as a plaintext ConfigMap.
  • Define the ScaledObject targeting a workload that exposes the scale subresource (the ARC RunnerDeployment does; verify this for your ARC version), with minReplicaCount: 0 to enable scale-to-zero during idle periods, and a maxReplicaCount capped against your node pool’s autoscaling ceiling to prevent runaway billing.
  • Attach a cluster-autoscaler or Karpenter provisioner to the underlying node group so pod-level scaling triggers node-level scaling in turn — KEDA scaling pods is meaningless if there is no compute capacity to schedule them onto.

#Code & Configurations

The ScaledObject below binds the ARC RunnerDeployment to the GitHub Actions job queue using the native KEDA scaler, polling every fifteen seconds and scaling between zero and forty ephemeral runners. It uses organisation scope; if you use runnerScope: repo instead, the scaler also requires a repos field listing the repositories. Check the field names against the KEDA documentation for your version:

1apiVersion: keda.sh/v1alpha1
2kind: ScaledObject
3metadata:
4 name: gha-runner-scaler
5 namespace: arc-runners
6spec:
7 scaleTargetRef:
8 apiVersion: actions.summerwind.dev/v1alpha1
9 kind: RunnerDeployment
10 name: default-runner-deployment
11 pollingInterval: 15
12 cooldownPeriod: 120
13 minReplicaCount: 0
14 maxReplicaCount: 40
15 triggers:
16 - type: github-runner
17 metadata:
18 githubApiURL: https://api.github.com
19 owner: kby-technologies
20 runnerScope: org
21 labels: "self-hosted,linux,x64"
22 targetWorkflowQueueLength: "1"
23 authenticationRef:
24 name: gha-runner-auth

Authentication is handled via a TriggerAuthentication resource referencing the GitHub App credentials, kept out of the ScaledObject manifest entirely:

1apiVersion: keda.sh/v1alpha1
2kind: TriggerAuthentication
3metadata:
4 name: gha-runner-auth
5 namespace: arc-runners
6spec:
7 secretTargetRef:
8 - parameter: applicationID
9 name: gha-app-credentials
10 key: appId
11 - parameter: installationID
12 name: gha-app-credentials
13 key: installationId
14 - parameter: appKey
15 name: gha-app-credentials
16 key: privateKey

Finally, the underlying RunnerDeployment should enforce ephemeral runner behaviour and pin resource requests tightly to avoid bin-packing fragmentation on the node pool:

1apiVersion: actions.summerwind.dev/v1alpha1
2kind: RunnerDeployment
3metadata:
4 name: default-runner-deployment
5 namespace: arc-runners
6spec:
7 replicas: 0
8 template:
9 spec:
10 ephemeral: true
11 organization: kby-technologies
12 labels:
13 - self-hosted
14 - linux
15 - x64
16 resources:
17 requests:
18 cpu: "1500m"
19 memory: "3Gi"
20 limits:
21 cpu: "2000m"
22 memory: "4Gi"
23 dockerEnabled: true

This is the exact pattern KBY Technologies applies when advising clients on architectural patterns for internal CI platforms — treat the runner fleet as a stateless, disposable consumer group, never as a pet infrastructure component.

#Failure Modes & Edge Cases

Self-hosted CI runners under event-driven autoscaling introduce a distinct failure surface compared to static pools, and each of the following needs explicit mitigation:

#
Scale-to-zero cold start latency

When minReplicaCount is set to zero, the first job after an idle period pays the full cost of pod scheduling, image pull, and runner registration — often tens of seconds, depending on image size and node availability; measure this in your own environment. For latency-sensitive pipelines (e.g. PR checks blocking merge), add a cron trigger to the same ScaledObject so that desired replicas stay at least 1 during business hours, and let it drop to zero only overnight. KEDA’s cron scaler takes timezone, start, end and desiredReplicas metadata; for example, a second entry under triggers:

1- type: cron
2 metadata:
3 timezone: Europe/London
4 start: 0 8 * * 1-5
5 end: 0 19 * * 1-5
6 desiredReplicas: "1"

Do not create a second ScaledObject for the same target, as two ScaledObjects on one workload create conflicting HPAs and are unsupported.

Autoscaling Self-Hosted CI Runners with KEDA architecture diagram 2

#
Registration token race conditions

GitHub Actions runner registration tokens are short-lived (GitHub documents them as expiring after one hour). A possible scenario is that ARC’s controller experiences a reconciliation delay while KEDA is simultaneously scaling replicas up, leaving pods that hold expired tokens and fail to register, possibly showing as CrashLoopBackOff. Whether this occurs depends on your ARC version and how it refreshes tokens. Check ARC controller health and reconciliation (controller pod status and logs, and any metrics its endpoint exposes if you scrape them with Prometheus). If runner pods are stuck, first confirm they are not running a job (check the runner’s status in GitHub and the pod logs), then delete only those stuck runner pods so they re-register with a fresh token. Note that cooldownPeriod does not help here: it only controls how long KEDA waits after the last active trigger before scaling to zero (default 300 seconds).

#
Webhook delivery gaps

If you drive scaling via GitHub webhooks rather than API polling, a missed webhook delivery — which can happen during GitHub API incidents — leaves KEDA blind to queued jobs. Consider running the polling-based github-runner scaler as a fallback signal even if webhooks are your primary trigger, since polling degrades gracefully while webhooks fail silently.

#
Node pool bin-packing fragmentation

Ephemeral self-hosted CI runners with tightly pinned resource requests can still fragment a node pool if job resource requirements vary wildly — a 1-CPU lint job and an 8-CPU integration test job scheduled onto the same node class produce poor bin-packing efficiency. Segment runner pools by workload class (e.g. runner-light vs runner-heavy labels) and attach separate ScaledObjects and node taints per class.

#Scaling & Security Trade-offs

Moving self-hosted CI runners to an event-driven model changes both the cost profile and the attack surface. The trade-offs worth quantifying before rollout:

  • Cost efficiency vs cold-start latency — scale-to-zero can substantially cut idle compute spend in business-hours-only usage patterns, at the cost of a cold start on the first job after idle. Measure both against your own workload.
  • Ephemeral vs persistent runners — ephemeral self-hosted CI runners eliminate cross-job state leakage and reduce the blast radius of a compromised job, but increase registration and API call volume against GitHub’s rate limits. GitHub App installation rate limits vary by plan and organisation size, so check GitHub’s rate limit documentation for your account.
  • Secret exposure window — persistent runners stay registered for long periods and are a higher-value target for lateral movement; ephemeral runners register for a single job, which shrinks the exploitable window to that job’s duration.
  • Blast radius of a compromised runner image — a poisoned base image affects every job scheduled during its validity window; enforce image signature verification with an admission controller policy (Kyverno or the sigstore policy-controller) on the runner namespace to bound this risk.
  • Autoscaler-to-autoscaler latency stacking — KEDA scaling pods and cluster-autoscaler or Karpenter scaling nodes are two independent control loops; under aggressive bursts, total time-to-capacity is the sum of both loops’ reaction times, which must be measured and factored into SLA commitments for CI turnaround time.
  • Multi-tenancy isolation — running self-hosted CI runners for multiple business units on a shared cluster requires network policies restricting pod-to-pod traffic and separate ScaledObjects per tenant to prevent one team’s burst from starving another’s runner budget.

Event-driven scaling turns self-hosted CI runners from a fixed capital cost into a variable, demand-proportional one, but it shifts operational complexity from capacity planning into control-loop tuning and credential lifecycle management. Get the cooldown periods and node provisioner sizing right, and the runner fleet becomes invisible infrastructure rather than a recurring capacity-planning meeting.

Evidence trail

Sources and verification

Primary documentation and external technical references used in this article.

  1. 01GitHub Actionsdocs.github.com

About this page

Credited to

Dates

Published

Last updated

Corrections

  • : Corrected during a review of published articles. Details
Reader Interaction

Comments

Add a thoughtful note on Autoscaling Self-Hosted CI Runners with KEDA. Comments are checked for spam and held for moderation before appearing.

Loading comments...

Learn More About KBY

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.