GitLab Runners and Executors¶
Overview¶
Distinguish shared, group, and project runners; pick an executor for isolation; and use job tags so the right capacity picks up production work.
A GitLab Runner is the agent that executes jobs. The executor decides how isolation works (host shell, Docker container, Kubernetes Pod, and others). Scope (instance/shared, group, project) decides who can use the runner. Tags bind jobs to capable fleets.
This is a core tutorial in Module 3 · GitLab Runners of the REBASH Academy GitLab CI/CD for Cloud & DevOps Engineers series — written for Cloud, DevOps, Platform, and SRE engineers.
Prerequisites¶
Learning Objectives¶
By the end of this tutorial, you will be able to:
- Contrast shared vs group vs project runners
- Choose shell, Docker, or Kubernetes executors for a workload
- Use
tagsso jobs land on the right fleet - Outline why autoscaling exists (cost and queue depth)
Architecture¶
This topic’s control points and relationships are shown below.
Theory¶
What it is¶
GitLab schedules jobs; runners claim them over the Runner API. Registration associates a runner with an instance, group, or project (modern registration uses authentication tokens and runner types). The executor plugin runs the job:
| Executor | Isolation | Typical use |
|---|---|---|
| Shell | Process on the runner host | Legacy / carefully locked hosts |
| Docker | Container per job | Most SaaS and self-managed CI |
| Kubernetes | Pod per job | Cluster-backed platforms |
| Docker Machine / autoscaler | Ephemeral VMs | Burst capacity (evolving tooling) |
Shared (instance) runners serve many projects (GitLab.com shared runners). Group runners serve all projects in a group. Project runners are scoped to one project — useful for privileged or regulated workloads.
Why it matters¶
Wrong executor choices create security and reliability debt: shell executors share a host filesystem; untagged “any runner” jobs can land on laptops registered as runners; missing capacity creates hour-long queues. Platform teams treat runners as product infrastructure — sized, tagged, monitored, and patched like any other fleet.
How it works¶
- Admin registers a runner with GitLab (token / runner authentication).
- Runner polls for jobs that match its tags and access scope.
- For Docker: pull
image:(or default), mount the build directory, runscript. - For Kubernetes: create a build Pod in a configured namespace, stream logs, clean up.
- Status and artefacts return to GitLab; autoscalers add/remove runner capacity from queue metrics.
Job authors select capacity with tags: [docker, linux] (example). Without tags, any untagged runner in scope may take the job — usually undesirable in production.
You can study YAML without owning runners: GitLab.com free tier provides shared runners; gitlab-ci-local runs many jobs on your laptop; glab ci lint validates syntax.
Key concepts and comparisons¶
| Scope | Who can use it | Ops note |
|---|---|---|
| Shared / instance | Broad set of projects | Minute quotas, noisy neighbour |
| Group | Projects under the group | Standard platform fleet |
| Project | One project | Privileged / air-gapped builds |
Autoscaling overview: idle VMs or cluster nodes cost money; static fleets waste capacity. Autoscaling adds runners when the pending queue grows and removes them when idle — design for warm pools if cold starts hurt MR feedback.
Common pitfalls¶
- Registering a personal laptop as an unprotected shared runner.
- Using the shell executor for untrusted open-source MRs.
- Forgetting tags so GPU or privileged jobs never run (or run everywhere).
- Equating “Docker executor” with “Docker-in-Docker” — DinD is a separate, higher-risk pattern.
Hands-on Lab¶
Create a workspace for this tutorial.
Focus: compare executor tags and pin a runner tag on a job
Step 1 – Document executors and pin tags¶
cat > runner-notes.md << 'EOF'
# Runner executors
- shell: fast, weak isolation
- docker: clean images (common)
- kubernetes: elastic; needs RBAC
Prefer tags over untagged shared runners for production jobs
EOF
cat > .gitlab-ci.yml << 'EOF'
stages: [probe]
probe_docker:
stage: probe
image: alpine:3.20
tags: [docker]
script:
- uname -a
- echo "executor expected: docker"
probe_shell:
stage: probe
tags: [shell]
rules: [{when: manual}]
script: ["echo manual shell-tagged job"]
EOF
Step 2 – Validate tags¶
Final step – Cleanup note¶
Validation¶
- Lab commands run under
~/rebash-gitlab/module-03/ - You can explain each Theory section in your own words
- You used modern tooling where it applies to this topic
- You can describe one production failure mode for this topic
Code Walkthrough¶
Production practice for GitLab Runners and Executors always combines:
- Inspect before you change (status, plan, logs, dry-run)
- Prefer reversible, documented changes (Git, IaC, drop-ins, version pins)
- Capture evidence (command output, pipeline logs) for handovers
- Prefer current tools and APIs over legacy shortcuts
- Least privilege — escalate credentials only when required
Keep runbooks short enough to follow under pressure. Automate checks; keep humans for judgement.
Security Considerations¶
- Treat credentials and tokens for gitlab as privileged — never commit them
- Prefer short-lived auth (OIDC, roles, SSO) over long-lived keys
- Validate blast radius before apply/deploy/delete operations
- Restrict who can approve production changes
- Collect audit logs; limit who can read sensitive traces
Common Mistakes¶
Registering a personal laptop as an unprotected shared runner.
Validate assumptions against the Theory section and official docs before changing production.
Using the shell executor for untrusted open-source MRs.
Lab shortcuts (open security groups, admin roles, skip approvals) must not ship unchanged.
Changing production without a rollback path
Always know how to revert (previous artefact, prior release, state rollback, DNS failback).
Best Practices¶
- Encode GitLab Runners and Executors changes as code and review them in pull requests
- Pin versions (images, modules, actions, provider plugins)
- Separate environments with clear promotion gates
- Alert on symptoms with runbooks attached
- Destroy lab resources; tag everything with owner and expiry where possible
Troubleshooting¶
| Symptom | Likely cause | Fix |
|---|---|---|
| Auth / permission denied | Wrong identity, policy, or scope | Check caller identity, roles, and least-privilege policies |
| Timeout / no route | Network, DNS, security group, or endpoint | Trace path, DNS, and allow-lists before retrying |
| Drift / unexpected plan | Manual change or wrong state/workspace | Reconcile desired vs actual; avoid click-ops on managed resources |
| Pipeline/job red | Flaky step, cache, or missing secret | Read failing step logs; bisect recent workflow/config changes |
| Cost spike | Idle load balancer, NAT, oversized compute | Inventory billable resources; stop/delete labs promptly |
Summary¶
GitLab Runners and Executors is essential for Cloud and DevOps engineers working with gitlab. Practise the lab until the inspection and change path is muscle memory, then continue the track.
Interview Questions¶
- Compare shell, Docker, and Kubernetes executors for isolation and cost.
- Jobs stuck in pending — what runner factors do you verify first?
- Why tag runners instead of relying on shared untagged runners?
- What security risk does a privileged Docker runner introduce?
- How do protected runners interact with protected branches/variables?
Sample answer — question 2
Check runner online status, matching tags, concurrent job limits, and whether the project may use that runner. Pending almost always means no eligible runner.
Sample answer — question 4
Privileged mode and Docker socket mounts can let jobs escape to the host. Prefer unprivileged executors and dedicated tags for production.