Kubernetes - The connection to the server localhost:8080 was refused - did you specify the right host or port?

12,884

The reason behind that is kubectl version prints Client Version and Server Version (kubernetes version) both. When you just install kubectl it is just Kubernetes client. If you have kubernetes cluster installed, it will print both kubectl version and kubernetes version.

If you want to just want to print client version, then use following command:

kubectl version --client=true

The error meant kubectl tried to contact the kubernetes server to get its version but couldn't connect. Are you specifying the right host or port to connect to the kubernetes server.

The reason behind the error is you have not installed kubernetes cluster on you mac. You just installed kubectl which is just a client to access kubernetes cluster. Once you install the kubernetes cluster the output of kubectl version will be like:

[root@ip-10-0-1-138 centos]# kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.1", 
GitCommit:"eec55b9ba98609a46fee712359c7b5b365bdd920", GitTreeState:"clean", BuildDate:"2018-12-13T10:39:04Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:05:37Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

If you want to install the complete kubernetes cluster on mac, please try minikube to install cluster locally.

Share:
12,884
Ari M.
Author by

Ari M.

Updated on June 20, 2022

Comments

  • Ari M.
    Ari M. almost 2 years

    I just finished installing kubectl via Ubuntu 64 (Linux). I followed the online Kubernetes guide, but I've had an error with the host. After the first step (install kubectl), when I checked the kubectl version, this was the message (I didn't yet install and deploy the minikube because I've not the connection according to this problem):

    root@ubuntu:~# kubectl version
    Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.1", GitCommit:"eec55b9ba98609a46fee712359c7b5b365bdd920", GitTreeState:"clean", BuildDate:"2018-12-13T10:39:04Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
    The connection to the server localhost:8080 was refused - did you specify the right host or port?
    

    Does someone have the same problem? How can I fix it?

  • Ari M.
    Ari M. over 5 years
    Thank you. I've tried to use minikube for installing cluster locally. I've found another problem. This is the code. root@ubuntu:~# minikube start Starting local Kubernetes v1.12.4 cluster... Starting VM... E0107 06:52:39.350772 2851 start.go:187] Error starting host: Error starting stopped host: Machine didn't return an IP after 120 seconds. Retrying. E0107 06:52:39.351121 2851 start.go:193] Error starting host: Error starting stopped host: Machine didn't return an IP after 120 seconds
  • Prafull Ladha
    Prafull Ladha over 5 years
    Have you tried minikube delete followed by minikube start --vm-driver=hyperkit. Please see following link to install minikube kubernetes.io/docs/setup/minikube
  • Prafull Ladha
    Prafull Ladha over 5 years
    Also, as you're on ubuntu, I would suggest you to move to microk8s. I have been using the same and I absolutely love it. Checkout the why microk8s stackoverflow.com/questions/29746926/… github.com/ubuntu/microk8s