I want to perform kubernetes rolling update from Gitlab CI. My idea is running some kubectl
commands from Gitlab CI pipeline on my kubernetes AWS machine which has been registered as gitlab-runner
.
Below is my .gitlab-ci.yml
config.
rolling-update:
script:
- kubectl set image deployment web-server web=web:latest
stage: deploy
tags:
- k8s
when: manual
However, every time I run the pipeline, I get error
error: You must be logged in to the server (Unauthorized)
I guess the more general question is how can I run kubectl
on gitlab-runner
?
Found the issue. The gitlab-runner
environment config is not correctly set. I add those commands to my pipeline and it works fine.
sudo cp /etc/kubernetes/admin.conf $HOME/
sudo chown $(id -u):$(id -g) $HOME/admin.conf
export KUBECONFIG=$HOME/admin.conf