One of the biggest topics in CI/CD is how to scale Gitlab Runners and make them Highly Available. Whatever may happen server-side, developers should experience minimal to no service disruption.

Exoscale Instance Pools allow you to deploy a set of identical Instances, that can be subsequently scaled horizontally. That makes an easy setup to achieve an Highly Available Gitlab Runners infrastructure.

We will deploy an Instance Pool of three managed Gitlab Runners on Compute Instances, relying on a preconfigured Cloud-init. You can use this model both on a managed Gitlab.com account or on a self-hosted Gitlab account.

Combine Exoscale Instance Pools with Gitlab runners

Register new Runners on Gitlab

To register a new Runner on Gitlab we first need a registration token that we will then provide to all instances managed by the Instance Pool using Cloud-init.

Get your registration token by going in a Gitlab project.

Settings > CI/CD.

Copy the token in 3. like on the following screenshot (where the red arrow is pointing).

token

Configure Cloud-init to install new Gitlab Runners

Cloud-init will be used to install and start all the needed components transparently at instance creation.

Create a gitlab-runners.init file with the following Cloud-init commands:

Note

Remember to paste your registration token into --registration-token flag.

If you are using the managed https://gitlab.com service you can leave the --url flag as in the example. Otherwise point it to your self-hosted Gitlab adress (e.g. https://gitlab.self-hosted.com).

#cloud-config
runcmd:

#Install Docker on the instance
- curl -sSL https://get.docker.com | sh

#Register the new Runner to your Gitlab account
- >
  docker run --rm -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register
  --non-interactive
  --executor "docker"
  --docker-image alpine:latest
  --url "https://gitlab.com/"
  --registration-token "XXXXXXXXX"
  --description "docker-runner"
  --tag-list "docker,instance-pool,exoscale"
  --run-untagged="true"
  --locked="false"
  --access-level="not_protected"

#Run the Gitlab Runner demon
- >
  docker run -d --name gitlab-runner --restart always
  -v /srv/gitlab-runner/config:/etc/gitlab-runner
  -v /var/run/docker.sock:/var/run/docker.sock
  gitlab/gitlab-runner:latest

While in this example we make all the configuration through Cloud-init, we recommend you to create a custom template for production purposes, pre-installing Docker engine and use Cloud-init only to start the Runner service.

Create the Instance Pool containing the Gitlab Runners

By starting an Instance Pool of 3 instances with the previous Cloud-init configuration, a pool of Gitlab Runners will be created and managed for you.

$ exo instancepool \
    create gitlab-runners \
    --description "Gitlab Runners of 3 instances" \
    --size 3 \
    --zone de-fra-1 \
    --service-offering medium \
    --template "Linux Ubuntu 18.04 LTS 64-bit" \
    --cloud-init gitlab-runners.init

Congratulation your managed Gitlab Runners are running!

$ exo instancepool show gitlab-runners --zone de-fra-1
┼──────────────────┼───────────────────────────────┼
│ ID               │ 43857934-3b38-a961-f489-8af3  │
│ Name             │ gitlab-runners                │
│ Description      │ Gitlab Runners of 3 instances │
│ Service Offering │ Medium                        │
│ Template         │ Linux Ubuntu 18.04 LTS 64-bit │
│ Zone             │ de-fra-1                      │
│ Security Groups  │ default                       │
│ Privnets         │ n/a                           │
│ SSH Key          │ pierre                        │
│ Size             │ 3                             │
│ Disk Size        │ 50 GiB                        │
│ State            │ running                       │
│ Instances        │ pool-2db9b-xggaz              │
│                  │ pool-2db9b-zekbt              │
│                  │ pool-2db9b-ndxtu              │
┼──────────────────┼───────────────────────────────┼

You should see the Runners appear in Gitlab automagically! runners

You can now scale up or down the Instance Pool, and the new Gitlab Runners will appear in Gitlab.

$ exo instancepool \
    update gitlab-runners \
    --zone de-fra-1 \
    --description "Gitlab Runners of 5 instances" \
    --size 5
┼──────────────────┼───────────────────────────────┼
│ ID               │ 2db9b0cd-3b38-a961-f489-8af3  │
│ Name             │ gitlab-runners                │
│ Description      │ Gitlab Runners of 5 instances │
│ Service Offering │ Medium                        │
│ Template         │ Linux Ubuntu 18.04 LTS 64-bit │
│ Zone             │ de-fra-1                      │
│ Security Groups  │ default                       │
│ Privnets         │ n/a                           │
│ SSH Key          │ pierre                        │
│ Size             │ 5                             │
│ Disk Size        │ 50 GiB                        │
│ State            │ scaling-up                    │
│ Instances        │ pool-2db9b-xggaz              │
│                  │ pool-2db9b-zekbt              │
│                  │ pool-2db9b-ndxtu              │
┼──────────────────┼───────────────────────────────┼

new-runner