GitLab Runners inMiniKube

Fernando Karnagi
DevOps Configuration Experiences
4 min readJul 28, 2024

What a wonderful Sunday afternoon, accompanied with Toastbox Kopi-C Siew Dai, and “Nothing’s Gonna Change My Love You” https://music.youtube.com/playlist?list=OLAK5uy_nGzQNyE5R0ipIhXCG_JNemAQl1C9s7PTY&si=SMwjbKNYKdd1Ct1i, having ‘me’ time with Minikube and GitLab.

This story is about sharing a bit of experience of mine running GitLab runners in Minikube K8S.

Install Minikube

First of all, I need to install the minikube in my Google Cloud

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64

Once installed, start it

minikube start

Let’s do a test to make sure this K8S is in operation.

Deploy this

kubectl apply -f 04_nginx.yaml

Content of 04_nginx.yaml

apiVersion: v1
kind: Namespace
metadata:
name: test
---

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: test
spec:
selector:
matchLabels:
app: nginx
replicas: 1 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

Check the Pod

kubectl -n test get all

We have just verified the Minikube is up and running.

Delete that testing workload

kubectl delete -f 04_nginx.yaml

Install Helm and Repo

Let’s install Helm installer

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

Add gitlab-runner Helm Repo

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

Create GitLab Runner

Let’s create the runner in GitLab project

Click “Create runner”

Remember the token, coz you are going to use that in the GitLab Runner Helm Release.

Now, release the Helm. Here is the values.xml

# The GitLab Server URL (with protocol) that you want to register the runner against
# ref: https://docs.gitlab.com/runner/commands/index.html#gitlab-runner-register
#
gitlabUrl: https://gitlab.com/

# The registration token for adding new runners to the GitLab server
# Retrieve this value from your GitLab instance
# For more info: https://docs.gitlab.com/ee/ci/runners/index.html
#
runnerRegistrationToken: "glrt--xxxxx"

# For RBAC support:
rbac:
create: true

# Run all containers with the privileged flag enabled
# This flag allows the docker:dind image to run if you need to run Docker commands
# Read the docs before turning this on:
# https://docs.gitlab.com/runner/executors/kubernetes/index.html#using-dockerdind
runners:
privileged: true
helm install --namespace gitlabrunner --create-namespace -f values.yaml gitlab-runner gitlab/gitlab-runner

Helm has been successfully released.

Helm Verification

Let’s verify the Helm

helm --namespace gitlabrunner get all gitlab-runner

Verify the Pod

kubectl -n gitlabrunner get all

Verify the Pod log

kubectl -n gitlabrunner logs -f pod/gitlab-runner-5644f85db8-x6dhq

Lastly, verify the Runner itself

Run Pipeline in This Runner

Now, try running pipeline in this Runner.

I prepared a simple pipeline yaml as shown below.

stages:
- prep
- build

prep:
stage: prep
script:
- apt-get update
- apt-get -y install jq
- cat package.json | jq -r '.version' > version.txt
- cat version.txt
image: ubuntu:22.04
only:
- main
artifacts:
paths:
- version.txt
expire_in: 1 hour
tags:
- k8s

build:
stage: build
script:
- rm -Rf .git
- npm config set unsafe-perm true
- yarn
image: node:14.21
only:
- main
artifacts:
paths:
- .
expire_in: 1 hour
tags:
- k8s

Let’s run it.

During the run, let’s inspect the Pod.

New Pod runs, that’s the Pod that runs the job, spawned by the runner Pod.

It runs with ubuntu:22.04, as what is specified in the pipeline yaml file.

The pipeline has been executed successfully

Thanks folks for reading my story, let me know your thought :)

--

--