我在构建服务器上kubectl version
与gitlab-runner
用户一起在Gitlab的CI中运行。它在CI作业上失败,但在具有相同用户的主机Shell上成功。
我有以下工作gitlab-ci.yml
:
deploy:
stage: deploy
environment: staging
script:
- whoami
- kubectl version
失败并显示以下错误:
$ whoami
15 gitlab-runner
16 $ kubectl version
17 Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:20:10Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
18 error: You must be logged in to the server (the server has asked for the client to provide credentials)
22 ERROR: Job failed: exit status 1
kubectl version
使用gitlab-runner
用户在构建服务器的外壳上:
admin@BuildServer:~$ sudo -u gitlab-runner kubectl version
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:20:10Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:13:49Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
它在其他项目CI工作中也能正常工作。看来该项目的CI工作中的构建服务找不到/home/gitlab-runner/.kube/config
。但是我认为,当该作业由同一gitlab-runner
用户运行时,它应产生与在同一用户本地运行该作业相同的结果。
我想念的是什么?
因为其他项目的CI管道可以在同一个运行器上正常工作,并且问题仅与我的一个项目有关,所以我只使用Clear Runner Caches
了管道页面上的按钮。(我还清除了管理区域中的群集缓存,但不确定是否与问题有关。)