GitLab Runner on GKE: limits and node autoscaling
GitLab Runner with the Kubernetes executor on GKE: spot nodes, runner from Helm, ResourceQuota and a 14-job load test in which the cluster added two nodes.
GITLAB · KUBERNETES · CI-CD · DEVOPS · PORADNIK
Pipelines sit in the queue because the runner lives on one VM with four cores and that is it. Or the other way round: the VM is big enough to survive Monday morning, and for the rest of the week you pay for an idle CPU. A runner with the Kubernetes executor on an autoscaling cluster solves both, as long as the limits are right. Wrong limits can block scaling altogether, which we checked in the lab.
This is the third post in the series about our GitLab Ultimate lab on Google Cloud. In the first one we set up OpenTofu state and the module registry, in the second the pipeline’s keyless login to Google Cloud. Now we build a GKE cluster, install a runner on it and load it with fourteen jobs at once.
When to run your own runner instead of GitLab.com runners
GitLab-hosted runners are enough while jobs are short and the team fits into the compute minutes of its plan. Your own runner makes sense when:
- you build images with Docker-in-Docker and want to control how much memory such a build gets,
- jobs need access to resources in your network or cloud,
- you want to pay for spot nodes that exist only while there are jobs.
In the lab all three apply. The next posts deploy an application to the same cluster, and the Ultimate scanners build and scan images on it.
The cluster from a module: GKE Standard and spot nodes
The cluster comes from the gke-runner module in the group registry, described in the first post. It is GKE Standard in a single zone (europe-central2-a), with private nodes and Cloud NAT for outbound traffic to gitlab.com. Jobs land in one pool of e2-standard-4 spot nodes that autoscales from 1 to 3:
resource "google_container_node_pool" "spot" {
autoscaling {
min_node_count = var.node_min_count # 1
max_node_count = var.node_max_count # 3
}
node_config {
machine_type = var.node_machine_type # e2-standard-4
spot = true
disk_type = "pd-standard"
disk_size_gb = 50
}
}
Autopilot is out. Docker-in-Docker builds need privileged pods, and Autopilot does not allow them.
You pay for the cluster, the NAT and the node for every hour they run, including nights when nobody starts a job. That is why the module has a cluster_enabled switch. With false only the network stays, and the network costs nothing. In the lab we flip the switch by hand, because the cluster runs only during a working session.
In a dev or rc environment you can turn the cluster off and on automatically at fixed times. A GitLab pipeline schedule (Build → Pipeline schedules) runs an apply with cluster_enabled = false at 19:00 and with true at 7:00. Pass the value in the schedule variable TF_VAR_cluster_enabled, not in terraform.tfvars, because a value from the file takes precedence over an environment variable. The apply job in a scheduled pipeline also has to start on its own instead of waiting for a click. With 12 working hours Monday to Friday, the cluster runs 60 hours a week instead of 168, so you pay for a little over a third of the time.
The runner from Helm, token only from a variable
You register the runner in GitLab: in the group, Build → Runners → New group runner, with the gke tag. If you pick GKE as the platform on the next screen, GitLab offers its own Terraform setup that creates a separate cluster. With an existing cluster, skip that wizard and take only the glrt-... token from the top of the page.
The token never goes into the repository. The install reads it from an environment variable:
helm upgrade --install gitlab-runner gitlab/gitlab-runner -n gitlab-runner \
-f runner/values.yaml --set-string runnerToken="$RUNNER_TOKEN"
For kubectl and helm to connect to GKE at all, you need the gke-gcloud-auth-plugin (gcloud components install gke-gcloud-auth-plugin). Without it, get-credentials writes the kubeconfig, but every command fails with executable gke-gcloud-auth-plugin not found.
Job limits and ResourceQuota
In values.yaml every job gets requests and limits separately for the build container, the service (here docker:dind) and the helper:
[runners.kubernetes]
privileged = true
cpu_request = "500m"
cpu_limit = "2"
memory_request = "1Gi"
memory_limit = "3Gi"
service_cpu_request = "250m"
service_cpu_limit = "1"
service_memory_request = "512Mi"
service_memory_limit = "2Gi"
helper_cpu_request = "50m"
helper_cpu_limit = "500m"
cpu_limit_overwrite_max_allowed = "4"
memory_limit_overwrite_max_allowed = "6Gi"
A job pod with dind reserves 0.8 cores and can use up to 3.5. The last two lines let a job ask for a higher limit in .gitlab-ci.yml, but no more than 4 cores and 6 GiB. A request above that fails the job instead of taking the whole node.
On the gitlab-runner namespace we set a ResourceQuota, the upper bound for all jobs together, and a LimitRange with defaults for containers without requests. How a per-project ResourceQuota fixed runners that took over a whole node is described in a separate post about a client project.
Pitfall: a quota limit blocks autoscaling
The first version of the quota had limits.cpu: "16". At 3.5 cores of limit per dind pod, only 4 jobs fit in it at once. Four jobs fit on one node, so the cluster would never have a reason to scale, and the remaining jobs would wait in the GitLab queue. The autoscaler looks at requests, while the quota also counts limits, so you have to work out both together with the runner’s concurrent.
In the lab the runner has concurrent: 8, and the quota is:
spec:
hard:
requests.cpu: "8"
requests.memory: 16Gi
limits.cpu: "32"
limits.memory: 48Gi
pods: "20"
Eight dind pods take 6.4 cores of requests and 28 cores of limits. That fits in the quota and does not fit on one e2-standard-4 node.
Load test: 14 jobs on one node
The test project has a pipeline with two parallel jobs: an image build in Docker-in-Docker and 4 minutes of CPU work. We started 7 pipelines, 14 jobs in total. The timeline from kubectl get events and kubectl get nodes:
| Time | What happened |
|---|---|
| 17:08:01 | FailedScheduling: 0/1 nodes are available: 1 Insufficient cpu |
| 17:08:01 | TriggeredScaleUp: pool from 1 to 2 nodes |
| 17:08:17 | TriggeredScaleUp: pool from 2 to 3 nodes (maximum) |
| 17:09:06 | second node Ready, about 65 s after the autoscaler’s decision |
| 17:09:11 | no job pod waiting for room |
| 17:09:27 | third node Ready |
At the peak the quota was at 6050m of 8 cores of requests and 27 of 32 cores of limits. All 14 jobs succeeded.

