Created
December 17, 2020 20:53
-
-
Save andrewodri/13a018305dafd31334a85c55aed8d62f to your computer and use it in GitHub Desktop.
Automatically register Gitlab Runners with Gitlab FOSS via Kubernetes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: gitlab-deployment | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: gitlab | |
template: | |
metadata: | |
labels: | |
app: gitlab | |
spec: | |
containers: | |
- name: gitlab-container | |
image: gitlab/gitlab-ce:latest | |
imagePullPolicy: IfNotPresent | |
ports: | |
- containerPort: 80 | |
env: | |
- name: GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN | |
value: "r3g1str4t10n" | |
- name: GITLAB_OMNIBUS_CONFIG | |
value: | | |
external_url 'https://example.com' | |
nginx['listen_port'] = 80 | |
nginx['listen_https'] = false | |
gitlab_rails['monitoring_whitelist'] = ['0.0.0.0/0'] | |
--- | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: gitlab-runner-deployment | |
spec: | |
replicas: 2 | |
selector: | |
matchLabels: | |
app: gitlab-runner | |
template: | |
metadata: | |
labels: | |
app: gitlab-runner | |
spec: | |
initContainers: | |
- name: gitlab-runner-initcontainer | |
image: curlimages/curl:latest | |
imagePullPolicy: IfNotPresent | |
command: [ "/bin/sh", "-c" ] | |
args: [ "until [[ $(curl -iso /dev/null -w '%{http_code}\n' 'https://example.com/-/readiness') == '200' ]]; do sleep 1; done" ] | |
containers: | |
- name: gitlab-runner-container | |
image: gitlab/gitlab-runner:latest | |
imagePullPolicy: IfNotPresent | |
command: [ "/usr/bin/dumb-init", "--" ] | |
args: [ "/bin/sh", "-c", "/entrypoint help \ | |
&& gitlab-runner register --non-interactive --registration-token \"${GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN}\" --locked=false --description \"$(hostname)\" --url \"https://example.com\" --executor kubernetes --kubernetes-privileged \ | |
&& exec gitlab-runner run --user=gitlab-runner --working-directory=/home/gitlab-runner" ] | |
ports: | |
- containerPort: 80 | |
env: | |
- name: GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN | |
value: "r3g1str4t10n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above
config.yaml
is by no means complete, but contains all the essential configuration you would need to add to an already working configuration. Here is a brief explanation of what is going on:GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN
value is defined so that we can pass that on to the runners to... Of course, you might want to tighten this up with secrets and moving access/definitions around.