我需要创建一个卷来公开 maven .m2 文件夹,以便在我的所有项目中重用,但我根本无法做到这一点。
我的 gitlab 运行程序作为容器在我的 kubernetes 集群中运行。
遵循部署和配置图
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]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)