Skip to content

2. Deploy Gitlab Agent + Runner on MicroK8S

Original Author: Sara Jokela
Last updated by Jesse Anttila
Last checked by Jesse Anttila
Lastmod: 23.10.2025
Status: OK

Notes#

NOTE: This Notes section contains old info, it is safe to skip. Leaving it as is for now.

This guide is based on the following resources:

It is recommended to go through those guides beforehand!

Next steps: commands for getting floating IP address and domain name in .gitlab-ci.yml instead of adding them as static variables.

Introduction#

Introduction here

Prerequisites#

Adding Kubernetes Agent#

1. Connect a cluster#

Create a new GitLab project. You can name it anything you want, for example simple-service-agent-runner. You can use this same project in the following Setting Up a Service guide as well.

Inside your GitLab project, from the left side panel, choose Operate -> Kubernetes clusters. After that, click Connect a cluster.

Navigating GitLab

Connect a cluster

2. Create an agent#

Create a new agent with Option 2: Create and register agent with the UI. Give a name for your agent, and click Create and register.

Creating new agent

You'll get an agent access token, which is something like "glagent-abcxyz123". GitLab also generates commands that are used to install the Agent to your virtual machine. Run these commands in your virtual machine one by one.

Commands and token

If the installation was successful, you should see following message:

Successfull installation

Go back to your GitLab project and check the Kubernetes tab. Your agent should be connected.

Connected agent

Adding a Gitlab Runner to the project#

Runners are responsible for running CI/CD tasks in Gitlab. You get some by default with Jamk Gitlab, but those are shared by everyone at Jamk, you may have to get in really long queues waiting for your tasks to run.. To avoid that, you can install your own custom runner which will run on the Kubernetes setup

1. Create a runner#

From the side panel in GitLab, choose Settings -> CI/CD -> Runners, then click New project runner.

Adding new runner

While creating new runner, select Run untagged jobs under Tags. Then, click Create runner.

Select Run untagged jobs

You should be now on a tab called Register runner.

You are given a runner authentication token on this page, under Step 1 section. It is something like "glrt-abcdxyz123". Save the runner authentication token somewhere, you will need it soon.

Choose Linux for operating system.

Before you can register the runner, you have to install gitlab-runner on your virtual machine. You can find the commands for that by clicking How do I install GitLab Runner? However, change the output destination /usr/local/bin/gitlab-runner to /usr/bin/gitlab-runner so sudo can easily find it. Remember to also change the architecture to match your setup. Installation commands for amd64 architecture:

Download binary:

sudo curl -L --output /usr/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

Give permissions to execute:

sudo chmod +x /usr/bin/gitlab-runner

Create a "GitLab Runner" user:

sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

Install:

sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner

Start as a service:

sudo gitlab-runner start

Registering runner

Now, continue with the two steps shown on the GitLab Register runner page.

If registering process asks for an URL, use https://gitlab.labranet.jamk.fi.

For an executor, choose Kubernetes.

2. Installing the runner with Helm#

Go to your virtual machine, and create a values.yaml file in your users home folder. Add following values and paste your runner token to the runnerRegistrationToken.

gitlabUrl: https://gitlab.labranet.jamk.fi/

runnerRegistrationToken: <YOUR REGISTRATION TOKEN>

concurrent: 10

checkInterval: 30

rbac:
  create: true
  rules:
    - apiGroups: [""]
      resources: ["pods"]
      verbs: ["list", "get", "watch", "create", "delete"]
    - apiGroups: [""]
      resources: ["pods/exec"]
      verbs: ["create"]
    - apiGroups: [""]
      resources: ["pods/log"]
      verbs: ["get"]
    - apiGroups: [""]
      resources: ["pods/attach"]
      verbs: ["list", "get", "create", "delete", "update"]
    - apiGroups: [""]
      resources: ["secrets"]
      verbs: ["list", "get", "create", "delete", "update"]
    - apiGroups: [""]
      resources: ["configmaps"]
      verbs: ["list", "get", "create", "delete", "update"]

runners:
  privileged: true

  config: |
    [[runners]]
      [runners.kubernetes]
        namespace = "gitlab"
        tls_verify = false
        image = "docker:19"
        privileged = true

3. Runner Helm chart#

Next, we install the runner with Helm. Make sure that Helm repository is added and updated.

helm repo add gitlab https://charts.gitlab.io
helm repo update gitlab

Create a dedicated namespace for GitLab runner.

kubectl create namespace gitlab

And finally install a Helm chart:

helm install --namespace gitlab gitlab-runner gitlab/gitlab-runner -f values.yaml

A Helm chart is a structured bundle of files that describe a Kubernetes application, including how to install, configure, and manage it.

--namespace gitlab flag tells Helm which Kubernetes namespace to install the resources into. All pods, deployments, etc. created by this Helm release will live in the namespace called gitlab.

gitlab-runner is the release name, a name chosen for this specific installation of the chart.

gitlab/gitlab-runner is the chart reference, which tells Helm which chart to install and from where. In this case, gitlab refers to the Helm repository we added earlier, and gitlab-runner is the chart name inside that repository.

If the installation was successful, you should see following output:

Successfull installation

You can check the installed runner "release" with the following command, which makes Helm list all releases that are deployed in the "gitlab" namespace.

helm list -n gitlab

helm list -n gitlab output

NOTE: You can disable the gitlab-runner because it is not needed since we are also installing the runner with helm. Kubernetes agent only needs one runner active at a time

sudo systemctl stop gitlab-runner
sudo systemctl disable gitlab-runner

Resources#