Skip to content

Instantly share code, notes, and snippets.

@DevOpsKev
Forked from philipz/Readme.md
Created April 5, 2022 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DevOpsKev/1ff690c3af4cb395d989f2745eecd969 to your computer and use it in GitHub Desktop.
Save DevOpsKev/1ff690c3af4cb395d989f2745eecd969 to your computer and use it in GitHub Desktop.
GitLab Runner on a Kubernetes cluster
  1. Create namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: gitlab
  1. kubectl create -f ./namespace.yaml

  2. Create configmap.yaml, The token of "CI / CD Settings -> Runners settings" is for gitlab-runner register process. Try gitlab-runner register to get the right token in cofig.toml of local, and change token of config.toml of K8S.

apiVersion: v1
kind: ConfigMap
metadata:
  name: gitlab-runner
  namespace: gitlab
data:
  config.toml: |
    concurrent = 4

    [[runners]]
      name = "Kubernetes Runner"
      url = "https://gitlab.com/ci"
      token = "...."
      executor = "kubernetes"
      [runners.kubernetes]
        namespace = "gitlab"
        image = "busybox"
  1. kubectl create -f configmap.yaml

  2. Check configmap, kubectl get configmap --all-namespaces=true

  3. Create deployment.yaml file

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: gitlab-runner
  namespace: gitlab
spec:
  replicas: 1
  selector:
    matchLabels:
      name: gitlab-runner
  template:
    metadata:
      labels:
        name: gitlab-runner
    spec:
      containers:
      - args:
        - run
        image: gitlab/gitlab-runner:latest
        imagePullPolicy: Always
        name: gitlab-runner
        volumeMounts:
        - mountPath: /etc/gitlab-runner
          name: config
        - mountPath: /etc/ssl/certs
          name: cacerts
          readOnly: true
      restartPolicy: Always
      volumes:
      - configMap:
          name: gitlab-runner
        name: config
      - hostPath:
          path: /usr/share/ca-certificates/mozilla
        name: cacerts
  1. kubectl create -f deployment.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment