---
apiVersion: apps/v1
kind: Deployment

metadata:
  name: gitlab-runner
  labels:
    app.kubernetes.io/name: gitlab-runner
    app.kubernetes.io/component: runner

spec:
  replicas: 1

  strategy:
    type: Recreate

  selector:
    matchLabels:
      app.kubernetes.io/name: gitlab-runner
      app.kubernetes.io/component: runner

  template:
    metadata:
      labels:
        app.kubernetes.io/name: gitlab-runner
        app.kubernetes.io/component: runner

    spec:
      serviceAccountName: gitlab-runner
      terminationGracePeriodSeconds: 3600

      securityContext:
        fsGroup: 999
        runAsUser: 999

      initContainers:
        - name: configure
          image: gitlab-runner
          imagePullPolicy: IfNotPresent

          command:
            - /bin/bash
            - /scripts/configure

          envFrom:
            - configMapRef:
                name: gitlab-runner

          volumeMounts:
            - name: secrets
              mountPath: /secrets
              readOnly: false
            - name: scripts
              mountPath: /scripts
              readOnly: true
            - name: init
              mountPath: /inits
              readOnly: true

          resources:
            limits:
              cpu: "1.0"
              memory: "256M"
            requests:
              cpu: "0.1"
              memory: "128M"

      containers:
        - name: server
          image: gitlab-runner
          imagePullPolicy: IfNotPresent

          command:
            - /bin/bash
            - /scripts/entrypoint

          lifecycle:
            preStop:
              exec:
                command:
                  - /entrypoint
                  - unregister
                  - --all-runners

          envFrom:
            - configMapRef:
                name: gitlab-runner

          ports:
            - name: metrics
              containerPort: 9252

          livenessProbe:
            exec:
              command:
                - /bin/bash
                - /scripts/check-liveness
            initialDelaySeconds: 60

          readinessProbe:
            exec:
              command:
                - /bin/bash
                - /scripts/check-readiness
            initialDelaySeconds: 10

          resources:
            limits:
              cpu: "1.0"
              memory: "256M"
            requests:
              cpu: "0.1"
              memory: "128M"

          volumeMounts:
            - name: secrets
              mountPath: /secrets
            - name: configs
              mountPath: /home/gitlab-runner/.gitlab-runner
            - name: scripts
              mountPath: /scripts

      volumes:
        - name: secrets
          emptyDir:
            medium: "Memory"
        - name: configs
          emptyDir:
            medium: "Memory"
        - name: scripts
          configMap:
            name: gitlab-scripts
        - name: init
          projected:
            sources:
              - secret:
                  name: gitlab-runner
                  items:
                    - key: runner-registration-token
                      path: runner-registration-token

...
