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

2/4/2020

I am new to kubernetes . I got the below error while interacting with the cluster kubectl get nodes .

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

-- sai saubhagya
kubernetes

3 Answers

2/4/2020

When there is clear instructions by kubeadm init to execute following commands as an regular user, if you miss runing them you end up with issue reported.

To make kubectl work for your non-root user, run these commands, which are also part of the kubeadm init output:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should check back the logs at kubeadm init time and you will find similar as below asking to execute the command.

[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a Pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  /docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

  kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
-- DT.
Source: StackOverflow

2/4/2020

After search in the internet i fixed my issues .

#sudo cp /etc/kubernetes/admin.conf $HOME/

#sudo chown $(id -u):$(id -g) $HOME/admin.conf

#export KUBECONFIG=$HOME/admin.conf

-- sai saubhagya
Source: StackOverflow

2/4/2020

Your kubectl is probably not referring to right kubeconfig file or the kubeconfig file does not right details.

-- Arghya Sadhu
Source: StackOverflow