温馨提示:本文翻译自stackoverflow.com,查看原文请点击:continuous integration - kubectl credential error on Gitlab runner
continuous-integration gitlab kubectl

continuous integration - Gitlab运行程序上的kubectl凭证错误

发布于 2020-04-16 14:44:12

在构建服务器上kubectl versiongitlab-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用户运行时,它应产生与在同一用户本地运行该作业相同的结果。

我想念的是什么?

查看更多

提问者
Ahmad Ahmadi
被浏览
81
Ahmad Ahmadi 2020-02-04 19:37

因为其他项目的CI管道可以在同一个运行器上正常工作,并且问题仅与我的一个项目有关,所以我只使用Clear Runner Caches了管道页面上的按钮。(我还清除了管理区域中的群集缓存,但不确定是否与问题有关。)