Search code examples
gitlabkubectlrancher

Kubectl on Rancher Server not working properly


It is probably a stupid question, but I could not find anything useful on that topic.

I am following this tutorial to set up an automatic CI/CD pipeline: https://rancher.com/blog/2018/2018-08-07-cicd-pipeline-k8s-autodevops-rancher-and-gitlab/

I get stuck on the Token part. I get this error:

unable to recognize "http://x.co/rm082018": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused

It seems kubectl is not properly configured. If I call kubectl version I get the following output:

Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.2", GitCommit:"66049e3b21efe110454d67df4fa62b08ea79a19b", GitTreeState:"clean", BuildDate:"2019-05-16T16:23:09Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?

It seems I would have to copy the admin.conf file into the home directory. However, this file does not exist since kubeadm is not installed on the rancher server. Later I tried installing kubeadm myself, calling kubeadm init and copying the resulting admin.conf file.

The error is still there.

So my question is:

how can I fix this? do I have to fix this or can I get the token any other way? Is the kubectl error normal behaviour since Rancher should handle all of this on its own?

Thanks in advance for any answers.


Solution

  • The kubectl command output indicates that no kubeconfig was found on your host. You have to do one of the following:

    • place a kubeconfig named config under ~/.kube/
    • export an environment variable named KUBECONFIG with the kubeconfig location as its value
    • use the kubectl command with the --kubeconfig ... argument

    Happy hacking Regards