使用 gitlab runner 挂载 hostpah 卷的正确方法是什么?

What is the correct way to mount a hostpah volume with gitlab runner?

我需要创建一个卷来公开 maven .m2 文件夹,以便在我的所有项目中重复使用,但我根本做不到。

我的 gitlab runner 运行 在我的 kuberentes 集群中作为容器。

遵循部署和配置映射

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: gitlab-runner
  namespace: default
spec:
  template:
    metadata:
      labels:
        name: gitlab-runner
    spec:
      serviceAccountName: gitlab-sa
      nodeName: 140.6.254.244
      containers:
        - name: gitlab-runner
          image: gitlab/gitlab-runner
          securityContext:
            privileged: true
          command: ["/bin/bash", "/scripts/entrypoint"]
          env:
            - name: KUBERNETES_NAMESPACE
              value: default 
            - name: KUBERNETES_SERVICE_ACCOUNT
              value: gitlab-sa
          # This references the previously specified configmap and mounts it as a file
          volumeMounts:
            - mountPath: /scripts
              name: configmap
          livenessProbe:
            exec:
              command: ["/usr/bin/pgrep","gitlab.*runner"]
            initialDelaySeconds: 60
            timeoutSeconds: 1
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            exec:
              command: ["/usr/bin/pgrep","gitlab.*runner"]
            initialDelaySeconds: 10
            timeoutSeconds: 1
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3

      volumes:
      - configMap:
          name: gitlab-runner-cm
        name: configmap

配置图:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: gitlab-runner-cm
  namespace: default 
data:
  entrypoint: |
    #!/bin/bash

    set -xe

    cp /scripts/config.toml /etc/gitlab-runner/

    # Register the runner
    /entrypoint register --non-interactive --registration-token ###### --url http://gitlab.######.net --clone-url http://gitlab.######.net --executor "kubernetes" --name "Kubernetes Runner" --config "/etc/gitlab-runner/config.toml"

    # Start the runner
    /entrypoint run --user=gitlab-runner \
      --working-directory=/home/gitlab-runner \
      --config "/etc/gitlab-runner/config.toml"
  config.toml: |
    concurrent = 50 
    check_interval = 10
    [[runners]]
      name            = "PC-CVO"
      url             = "http://gitlab.######.net"
      token           = "######"
      executor = "kubernetes"
      cache_dir = "/tmp/gitlab/cache"
      [runners.kubernetes]
        [runners.kubernetes.volumes]
          [[runners.kubernetes.volumes.host_path]]
            name = "maven"
            mount_path = "/.m2/"
            host_path = "/mnt/dados/volumes/maven-gitlab-ci"
            read_only = false

          [[runners.kubernetes.volumes.host_path]]
            name = "gitlab-cache"
            mount_path = "/tmp/gitlab/cache"
            host_path = "/mnt/dados/volumes/maven-gitlab-ci-cache"
            read_only = false



但即使按照文档中的说明放置 [[runners.kubernetes.volumes.host_path]] 我的卷也没有安装在主机上,我尝试使用 pv 和 pvc,但没有任何效果,任何人都知道如何在主机上公开此 .m2 文件夹,以便我的所有作业都可以在不缓存的情况下共享它?

在用内部 DNS、我的 m2 卷和使用 docker 守护进程而不是 docker: dind 解决名称解析问题后,我终于得到了解决我问题的配置,如果有人通过同样的问题,下面是最终的配置文件。 主要问题是,当注册跑步者时,注册过程修改了 config.toml 文件,这会覆盖我的设置,为了解决这个问题,我在容器注册后制作了一只猫。

部署

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: gitlab-runner
  namespace: default
spec:
  template:
    metadata:
      labels:
        name: gitlab-runner
    spec:
      serviceAccountName: gitlab-sa
      nodeName: 140.6.254.244
      containers:
        - name: gitlab-runner
          image: gitlab/gitlab-runner
          securityContext:
            privileged: true
          command: ["/bin/bash", "/scripts/entrypoint"]
          env:
            - name: KUBERNETES_NAMESPACE
              value: default 
            - name: KUBERNETES_SERVICE_ACCOUNT
              value: gitlab-sa
          # This references the previously specified configmap and mounts it as a file
          volumeMounts:
            - mountPath: /scripts
              name: configmap
          livenessProbe:
            exec:
              command: ["/usr/bin/pgrep","gitlab.*runner"]
            initialDelaySeconds: 60
            timeoutSeconds: 1
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            exec:
              command: ["/usr/bin/pgrep","gitlab.*runner"]
            initialDelaySeconds: 10
            timeoutSeconds: 1
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3

      volumes:
      - configMap:
          name: gitlab-runner-cm
        name: configmap

配置图(这里是解决方案!)

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: gitlab-runner-cm
  namespace: default 
data:
  entrypoint: |
    #!/bin/bash

    set -xe

    cp /scripts/config.toml /etc/gitlab-runner/

    # Register the runner
    /entrypoint register --non-interactive --registration-token ############ --url http://gitlab.######.net --clone-url http://gitlab.######.net --executor "kubernetes" --name "Kubernetes Runner" --config "/etc/gitlab-runner/config.toml"

    cat >> /etc/gitlab-runner/config.toml << EOF
          [[runners.kubernetes.volumes.host_path]]
            name = "docker"
            path = "/var/run/docker.sock"
            mount_path = "/var/run/docker.sock"
            read_only = false
          [[runners.kubernetes.volumes.host_path]]
            name = "maven"
            mount_path = "/.m2/"
            host_path = "/mnt/dados/volumes/maven-gitlab-ci"
            read_only = false
          [[runners.kubernetes.volumes.host_path]]
            name = "resolvedns"
            mount_path = "/etc/resolv.conf"
            read_only = true
            host_path = "/etc/resolv.conf"

    EOF



    # Start the runner
    /entrypoint run --user=gitlab-runner \
      --working-directory=/home/gitlab-runner \
      --config "/etc/gitlab-runner/config.toml"
  config.toml: |
    concurrent = 50 
    check_interval = 10
    [[runners]]
      name            = "PC-CVO"
      url             = "http://gitlab.########.###"
      token           = "##############"
      executor = "kubernetes"
      cache_dir = "/tmp/gitlab/cache"
      [runners.kubernetes]