The chart comes from GitLab Observability, where an OpenTelemetry collector in the cluster sends node and pod metrics. The next post shows how we deployed it through the GitLab agent. CPU usage of all jobs together shows where the ceiling of a single node was:

Waiting for a node shows in job durations. A dind build on a warm node took 24–34 s. The same build, whose pod waited for a new node and pulled images from scratch, took 70–165 s. A CPU job with 240 s of work finished after 247–251 s without waiting and after 307–356 s with waiting. If that extra minute on a cold node bothers you, raise min_node_count during the team’s working hours or lower concurrent. Both cost money, so the choice depends on what the team’s waiting costs you.
Scaling down: from three nodes to two, not to one
The last test job finished at 17:16. The autoscaler started draining a node at 17:27, after about 10 minutes without load, and removed it at 17:31. It picked the first node of the cluster, not one of the added ones. The autoscaler takes the node that is easiest to empty, not the youngest.

The cluster did not get down to one node. The autoscaler status (kubectl -n kube-system get configmap cluster-autoscaler-status) showed scaleDown: NoCandidates. Both nodes still ran GKE system pods from the kube-system namespace: kube-dns, metrics-server, event-exporter and a few more. The autoscaler does not move kube-system pods that have no PodDisruptionBudget, and with two nodes kube-dns keeps two replicas, one per node. With no jobs you pay for two nodes instead of one.
A PodDisruptionBudget for those pods lets the autoscaler move them. The optimize-utilization autoscaling profile also removes nodes faster than the default one. In the lab we turn the whole cluster off after a session, so we did not change this.
Turning the cluster off after a session
There are two ways to turn the cluster off after a session. Both end with the same bill, because the network that may stay costs nothing. Where else the CI budget leaks on Kubernetes (right-sizing, scaling runners to zero, cache) is covered in a separate guide.
The first is the destroy job. The OpenTofu component adds it to the main pipeline as a manual job, so one click in the latest pipeline is enough. It removes everything in the lab state, network included. The code does not change and still says cluster_enabled = true, so in the next session you run the manual apply on main and OpenTofu rebuilds the network and the cluster from scratch, in a few to a dozen or so minutes. This is the simplest way when you need the cluster only now and then.
The second is a merge request with cluster_enabled = false and a manual apply on main, which is what we do in the lab. The cluster, the NAT and the nodes go away, and the network stays. The change is in the repository history with a description and an approval, and the plan in the merge request shows before the merge what exactly will be removed. In the next session you open the reverse merge request with true. Choose this one when something other than the cluster uses the network, or when every infrastructure change has to go through review.
Either way, the runner goes away with the cluster. Its registration in GitLab stays, so after the cluster is back you only need the Helm install. GitLab shows the runner token only once, so keep it in a password manager or create a new one with Reset token.
The same setup works on Kubernetes on your own servers, for example on RKE2. No autoscaler adds nodes there, so capacity is fixed, and job limits and ResourceQuota decide whether one heavy pipeline blocks everything else. That is how we moved runners from the Docker executor to Kubernetes in the project described separately.
Want Kubernetes runners in the cloud or on your own servers that do not take over the whole cluster? See how we set up CI/CD and automation. We are a GitLab partner, so we can help with licensing too.