I am trying to set up a Gitlab Kubernetes Agent in a small self-hosted k3s cluster.

I am however getting an error:

$ kubectl config get-contexts
error: error loading config file "/root/.kube/config": open /root/.kube/config: permission denied

I have been following the steps in documentation found here:
https://docs.gitlab.com/ee/user/clusters/agent/ci_cd_workflow.html

I got the agent installed and registered so far.

I also found a pipeline kubectl example here: https://docs.gitlab.com/ee/user/clusters/agent/ci_cd_workflow.html#update-your-gitlab-ciyml-file-to-run-kubectl-commands

Using the one below gives the error:

deploy:
   image:
     name: bitnami/kubectl:latest
     entrypoint: [""]
   script:
   - kubectl config get-contexts
   - kubectl config use-context path/to/agent/repository:agent-name
   - kubectl get pods

I do not know what is missing. The script itself seems a bit confusing as there is nothing telling the container how to access the cluster.

Looking further down there is also one for doing both certificate-based and agent-based connections. However I have no knowledge of either so I cannot tell if there is something extra in this that I should actually be adding.

Also if it makes a difference the runner is also self-hosted and set to run docker. The agent is set up without a configuration file. I wanted to keep it as simple as possible and take it from there.

Anyone know what should be changed/added to fix the issue?

EDIT:

I took at step back and disregarded the agent approach. I put the kubeconfig in a gitlab variable and used that in the kubernetes image. This is good enough for now and a relief to finally for the first time have something working and be able to push stuff to my cluster from pipeline. After well over 15 hours spent on the agent I have had enough. Only after several hours did I figure out that the agent was not just about security etc but that it was also intended for syncing repo and cluster without pipelines. This was very poorly presented and as someone who has done neither completely escaped me. The steps in docs I followed seems to be a mixture of both which does not exactly help out. I will wait some months and see if some proper guides are release somewhere by then.

0

There are 0 answers