Need Help understanding/setting up Gitlab Kubernetes agents/Runners

So this was my setup:

  1. I created a gitlab.com repository for my Kubernetes agents, then I created this file: .gitlab/agents/primary-agent/config.yaml with the following contents:
ci_access:
  projects:
    - id: rafaelmoreira1180778/home-media-center

This would mean that the project rafaelmoreira1180778/home-media-center would have access to this agent.

  1. Then i created my project, NPM based where i want to compile a CDK8s project and deploy the generated manifests to my cluster.

Inside that project i created the runner with this configuration (for now I’ve skiped the npm run build step in the pipeline, I run it manually and commit the dist files, the idea would be to do it ‘on the go’ inside the pipeline):

deploy:
  image:
    name: bitnami/kubectl:latest
    entrypoint: [""]
  script:
    - kubectl config use-context rafaelmoreira1180778/kubernetes-agents:primary-agent
    - kubectl get all -o wide -n default
    - kubectl get all -o wide

After this I registered a runner with:

$ docker run -d gitlab/gitlab-runner:alpine
$ docker exec -ti <container> sh
$ gitlab-runner register

After registering the runner on my project with the executor Kubernetes I triggered a pipeline and this was the result:

Running with gitlab-runner 14.7.0 (98daeee0)
  on kubernetes-test BXW7HGEr
Preparing the "kubernetes" executor
00:09
WARNING: Namespace is empty, therefore assuming 'default'.
Using Kubernetes namespace: default
ERROR: Preparation failed: getting Kubernetes config: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
Will be retried in 3s ...
WARNING: Namespace is empty, therefore assuming 'default'.
Using Kubernetes namespace: default
ERROR: Preparation failed: getting Kubernetes config: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
Will be retried in 3s ...
WARNING: Namespace is empty, therefore assuming 'default'.
Using Kubernetes namespace: default
ERROR: Preparation failed: getting Kubernetes config: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
Will be retried in 3s ...
ERROR: Job failed (system failure): getting Kubernetes config: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable

Can anyone help me understand what I did wrong here? Should I place the agent in the same project as the code?

Notes: this is on gitlab.com on my home server, I was planning on moving to a self-hosted instance once I got a few basic things working.

2 Likes

The error message definitely requires some improvement. I am also struggling with this issue. Some people have suggested that it is due to the missing .kube directory inside the gitlab-runner user’s home directory (/home/gitlab-runner/). I did try to create one by logging as the gitlab-runner user and create it (sudo su gitlab-runner && cd /home/gitlab-runner && mkdir .kube), but nothing changed. The .kube directory, at least on my small self-hosted private cluster, appears to contain just a cache directory and nothing else (no hidden files).