Custom volumes with gltlab-runner helm installation

9/24/2018

For faster builds I want to reuse my gradle-user-home in gitlab-runner. To achieve this I created a pvc and want to mount it on my build-containers. Can I do this with the default helm-chart?

-- Joerg
gitlab-ci-runner
kubernetes
kubernetes-helm

1 Answer

9/24/2018

So if you see here. There are no PVCs (Physical Volume Claims) or PVs (Physical Volumes) defined on the default Helm Chart.

You'd have to have something like this:

        volumeMounts:
        - name: gradle-user-home <== add this
          mountPath: /path/to/home
          subPath: home  
        - name: runner-secrets
          mountPath: /secrets
        - name: etc-gitlab-runner
          mountPath: /home/gitlab-runner/.gitlab-runner
        - name: scripts
          mountPath: /scripts
        {{- if .Values.certsSecretName }}
        - name: custom-certs
          readOnly: true
          mountPath: /home/gitlab-runner/.gitlab-runner/certs/
        {{- end }}
        resources:
{{ toYaml .Values.resources | indent 10 }}
      volumes:
      - name: runner-secrets
        emptyDir:
          medium: "Memory"
      - name: etc-gitlab-runner
        emptyDir:
          medium: "Memory"
      - name: init-runner-secrets
        projected:
          sources:
            {{- if .Values.runners.cache }}
            - secret:
                name: {{ template "gitlab-runner.cache.secret" . }}
                items:
                  - key: accesskey
                    path: s3-access-key
                  - key: secretkey
                    path: s3-secret-key
            {{- end }}
            - secret:
                name: {{ template "gitlab-runner.secret" . }}
                items:
                  - key: runner-registration-token
                    path: runner-registration-token
                  - key: runner-token
                    path: runner-token
      {{- if .Values.certsSecretName }}
      - name: custom-certs
        secret:
          secretName: {{ .Values.certsSecretName }}
      {{- end }}
      - name: scripts
        configMap:
         name: {{ template "gitlab-runner.fullname" . }}


  volumeClaimTemplates:  <== Add this
  - metadata:
      name: gradle-user-home
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
          storage: 10Gi

Note the this is only a rough draft template. You'll have to convert to the appropriate Helm template if you want to make it a Helm chart. (This happens to be a Golang template)

You don't have to modify the template if you don't want to. You can directly modify your deployment if you'd like with: kubectl -n <namespace> edit deployment <gitlab-runner-deployment>

Also if you are using PVCs (Physical Volume Claims), you'll have to define a default Kubernetes Storage Class

Hope it helps!

-- Rico
Source: StackOverflow