How to mount the kubernetes configuration to docker container created by docker executor

Hello everyone,

Issue

  • I’m unable to mount the Kubernetes configuration with docker container created by docker executor

Details

  • According to what I know GitLab provides different types of runners like a shell, docker, Kubernetes, and others. I was trying to use docker runner which was creating a docker container in the VM (where my Kubernetes cluster is running) and the container doesn’t have configuration mounted on it I was trying to see how GitLab allows mounting configuration of the cluster to its container.

As the jobs run inside the container it is throwing error like:

  • When I run kubectl config view from the GitLab docker container it doesn’t show any config.
$ kubectl config view
apiVersion: v1
clusters: null
contexts: null
current-context: ""
kind: Config
preferences: {}
users: null
  • When I run go-client to deploy some application then it thows error:
    Unable to Get the kubeconfig, due to {open /var/run/secrets/kubernetes.io/serviceaccount/token: no such file or directory}
    Expected
        <*os.PathError | 0xc000414090>: {
            Op: "open",
            Path: "/var/run/secrets/kubernetes.io/serviceaccount/token",
            Err: 0x2,
        }
    to be nil
  • kubectl get nodes from container
error: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
  • The config.toml file is:
[[runners]]
  name = "pod-level-e2e"
  url = "XXXXXXXXXXXXXXXXX"
  token = "XXXXXXXXXXXXXXXXXXXX"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "uditgaurav/litmus-runner:e2e"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0

So, How to mount the Kubernetes configuration to the docker container?

Are you attempting to deploy your application to a Kubernetes cluster through GitLab? If yes, read on:

Follow the document at Kubernetes clusters, I’ve copied a relevant portion below:

Deploying to a Kubernetes cluster

A Kubernetes cluster can be the destination for a deployment job. If

  • The cluster is integrated with GitLab, special deployment variables are made available to your job and configuration is not required. You can immediately begin interacting with the cluster from your jobs using tools such as kubectl or helm .
  • You don’t use GitLab’s cluster integration you can still deploy to your cluster. However, you must configure Kubernetes tools yourself using environment variables before you can interact with the cluster from your jobs.

From your recorded observances, it looks like KUBECONFIG was not auto-defined by GitLab, so you may need to follow the second step if it is not integrated with your project.

1 Like