Helm 安装 gitlab-runner 报错

发布时间 2023-03-24 00:41:55作者: Professor哥

环境信息:

Helm: v3

gitlab-ce: 15.9

gitlab-runner: 15.9.3

安装集群:Kubernetes

Chart库:https://gitlab.com/gitlab-org/charts/gitlab-runner

问题1. gitlab-runner 注册报 401 Unauthorized

Helm values.yaml 参数配置如下:

## The GitLab Server URL (with protocol) that want to register the runner against
## ref: https://docs.gitlab.com/runner/commands/index.html#gitlab-runner-register
##
gitlabUrl: http://gitlab.fawve.ml

## The Registration Token for adding new Runners to the GitLab Server. This must
## be retrieved from your GitLab Instance.
## ref: https://docs.gitlab.com/ce/ci/runners/index.html
## ref: https://docs.gitlab.com/runner/register/
##
runnerRegistrationToken: "GR1348941YwnJqDctbGzbMDf_ZQzQ"

报错pod日志如下:

Registration attempt 1 of 30
Runtime platform                                    arch=amd64 os=linux pid=14 revision=d540b510 version=15.9.1
WARNING: Running in user-mode.                     
WARNING: The user-mode requires you to manually start builds processing: 
WARNING: $ gitlab-runner run                       
WARNING: Use sudo for system-mode:                 
WARNING: $ sudo gitlab-runner...                   
                                                   
Created missing unique system ID                    system_id=r_6STgtCdS6Nlo
Merging configuration from template file "/configmaps/config.template.toml" 
WARNING: Support for registration tokens and runner parameters in the 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with support for authentication tokens. For more information, see https://gitlab.com/gitlab-org/gitlab/-/issues/380872 
ERROR: Registering runner... failed                 runner=GR1348941YwnJqDct status=GET https://gitlab.fawve.ml:443/api/v4/runners: 401 Unauthorized
PANIC: Failed to register the runner.              

解决办法:

由于我环境中gitlab运行在 https 域名下,有有效证书,所以需要修改 values.yaml 中配置错误的 gitlabUrl 域名:

## The GitLab Server URL (with protocol) that want to register the runner against
## ref: https://docs.gitlab.com/runner/commands/index.html#gitlab-runner-register
##
gitlabUrl: https://gitlab.fawvel.ml

问题2. 注册报错 PANIC: Failed to verify the runner. You may be having network problems.

Helm values.yaml 参数配置如下:

.......
## The GitLab Server URL (with protocol) that want to register the runner against
## ref: https://docs.gitlab.com/runner/commands/index.html#gitlab-runner-register
##
gitlabUrl: https://gitlab.fawwel.ml

## The Registration Token for adding new Runners to the GitLab Server. This must
## be retrieved from your GitLab Instance.
## ref: https://docs.gitlab.com/ce/ci/runners/index.html
## ref: https://docs.gitlab.com/runner/register/
##
runnerRegistrationToken: "GR1348941YwnJqDctbGzbMDf_ZQzQ"

## The Runner Token for adding new Runners to the GitLab Server. This must
## be retrieved from your GitLab Instance. It is token of already registered runner.
## ref: (we don't yet have docs for that, but we want to use existing token)
##
runnerToken: "GR1348941YwnJqDctbGzbMDf_ZQzQ"
......

安装后查看 gitlab-runner-pod-xxxxx 的日志如下:

Registration attempt 6 of 30
Runtime platform                                    arch=amd64 os=linux pid=77 revision=d540b510 version=15.9.1
WARNING: Running in user-mode.                     
WARNING: The user-mode requires you to manually start builds processing: 
WARNING: $ gitlab-runner run                       
WARNING: Use sudo for system-mode:                 
WARNING: $ sudo gitlab-runner...                   
                                                   
Merging configuration from template file "/configmaps/config.template.toml" 
Token specified trying to verify runner...         
WARNING: If you want to register use the '-r' instead of '-t'. 
ERROR: Verifying runner... is removed               runner=GR1348941YwnJqDct
PANIC: Failed to verify the runner. You may be having network problems. 

解决办法

尝试取消 runnerToken 参数配置:

.......
## The GitLab Server URL (with protocol) that want to register the runner against
## ref: https://docs.gitlab.com/runner/commands/index.html#gitlab-runner-register
##
gitlabUrl: https://gitlab.fawwel.ml

## The Registration Token for adding new Runners to the GitLab Server. This must
## be retrieved from your GitLab Instance.
## ref: https://docs.gitlab.com/ce/ci/runners/index.html
## ref: https://docs.gitlab.com/runner/register/
##
runnerRegistrationToken: "GR1348941YwnJqDctbGzbMDf_ZQzQ"

## The Runner Token for adding new Runners to the GitLab Server. This must
## be retrieved from your GitLab Instance. It is token of already registered runner.
## ref: (we don't yet have docs for that, but we want to use existing token)
##
runnerToken: ""       ## <--- 置为空
......

再次安装 release :

helm upgrade -n gitlab gitlab-runner .

查看日志:

Registration attempt 1 of 30
Runtime platform                                    arch=amd64 os=linux pid=14 revision=d540b510 version=15.9.1
WARNING: Running in user-mode.                     
WARNING: The user-mode requires you to manually start builds processing: 
WARNING: $ gitlab-runner run                       
WARNING: Use sudo for system-mode:                 
WARNING: $ sudo gitlab-runner...                   
                                                   
Created missing unique system ID                    system_id=r_gY1tViN3pI4n
Merging configuration from template file "/configmaps/config.template.toml" 
WARNING: Support for registration tokens and runner parameters in the 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with support for authentication tokens. For more information, see https://gitlab.com/gitlab-org/gitlab/-/issues/380872 
Registering runner... succeeded                     runner=GR1348941YwnJqDct
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
 
Configuration (with the authentication token) was saved in "/home/gitlab-runner/.gitlab-runner/config.toml" 
Runtime platform                                    arch=amd64 os=linux pid=7 revision=d540b510 version=15.9.1
Starting multi-runner from /home/gitlab-runner/.gitlab-runner/config.toml...  builds=0
WARNING: Running in user-mode.                     
WARNING: Use sudo for system-mode:                 
WARNING: $ sudo gitlab-runner...                   
                                                   
Configuration loaded                                builds=0
Metrics server listening                            address=:9252 builds=0
[session_server].listen_address not defined, session endpoints disabled  builds=0
Initializing executor providers                     builds=0
.....

安装注册成功。