[Kubernetes (K8S)] Helm install GitLab Runner that works with GitLab CI/CD to run jobs in a pipeline within Kubernetes (K8S)

GitLab Runner

GitLab Runner is an application that works with GitLab CI/CD to run jobs in a pipeline.

GitLab Runner has the following features.

  • Run multiple jobs concurrently.

  • Use multiple tokens with multiple servers (even per-project).

  • Limit the number of concurrent jobs per-token.

  • Jobs can be run:

    • Locally.

    • Using Docker containers.

    • Using Docker containers and executing job over SSH.

    • Using Docker containers with autoscaling on different clouds and virtualization hypervisors.

    • Connecting to a remote SSH server.

  • Is written in Go and distributed as single binary without any other requirements.

  • Supports Bash and Windows PowerShell.

  • Works on GNU/Linux, macOS, and Windows (pretty much anywhere you can run Docker).

  • Allows customization of the job running environment.

  • Automatic configuration reload without restart.

  • Easy to use setup with support for Docker, Docker-SSH, Parallels, or SSH running environments.

  • Enables caching of Docker containers.

  • Easy installation as a service for GNU/Linux, macOS, and Windows.

  • Embedded Prometheus metrics HTTP server.

  • Referee workers to monitor and pass Prometheus metrics and other job-specific data to GitLab.

This article is about how to use Helm to deploy GitLab Runner on Kubernetes (K8S).

Prerequisites

  • Kubernetes (K8S)
    Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.

    For more information about installing and using Kubernetes (K8s), see the Kubernetes (K8s) Docs.

  • Helm
    Helm is the best way to find, share, and use software built for Kubernetes.

    For more information about installing and using Helm, see the Helm Docs.

Installation

Custom Values.yaml

Remember to replace content within {{ }} with your prefer values.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# values.yaml

# values.yaml · master · GitLab.org / charts / GitLab Runner · GitLab
# https://gitlab.com/gitlab-org/charts/gitlab-runner/-/blob/master/values.yaml

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

## The Registration Token for adding new Runners to the GitLab Server. This must
## be retrieved from your GitLab Instance.
## ref: https://docs.gitlab.com/ce/ci/runners/README.html
##
runnerRegistrationToken: {{ .Values.runnerRegistrationToken }}

runners:
config: |
[[runners]]
[runners.kubernetes]
image = "ubuntu:16.04"

## Specify whether the runner should be locked to a specific project: true, false. Defaults to true.
##
# locked: true

## Specify the tags associated with the runner. Comma-separated list of tags.
##
## ref: https://docs.gitlab.com/ce/ci/runners/#use-tags-to-limit-the-number-of-jobs-using-the-runner
##
tags: {{ .Values.runners.tags }}

# Specify the name for the runner.
#
name: {{ .Values.runners.name }}

## Specify whether the runner should only run protected branches.
## Defaults to False.
##
## ref: https://docs.gitlab.com/ee/ci/runners/#prevent-runners-from-revealing-sensitive-information
##
protected: true

# If Gitlab is not reachable through $CI_SERVER_URL
#
# DEPRECATED: See https://docs.gitlab.com/runner/install/kubernetes.html#additional-configuration
cloneUrl: {{ .Values.runners.cloneUrl }}

## Run all containers with the privileged flag enabled
## This will allow the docker:dind image to run if you need to run Docker
## commands. Please read the docs before turning this on:
## ref: https://docs.gitlab.com/runner/executors/kubernetes.html#using-dockerdind
##
## DEPRECATED: See https://docs.gitlab.com/runner/install/kubernetes.html#additional-configuration
# privileged: false


## For RBAC support:
rbac:
create: true

## Run the gitlab-bastion container with the ability to deploy/manage containers of jobs
## cluster-wide or only within namespace
clusterWideAccess: true

Install by Helm

Helm install gitlab-runner into gitlab-runner namespace.

1
2
3
4
5
6
7
8
9
10
11
# crate namespace:
$ kubectl create namespace gitlab-runner

# Add the Helm repository:
$ helm repo add gitlab https://charts.gitlab.io

# Update your local Helm chart repository cache:
$ helm repo update

# To install Helm chart:
$ helm install gitlab-runner gitlab/gitlab-runner --namespace gitlab-runner -f values.yaml

See Helm release about gitlab-runner.

1
2
3
$ helm list --namespace gitlab-runner
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
gitlab-runner gitlab-runner 4 2020-09-19 09:30:53.392689 +0800 +0800 deployed gitlab-runner-0.22.0 13.5.0

See pods about gitlab-runner.

1
2
3
$ kubectl get pods -n gitlab-runner
NAME READY STATUS RESTARTS AGE
gitlab-runner-gitlab-runner-66db9ddf6b-4pmqg 1/1 Running 0 12h

References

[1] GitLab Runner Helm Chart | GitLab - https://docs.gitlab.com/runner/install/kubernetes.html

[2] values.yaml · master · GitLab.org / charts / GitLab Runner · GitLab - https://gitlab.com/gitlab-org/charts/gitlab-runner/-/blob/master/values.yaml

[3] GitLab Runner部署(kubernetes环境)-博客 - http://www.soolco.com/post/76550_1_1.html

[4] GitLab Runner | GitLab - https://docs.gitlab.com/runner/

[5] Helm - https://helm.sh/

[6] Kubernetes - https://kubernetes.io/