Continuous integration Gitlab runner上的kubectl凭据错误

Continuous integration Gitlab runner上的kubectl凭据错误,continuous-integration,gitlab,kubectl,Continuous Integration,Gitlab,Kubectl,我使用构建服务器上的Gitlab runneruser在Gitlab的CI中运行kubectl版本。它在CI作业上失败,但在主机外壳上使用同一用户成功 我在gitlab ci.yml中有这个工作: deploy: stage: deploy environment: staging script: - whoami - kubectl version 它失败,出现以下错误: $ whoami 15 gitlab-runner 16 $ kubectl version

我使用构建服务器上的
Gitlab runner
user在Gitlab的CI中运行
kubectl版本。它在CI作业上失败,但在主机外壳上使用同一用户成功

我在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
使用gitlab runner在构建服务器外壳上安装kubectl版本
,用户:

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管道可以与同一个运行程序正常工作,并且问题只与我的一个项目相关,所以我只使用了管道页面上的“清除运行程序缓存”按钮。(我还清除了管理区域中的群集缓存,但我不确定这是否与问题有关。)

尝试通过Gitlab Dashboard删除kube配置并添加一个新配置,它可能会修复。请让我知道。谢谢你的提示!因为其他项目的CI工作正常,所以我刚刚清除了集群和运行器缓存,现在它工作正常。