Using the GitLab Kubernetes extension
- compute
- object-storage
- reverse
- proxy
- application
- GitLab
- Kubernetes
GitLab Kubernetes integration - Overview
GitLab provides a built-in Kubernetes Integration that allows you to build, test, deploy, and run your app at scale.
In this tutorial you will learn how to use the gitlab
Kubernetes integration using a Scaleway Instance.
The instance will be deployed using the Scaleway gitlab
InstantApp.
You may need certain IAM permissions to carry out some actions described on this page. This means:
- you are the Owner of the Scaleway Organization in which the actions will be carried out, or
- you are an IAM user of the Organization, with a policy granting you the necessary permission sets
- You have created an Instance running the
gitlab
InstantApp. - You have created a Kapsule cluster.
- You have downloaded the corresponding kubeconfig file and kubectl is working
- You have the Helm client installed
Configuring GitLab runner using Helm charts
Installing helm
In this tutorial we use helm
to deploy a gitlab
runner on a Kapsule
cluster.
If you do not know how to install helm
, please follow the tutorial on the official helm
website.
On the example below we have successfully installed helm
version 3.2.0
helm versionversion.BuildInfo{Version:"v3.2.0", GitCommit:"e11b7ce3b12db2941e90399e874513fbd24bcb71", GitTreeState:"clean", GoVersion:"go1.13.10"}
The helm
charts are provided through repositories. By default helm
3 does not have any repository configured.
We will add the gitlab
repository, as it provides the necessary chart to install the runner.
helm repo add gitlab https://charts.gitlab.io"gitlab" has been added to your repositorieshelm repo updateHang tight while we grab the latest from your chart repositories......Successfully got an update from the "gitlab" chart repositoryUpdate Complete. ⎈ Happy Helming!⎈
Installing GitLab runners using Helm
A helm
chart is always shipped with a value.yaml
file. It can be edited to customize the deployement of the application.
In this part of the tutorial we customize the value.yaml
to fit our needs and deploy the runner on kapsule
.
-
Get the value.yaml :
wget https://gitlab.com/gitlab-org/charts/gitlab-runner/-/raw/main/values.yamlEach
gitlab
runner needs a registration token to register on thegitlab
server. Retrieve the registration token from the GitLab web interface (“Admin Area” > “Runners”): -
Fill the
value.yaml
with :- the gitlabUrl (in our case
http://212.47.237.92/
) - the registration token
- enable
rbac
Note:By default, the gitlabUrl and the registration token lines are written out as a comment in the
values.yaml
file. Make sure you have deleted the#
before saving.[..]gitlabUrl: http://212.47.237.92/runnerRegistrationToken: "t7u_qjh3EFJX2-yPypkz"rbac:create: true[..]serviceAccountName: defaultWe will use a dedicated namespace.
- the gitlabUrl (in our case
-
To install the
gitlab
runner, create it on yourKapsule
cluster:kubectl create ns gitlab-runnernamespace/gitlab-runner createdThe default service account should use a new kubernetes role, and rolebinding.
-
Use the following example to create a role and role binding and associate it to the default service account in the
gitlab-runner
namespace :cat <<EOF | kubectl create -f -apiVersion: rbac.authorization.k8s.io/v1kind: Rolemetadata:name: gitlab-runnernamespace: gitlab-runnerrules:- apiGroups: [""]resources: ["pods"]verbs: ["list", "get", "watch", "create", "delete"]- apiGroups: [""]resources: ["pods/exec"]verbs: ["create"]- apiGroups: [""]resources: ["pods/log"]verbs: ["get"]EOFkubectl create rolebinding --namespace=gitlab-runner gitlab-runner-binding --role=gitlab-runner --serviceaccount=gitlab-runner:default -
Use the
helm
command to install the runner (note that you specify in this command line thevalues.yaml
file) :helm install --namespace gitlab-runner gitlab-runner -f ./values.yaml gitlab/gitlab-runnerNAME: gitlab-runnerLAST DEPLOYED: Wed May 6 15:48:20 2020NAMESPACE: gitlab-runnerSTATUS: deployedREVISION: 1TEST SUITE: NoneNOTES:Your GitLab Runner should now be registered against the GitLab instance reachable at: "http://212.47.237.92/"You can check the runner is working in the
gitlab
console (“admin area” > runners):
Running a pipepline in the runner using a test app
To demonstrate that the runner is working, we create a repository with a “hello world” piece of code written in python.
- Create the files using a text editor of your choice (e.g.
nano
orvim
). In this tutorial, we usenano
.nano helloworld.py - Create the content of the file as follows, save and exit:
print("Hello, World!")
- Create an associated gitlab-ci file to check it is running in the runner we just deployed:
nano .gitlab-ci.yaml
- Create the content of the file as follows, save and exit:
image: ubuntuhello-test:script:- apt-get update && apt-get install python3- python3 helloworld.py
- Push the repository and an ubuntu container is launched. At first
apt
is updated andpython3
is installed, and then the “hello, world” script is launched in the terminal.
If you want to learn more about running a gitlab
runner on Kubernetes you can also check the gitlab-ci
official documentation