Sub topic 2
Ephemeral runners: one job, one clean environment
This chapter assumes you can write a basic GitHub Actions workflow and know what a Kubernetes pod is. It covers the runner behavior that ARC builds on.
The problem with long-lived runners
A self-hosted runner is a machine you manage that runs GitHub Actions jobs. The simplest setup registers a runner once and leaves it running. This is a persistent runner. It takes job after job, and each job inherits whatever the previous one left behind.
That causes three kinds of trouble:
- Drift. Files in the workspace, installed tools, and environment changes accumulate. A job passes on one runner and fails on another because of leftover state.
- Security exposure. A job that runs untrusted code can leave a modified tool, a stolen credential, or a background process. The next job runs in that compromised environment.
- Wasted capacity. An idle persistent runner costs money. If you have too few, jobs queue. If you have too many, they sit idle.
What ephemeral means
An ephemeral runner registers with GitHub, accepts exactly one job, and is then removed. GitHub deregisters it automatically after the job finishes, so it can never be assigned a second job. The next job gets a new runner built from the same clean image.
On Kubernetes the mapping is direct. Each runner is a pod, and the pod is deleted when its job ends. Nothing carries over except what you deliberately store outside the pod.
Seeing the difference
This workflow writes a marker file and then checks whether one already exists. Run it twice with the self-hosted label.
name: Clean environment check
on: workflow_dispatch
jobs:
check:
runs-on: self-hosted
steps:
- name: Look for leftovers
run: |
if [ -f /tmp/marker ]; then
echo "Leftover state found: this runner is being reused"
else
echo "Clean environment"
fi
- name: Leave a marker
run: touch /tmp/markerOn a persistent runner, the second run prints the leftover message. On an ephemeral runner, both runs print Clean environment, because each run lands in a fresh environment.
Trade-offs
Ephemeral runners are not free. You should plan for these costs:
| Benefit | Cost |
|---|---|
| Every job starts from a known image | Each job pays startup time for the pod and runner |
| Compromised state cannot reach later jobs | Local caches are lost, so tools and dependencies download again |
| Capacity can follow demand | You need a controller that creates and removes runners |
The last row is the reason ARC exists. Creating and cleaning up one runner per job by hand is impractical, so a controller does it. The cost of lost caches is usually handled with the actions/cache action or a prebuilt runner image that already contains your tools. Later chapters cover the image option.
Common mistakes
- Assuming files persist. Do not write build output to the runner and expect a later job to find it. Use artifacts or a cache instead.
- Treating ephemeral as fully safe. A clean runner protects later jobs. A running job can still read secrets given to it and reach whatever the pod's network allows.
- Registering runners with the ephemeral option off. Without it, a runner stays registered and accepts further jobs. ARC sets this for you, but you should know it when debugging manual setups.
Exercise
A team's builds pass on one self-hosted runner and fail on another. A leftover file from an old job is the cause. Why does an ephemeral runner prevent this, and what do they give up in return?
Show answer
An ephemeral runner accepts one job and is then deregistered and deleted, so every job starts from the same clean image and no leftover files can exist. In return they lose local state between jobs, such as dependency caches, and each job pays pod startup time. They can restore speed with actions/cache or a runner image that already includes their tools.