04 - Runner for a Gateway Cluster
This is the second runner setup, for an operator running GitLab CI jobs on a tenant cluster created through the gateway when the cluster is not hosted on the operator's machine. You end up with a GitLab runner on the GitLab host that holds only a kubeconfig fetched with getKubeconfig at https://k8s.socialweb.computer and places job Pods into that user's tenant cluster through the kcp mount.
In 02, the runner runs on the kcp host and reaches the tenant apiserver on its loopback port using a client certificate, since that is where the apiserver binds. Here the cluster is not on the operator's host at all. The user created it through the gateway, nodes are rented from the compute market, and the only entry point is the URL returned by getKubeconfig.
See gateway.md for the createCluster and getKubeconfig calls, and the short form of this runner. For related context, see 01 for the kcp host and tenant cluster, 02 for the loopback runner, and 03 for the job side.
Contents
- Topology
- Runner Host
- Prerequisites
- Kubeconfig
- Required Cluster Objects
- Config File
- The GitLab Host
- Registering the Runner
- Running the Runner
- Verification
- Failure Modes
- Pause Pods
- The Exec Path Through the kcp Mount
Topology
The runner connects to the tenant cluster through these endpoints:
| Component | URL |
|---|---|
| Gateway API | https://k8s.socialweb.computer |
| kcp front | https://kcp.socialweb.computer |
| Cluster in a kubeconfig | https://kcp.socialweb.computer/clusters/root:<accountHash>:<cluster>:clusters |
<accountHash> is the first 8 characters of the base36 encoding of sha256(did) (internal/kcpclient/names.go, AccountHash). The mount path is root:<accountHash>:<cluster>:clusters (MountPath).
The kubeconfig authenticates with a client certificate and key issued by the cluster's OpenBao PKI for the user's DID, using whatever lifetime the user chose in getKubeconfig (up to 24 hours, or no expiry if requested):
users:
- name: <cluster>
user:
client-certificate-data: <PEM>
client-key-data: <PEM>
Plain kubectl and client-go use this kubeconfig directly with no extra plugins. The client certificate front at kcp.socialweb.computer admits the certificate while its ClusterClientCertificate exists and is not revoked, and grants it cluster-admin access in that tenant cluster.
Runner Host
Run the runner on the GitLab host (ssh gitlab). That keeps it off the kcp host, which is the point: nothing here needs 127.0.0.1:<leased port> or access to the operator's host because the kubeconfig carries both the URL and the certificate.
GitLab is also local to that host, so the runner's HTTPS connection to GitLab is direct with no extra network hop, and a runner binary is already installed and registered there (see The GitLab Host). Since the cluster sits behind a public HTTPS name, only the runner host needs to reach it.
Prerequisites
Make sure the following are in place before configuring the runner:
- The GitLab host resolves and reaches
kcp.socialweb.computer. - Outbound HTTPS from the GitLab host to the internet.
- A user account, a cluster created through the gateway, and the kubeconfig from
getKubeconfig(no helper is needed on the runner host). - A GitLab project for running jobs, with a runner registered to it.
No operator-managed RBAC is needed because the user is cluster-admin in their own cluster. See Required Cluster Objects for what the user still has to apply.
Kubeconfig
getKubeconfig returns a single kubeconfig file. Install it on the runner host so only the runner's user can read it:
sudo install -d -m 0700 /etc/gitlab-runner/tenant-ci
sudo install -m 0600 <cluster>.kubeconfig.yaml /etc/gitlab-runner/tenant-ci/kubeconfig.yaml
Verify it before pointing a runner at it:
export KUBECONFIG=/etc/gitlab-runner/tenant-ci/kubeconfig.yaml
kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}'; echo
kubectl auth can-i create pods --namespace gitlab-runner
kubectl auth can-i create pods/exec --namespace gitlab-runner
kubectl get nodes
The server output should be the kcp mount URL rather than a raw address, and both can-i checks should return yes (as they will for every other action). get nodes should return No resources found because an idle cluster has no nodes at rest. A node is provisioned only when a Pod cannot be placed, so an empty node list is healthy.
Certificate Rotation
The certificate uses the lifetime chosen in getKubeconfig, either up to 24 hours (the gateway rejects anything under 60 seconds or over 24 hours) or no expiry when requested. Once it expires, the client certificate front returns 401 and every job fails at authentication.
To rotate credentials, download a new kubeconfig and overwrite the file. Nothing else in the runner config changes. Revoking a certificate blocks it at the front within a second, so for a long-lived runner you can request a kubeconfig with no expiry and revoke it when the runner is retired.
KUBECONFIG Environment Variable
The Kubernetes executor has no kubeconfig config key. It loads the kubeconfig via client-go from the environment of the gitlab-runner process itself (see Cluster Config Resolution).
Do not use environment = [...] under [[runners]]. That setting injects variables into the build environment inside the job container (common/config.go: "Custom environment variables injected to build environment") rather than into the runner process.
Required Cluster Objects
You need to apply the gitlab-runner namespace beforehand, and if you enable pause pods, you also need to apply a PriorityClass.
First, create the namespace:
apiVersion: v1
kind: Namespace
metadata:
name: gitlab-runner
The runner does not create this namespace. setupBuildNamespace returns immediately unless namespace_per_job = true (executors/kubernetes/kubernetes.go), so with the default setting the configured namespace must exist ahead of time or every job fails with namespaces "gitlab-runner" not found.
Second, if the user enables pause pods, apply the PriorityClass they configure (priorityclasses is cluster-scoped):
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: gitlab-pause
value: -10
globalDefault: false
description: "Pause pods, below job pods, so a job preempts one."
Cluster-Admin Permissions
This runner uses the client certificate embedded in the kubeconfig from getKubeconfig, which differs from the credential setup in 01:
| Setup in 01 | This setup |
|---|---|
| Client certificate from the ClientCA, with CommonName and Organizations chosen by the operator | Client certificate from the cluster's OpenBao PKI, with CommonName set to the user's DID and group socialweb.computer:cluster-owners |
| Identity and all RBAC rules controlled by the operator | Cluster-admin by default, because the owner group is bound to cluster-admin |
Checked with kubectl auth can-i ... --as=gitlab-runner --as-group=gitlab-runner | kubectl auth can-i '*' '*' answers yes |
Because the certificate has cluster-admin access, the 403 failures listed in 02's failure table cannot happen here. The flip side is that mistakes RBAC would normally block will succeed: a job can delete nodes, rewrite ClusterRole bindings, or read every Secret in the tenant cluster. There is no scoped variant of this setup, and the operator does not hold the key needed to mint one.
Config File
Use the same config file described in 02 (~/.gitlab-runner/config.toml on the GitLab host, or /etc/gitlab-runner/config.toml when running as a service). Only the connection block differs. For the full annotated file and node-size fit details, see 02. Here is the concise version:
concurrent = 2
check_interval = 3
[[runners]]
name = "kcp-tenant-kubernetes"
url = "https://gitlab.dorper-matrix.ts.net:8443/"
token = "<<runner authentication token>>"
executor = "kubernetes"
run_untagged = false
tag_list = ["kcp-tenant"]
# Runs AFTER the clone, before the job's script. A STRING, not an array.
pre_build_script = "if ! command -v pnpm >/dev/null 2>&1 && command -v npm >/dev/null 2>&1; then npm install -g pnpm@10.11.0; fi; true"
# Kilobytes. Default is 4096, which is 4 MiB and is not enough for a Go test log.
output_limit = 51200
[runners.kubernetes]
# No host, no cert_file, no key_file, no ca_file. The kubeconfig carries all of those,
# and setting host would make the executor ignore the kubeconfig.
namespace = "gitlab-runner"
image_pull_policy = "if-not-present"
cpu_request = "100m"
memory_request = "128Mi"
cpu_limit = "10"
memory_limit = "20Gi"
helper_cpu_request = "100m"
helper_memory_request = "128Mi"
helper_cpu_limit = "1"
helper_memory_limit = "1Gi"
# Seconds for the Pod to reach Running: a rented node boots, then the image pulls.
poll_timeout = 3600
cleanup_grace_period_seconds = 30
[runners.kubernetes.affinity]
[runners.kubernetes.affinity.pod_anti_affinity]
[[runners.kubernetes.affinity.pod_anti_affinity.required_during_scheduling_ignored_during_execution]]
topology_key = "kubernetes.io/hostname"
[runners.kubernetes.affinity.pod_anti_affinity.required_during_scheduling_ignored_during_execution.label_selector]
[[runners.kubernetes.affinity.pod_anti_affinity.required_during_scheduling_ignored_during_execution.label_selector.match_expressions]]
key = "project.runner.gitlab.com/id"
operator = "Exists"
Settings
Each setting in the config above (including the ones left unset) serves a specific role:
| Key | Value here | Why |
|---|---|---|
concurrent | 2 | Maximum jobs in flight at once. Each concurrent job rents a node, so this setting controls cost directly. Set it to the number of nodes the user will pay for. Note that 1 still wedges on a stale job from a cancelled pipeline. |
check_interval | 3 | Polling interval against GitLab, in seconds. |
run_untagged / tag_list | false / ["kcp-tenant"] | The GitLab host also runs an online instance runner with run_untagged, which could pick up untagged jobs before this runner does. Tag this runner and tag its projects accordingly. |
pre_build_script | pnpm guard | Runs after the clone and before the job's script. Must be a string, not an array. Holds the pnpm/corepack guard. |
output_limit | 51200 | Trace cap in kilobytes. The runner's default of 4096 (4 MiB) is too small for a Go test log. |
host | not set | Leaving it empty selects the kubeconfig path. Any non-empty host forces the out-of-cluster config path and ignores the kubeconfig. |
cert_file / key_file / ca_file | not set | The kubeconfig already provides the client certificate and CA. |
namespace | gitlab-runner | Target namespace for job Pods. Must exist beforehand. See Required Cluster Objects. |
image_pull_policy | if-not-present | Uses images pre-seeded on the node image when available. The seed list comes from the rented node image, not the operator. |
cpu_request / memory_request | 100m / 128Mi | Used by the scheduler for placement. A request larger than any rented node size leaves the Pod stuck forever and runs up a market bill for an unused node. |
cpu_limit / memory_limit | 10 / 20Gi | Enforcement caps, not placement inputs. |
helper_*_request / helper_*_limit | see file | A limit with no explicit request becomes the request. |
poll_timeout | 3600 | Seconds allowed for the Pod to reach Running. The first Pod waits for the market to win an RFP, boot a VM, join the cluster, and pull the image, which takes several minutes. |
| anti-affinity | required | Enforces one job per rented node to match the cost model. |
[runners.kubernetes.autoscaler] | not set | Pause pods configuration. See Pause Pods. |
The GitLab Host
GitLab 19.2.7-ce.0 runs in a container with external_url https://gitlab.dorper-matrix.ts.net:8443 and publishes ports 80 and 22 on the host. gitlab.dorper-matrix.ts.net is exposed through Tailscale Funnel, so the name resolves in public DNS and :8443 answers from outside the tailnet.
gitlab-runner 19.2.1 is installed at /home/johnandersen777/bin/gitlab-runner from the GitLab package repository, with its config at ~/.gitlab-runner/config.toml (mode 0600). /etc/gitlab-runner/ does not exist on this host, so create it if you move the runner to a system service. kubectl is not installed because only manual verification needs it, not the runner itself.
Three runners are registered in GitLab:
| id | description | type | state |
|---|---|---|---|
| 1 | socialwebcomputer | instance_type | online, executor = "instance" with the Fleeting plugin, tag socialwebcomputer, run_untagged = false |
| 2 | kcp-tenant-kubernetes | project_type, project 5 | offline |
| 3 | kcp-tenant-kubernetes-streamplace | project_type, project 1 | offline |
Runners 2 and 3 are already registered with the right configuration. They are offline only because config.toml currently configures runner 1 alone. Runner 1 uses a different mechanism (renting VMs via request-vm-ssh and running jobs over SSH) and must not overlap with this runner for the same jobs.
Registering the Runner
Skip this section if you are reusing runners 2 and 3. These are manual operator steps, not a script.
In the project's Settings > CI/CD > Runners, create a runner tagged kcp-tenant, uncheck "Run untagged jobs", and copy the authentication token. On the GitLab host, run:
gitlab-runner register \
--non-interactive \
--config ~/.gitlab-runner/config.toml \
--url https://gitlab.dorper-matrix.ts.net:8443/ \
--token <runner authentication token> \
--executor kubernetes \
--tag-list kcp-tenant \
--run-untagged=false
Replace the generated [runners.kubernetes] block with the one from Config File above (register writes little beyond the token and executor).
Runners 2 and 3 use the same command with tokens from johnandersen777/kcp-ci-probe (id 5) and streamplace/streamplace (id 1). Their existing tokens are stored only in GitLab and not in any config file on this host, so re-registering will issue new tokens.
Running the Runner
KUBECONFIG must be set in the runner process environment.
Under systemd, open a unit override:
sudo systemctl edit gitlab-runner
Add the environment variable to the [Service] block:
[Service]
Environment=KUBECONFIG=/etc/gitlab-runner/tenant-ci/kubeconfig.yaml
Or run the runner in the foreground from the operator's shell:
export KUBECONFIG=/etc/gitlab-runner/tenant-ci/kubeconfig.yaml
gitlab-runner run --config ~/.gitlab-runner/config.toml --working-directory /var/lib/gitlab-runner
Runner 1 accepts only jobs tagged socialwebcomputer, so it will not compete for untagged jobs. Still, tag this runner's jobs with kcp-tenant.
Verification
Run three checks in order. The first two are free, and the third boots a rented node.
1 Config Decoding
Check the runner's own output rather than GitLab's UI:
FATAL: Service run failed error=decoding configuration file: toml: line 9
Any FATAL error on startup means the process exited, even if GitLab still displays the runner as online.
2 Kubeconfig Access
Check the kubeconfig directly with kubectl:
export KUBECONFIG=/etc/gitlab-runner/tenant-ci/kubeconfig.yaml
kubectl get nodes # No resources found
kubectl get ns gitlab-runner # the namespace the user applied
At rest, get nodes stays empty because the cluster has no always-on node. Next, run 03's probe with the runner's tag:
prove-placement:
stage: prove
tags: [kcp-tenant]
image: busybox:1.36
script:
- echo "running on $(hostname)"
3 Node Provisioning and Scale-to-Zero
Watch pods and nodes while the probe job runs:
kubectl get pods -n gitlab-runner -o wide -w
kubectl get nodes -w
A successful run goes through these states:
the job pod exists, Pending, cluster at zero nodes
the scale decision read Provision: intent and no node
a node joins on demand and becomes Ready
the job pod is placed on it and runs
the job finishes success
the job pod is gone
the cluster is back at zero nodes (kubectl get nodes is empty again)
The wait between "pod Pending" and "node Ready" takes minutes because it includes a market round trip and a VM boot. That delay is expected, not a stall.
Failure Modes
The config-file failures in 02's table still apply. This table covers issues specific to this setup, listed in the order they usually show up:
| Symptom | Cause |
|---|---|
invalid configuration: no configuration has been provided at runner startup | KUBECONFIG is missing from the runner process environment. [[runners]] environment = [...] does not reach the runner. |
the server has asked for the client to provide credentials or Unauthorized | The certificate expired or was revoked, or the account no longer owns the cluster. Download a fresh kubeconfig. |
| Runner talks to the wrong cluster or a local cluster | host is still set in [runners.kubernetes], or KUBERNETES_SERVICE_HOST is set because the runner itself runs inside a cluster. With host empty, the executor tries in-cluster config before the kubeconfig. |
| Job hangs at "Preparing the environment" | The SPDY upgrade to pods/exec did not survive the kcp mount. See The Exec Path Through the kcp Mount. |
namespaces "gitlab-runner" not found | The namespace was not applied beforehand. The runner does not create it. |
Job stays pending, no node appears | No node was rented, or the market lost the RFP. Compare kubectl get pods -A with kubectl get nodes. A Pending Pod unseen by the scale decision indicates the provider is not running. |
Pod Pending for minutes, then Running | Normal. A rented node has to boot, and poll_timeout must be large enough to cover it. |
Pod Pending forever on an existing node | Pod requests do not fit the rented node size. Check 02's note on limits acting as requests when no request is set. |
ImagePullBackOff after a node boot | The image does not exist, or the rented node cannot reach its registry. Running 03's curl check first avoids paying for a node boot. |
Job fails during clone with Could not resolve host | Node-local CoreDNS is not answering on 169.254.20.10. Run kubectl -n kube-system get pods -l app.kubernetes.io/name=socialweb-node-dns -o wide. If none exists on the node, either the node is missing the socialweb.computer/node-local-dns=true label (older user_data) or the DaemonSet was never applied (the provider's add-on pass logs applied the node network add-ons). See 03. |
Job fails during clone with unable to access '...' after DNS resolves | CI_REPOSITORY_URL points to a GitLab unreachable from the rented node's provider egress. A GitLab served only on a tailnet (https://gitlab.dorper-matrix.ts.net:8443, observed 2026-11-25: clone timed out after 2 minutes and failed) cannot be reached from a job Pod. Publish GitLab on a publicly reachable name, or set GIT_STRATEGY: none (the job then succeeds because the runner, not the Pod, sends traces to GitLab). |
| Cluster never returns to zero | A non-job Pod remains Pending, usually a pause pod (see below). |
Job's first request returns Forbidden | Should never happen because the certificate is cluster-admin. If it does, the owner group binding changed. |
Pause Pods
03's pause pods work the same way here, except they cost more because nodes are rented instead of running on operator hardware. In 19.2.1, the configuration looks like this:
[runners.kubernetes.autoscaler]
max_pause_pods = 1
pause_pod_image = "registry.k8s.io/pause:3.10"
pause_pod_priority_class_name = "gitlab-pause"
[[runners.kubernetes.autoscaler.policy]]
idle_count = 0
idle_time = "1m"
Because a pause pod is a Pending Pod that is not a k3s addon, the scale decision counts it as scheduling intent and rents a node for it. The cluster will never return to zero while a pause pod exists. To work around this, schedule idle_count = 0 outside working hours via cron on the runner. This is a runner setting, not a cluster setting.
Do not leave
idle_count > 0running 24x7 on a cluster with billed nodes.
The Exec Path Through the kcp Mount
The Kubernetes executor creates Pods and then attaches to the build container with an HTTP upgrade (POST /api/v1/namespaces/<ns>/pods/<pod>/exec with Connection: Upgrade and Upgrade: SPDY/3.1, in executors/kubernetes/exec.go). That request travels from the runner to kcp.socialweb.computer, through Caddy, into kcp, and out to the tenant apiserver.
Because the kcp mount is a reverse proxy, README.md notes that a client certificate does not survive passing straight through it. Caddy handles the credential side by routing requests carrying a client certificate to the client certificate front. For the upgrade side, scripts/deploy.sh configures the kcp vhost with flush_interval -1 and a transport http block set to versions 1.1, forcing Caddy to speak HTTP/1.1 to kcp so the SPDY upgrade succeeds. Without versions 1.1, Caddy fails the upgrade with 502 Bad Gateway.
When the upgrade fails, the job hangs at "Preparing the environment" while the Pod sits Running: Pod creation succeeded, but attach never completes.
Cluster Config Resolution
From executors/kubernetes/util.go in gitlab-runner v19.2.1:
func getKubeClientConfig(config *common.KubernetesConfig, overwrites *overwrites) (*restclient.Config, error) {
if config.Host != "" {
kubeConfig, err = getOutClusterClientConfig(config)
} else {
kubeConfig, err = guessClientConfig(config)
}
...
}
This produces three behaviors. Setting host = "" selects the kubeconfig path, while any non-empty host takes the other branch and never reads the kubeconfig. In the kubeconfig branch, clientcmd.NewDefaultClientConfigLoadingRules() uses client-go's standard precedence ($KUBECONFIG, then ~/.kube/config), which is why KUBECONFIG must be a process environment variable rather than a config key. InClusterConfig() also runs before the kubeconfig loader and wins if it succeeds, so it fails on the GitLab host (where KUBERNETES_SERVICE_HOST is unset) and would succeed if the runner ran inside a Pod.