Kubernetes/Openshift 上的 Gitlab-Runner

Gitlab-Runner on Kubernetes/Openshift

我正在尝试在 Openshift/K8S 上部署 Gitlab-运行ner(s),但无法成功让 运行ners 与 Gitlab 通信(它本身部署在 pods 在 OCP 上)。

我遵循了以下几个不同的说明:

我的 gitlab-运行ner pod 启动正常,但它总是收到 HTTP 404 Not Found 错误消息。

这是我的 toml 配置文件:

# cat /etc/gitlab-runner/config.toml
concurrent = 6
check_interval = 0

[[runners]]
  name = "GitLab Runner"
  url = "http://gitlab-ce.MY_COMAIN.com/ci"
  token = "WHO_CARES?"
  executor = "kubernetes"
  [runners.kubernetes]
    namespace = "MINE"
    privileged = false
    host = ""
    cert_file = ""
    key_file = ""
    ca_file = ""
    image = ""
    cpus = ""
    memory = ""
    service_cpus = ""
    service_memory = ""
    helper_cpus = ""
    helper_memory = ""
    helper_image = ""
  [runners.cache]
    Type = "s3"
    ServerAddress = "minio-service:80"
    AccessKey = "GENERATED"
    SecretKey = "GENERATED"
    BucketName = "bkt-gitlab-runner"
    Insecure = true

一旦 pod 启动,我的日志中就有了这个:

Starting multi-runner from /etc/gitlab-runner/config.toml ...  builds=0
Running in system-mode.                            

Configuration loaded                                builds=0
Metrics server disabled                            
WARNING: Checking for jobs... failed                runner=WHO_CARES? status=404 Not Found
WARNING: Checking for jobs... failed                runner=WHO_CARES? status=404 Not Found
WARNING: Checking for jobs... failed                runner=WHO_CARES? status=404 Not Found

而在 Gitlab 中,在 运行ners 页面 (https://gitlab-ce.MY_COMAIN.com/group/project/settings/ci_cd) 中没有 "Runners activated for this project".

我可以在终端登录我的 pod 并启动 gitlab-runner register 来注册一个新的 运行ner

/ # gitlab-runner register
Running in system-mode.

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
https://gitlab-ce.MY_COMAIN.com
Please enter the gitlab-ci token for this runner:
WHO_CARES?
Please enter the gitlab-ci description for this runner:
[dc-gitlab-runner-service-1-ktw6v]: test
Please enter the gitlab-ci tags for this runner (comma separated):
test
Registering runner... succeeded                     runner=WHO_CARES?
Please enter the executor: docker+machine, kubernetes, ssh, docker-ssh, parallels, shell, virtualbox, docker-ssh+machine, docker:
kubernetes
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

但是当我尝试 运行 它时...我面临着完全相同的问题。

/ # gitlab-runner run
Starting multi-runner from /etc/gitlab-runner/config.toml ...  builds=0
Running in system-mode.

Configuration loaded                                builds=0
Metrics server disabled
WARNING: Checking for jobs... failed                runner=WHO_CARES? status=404 Not Found
WARNING: Checking for jobs... failed                runner=WHO_CARES? status=404 Not Found

当然,我检查了是否可以从 Runner 终端访问 Gitlab,它可以工作

/ # ping
BusyBox v1.27.2 (2018-06-06 09:08:44 UTC) multi-call binary.

Usage: ping [OPTIONS] HOST

/ # ping gitlab-ce.MY_COMAIN.com
PING gitlab-ce.MY_COMAIN.com (1.2.3.4): 56 data bytes
64 bytes from 1.2.3.4: seq=0 ttl=63 time=0.268 ms
64 bytes from 1.2.3.4: seq=1 ttl=63 time=0.261 ms
64 bytes from 1.2.3.4: seq=2 ttl=63 time=0.288 ms
^C

旁注:我正在 运行宁 OCP 3.9 / K8S 1.9

你看到我哪里做错了吗?

干杯, 奥利维尔

好的。这是解决方案。

问题来自 token 的奇怪行为。 Gitlab中有好几个token,要慎重选择使用

这个问题也在这里相关:https://gitlab.com/gitlab-org/gitlab-ce/issues/37807

您必须首先使用管理页面中提供的 Runner 令牌:https://gitlab-instance/admin/runners。此令牌将在 [runners.token] 部分下的 config.toml 中使用。

部署并启动运行器。

它出现在Gitlab中,但不可用。只需在管理区域中点击其名称:https://gitlab-instance/admin/runners/38

在此处查找与此 Runner 关联的令牌的详细信息。

将它复制回 config.toml 文件,仍然在完全相同的 [runners.token] 部分下,作为替换。 重新部署你的跑步者。

应该可以。

4 月2022:GitLab 14.10 确实支持该用例:

GitLab Runner Operator for Kubernetes

In GitLab 13.10, we released the GitLab Runner Operator for the Red Hat OpenShift container platform for Kubernetes.

That release provided OpenShift users with the automation and management capabilities of the Operator Framework and simplified the ongoing management of runners in an OpenShift Kubernetes cluster. Available starting in 14.10 is a GitLab Runner Operator v1.7.0 that you can use in non-OpenShift Kubernetes clusters. This GitLab Runner Operator is available on OperatorHub.io.

See Documentation and Issue.


另一个选项,可以避免令牌管理,GitLab 13.7(2020 年 12 月)

GitLab Runner for Red Hat OpenShift

Available today is the GitLab Runner container image for the Red Hat OpenShift Container Platform.

To install the runner on OpenShift, you can use the new GitLab Runner Operator available from the beta channel in Red Hat’s Operator Hub - a web console for OpenShift cluster administrators to discover and select Operators to install on their cluster.

Operator Hub is deployed by default in the OpenShift Container Platform.
We plan to transition the GitLab Runner Operator to the stable channel, and by extension GA, in early 2021. Finally, we are also developing an operator for GitLab, so stay tuned to future release posts for those announcements.

See Documentation and Issue.


GitLab 13.11(2021 年 4 月)对此进行了增强

Deploy GitLab on OpenShift and Kubernetes with the GitLab Operator (beta)

GitLab is working to offer full support for OpenShift. To accomplish this, we have released the MVP GitLab Operator. The operator aims to manage the full lifecycle of GitLab instances on Kubernetes and OpenShift container platforms.
Currently, this is a beta release and it is not recommended for production use.

The next steps will be to make the operator generally available (GA). In the future the operator will become the recommended installation method for Kubernetes and OpenShift, although the GitLab Helm chart will still be supported. We welcome you to try this operator and provide feedback on our issue tracker.

See Documentation and Issue.