I run kubectl version
in Gitlab's CI with gitlab-runner
user on build server. It fails on CI job but succeed on host's shell with same user.
I have this job in gitlab-ci.yml
:
deploy:
stage: deploy
environment: staging
script:
- whoami
- kubectl version
It fails with the following error:
$ 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
on the build server's shell using gitlab-runner
user:
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"}
It works fine in other projects CI jobs. It seems that build service in this project's CI job can't find the /home/gitlab-runner/.kube/config
. But I think when the job runs with same gitlab-runner
user, it should produce same result as running it locally with the same user.
What's the point I'm missing?
Because other project's CI pipeline works fine with the same runner and issue was related to just one of my projects, I just used the Clear Runner Caches
button on the pipelines page. (I also cleared cluster cache in the admin area, but I am not sure that was related to issue.)