How to use IBM Kubernetes Service and Gitlab Runners
Scope
This document helps teach you how to connect your IBM Kubernetes cluster to a Hosted Gitlab instance so you can leverage your own infrastructure for continuous integration and continuous deployment.
Most of this document is influenced from the official documentation from Gitlab.
Prerequisites
- A Kubernetes cluster on the IBM cloud
- An IP that the your Gitlab instance can reach
- ibmcloud CLI installed and configured
Steps
- Authenticate with the IBM cloud CLI so you can connect to your Kubernetes cluster.
ibmcloud login # with --sso if you need to use single sign on ibmcloud cs region-set us-south # The region you have your cluster in ibmcloud cs cluster-config YOURCLUSTERNAME # you will need to run the export KUBECONFIG command kubectl get nodes # a sanity check to make sure you can authenticate with your Kubernetes cluster
- Create a directory to do some work inside of it, and save some files if needed.
mkdir gitlab-runner cd gitlab-runner
- Add the
helm
repo from gitlab.helm repo add gitlab https://charts.gitlab.io
- Initialize
helm
on both your local machine and in your Kubernetes cluster.helm init
- Create a
values.yaml
for your configuration of gitlab-runner, the full values.yml is here.wget https://gitlab.com/charts/gitlab-runner/raw/master/values.yaml vi values.yaml
- The only two settings you have to edit in the
values.yaml
are the following:gitlabUrl
- the GitLab Server URL (with protocol) to register the runner againstrunnerRegistrationToken
- The Registration Token for adding new Runners to the GitLab Server. This must be retrieved from your GitLab Instance. See the GitLab Runner Documentation for more information.
- After the configuration is complete, run the following command with a NAMESPACE that won’t step on another project. Using something like
gitlab-runners
as the namespace will isolate the pods in your Kubernetes cluster.helm install --namespace NAMESPACE --name gitlab-runner -f values.yaml gitlab/gitlab-runner
- You should now be able to see your runner in the
admin/runners
URL on your Gitlab instance.
Uninstalling
To uninstall the GitLab Runner Chart, run the following:
helm delete --namespace NAMESPACE RELEASE-NAME