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

7/1/2018

when i am trying to test the configuration of kubectl

kubectl get svc 

i am getting this error: the server doesn't have a resource type "svc"

when I try this command

kubectl get services 

i am getting error:The connection to the server localhost:8080 was refused - did you specify the right host or port?

and i am following this userguide to deploy a kubernetes application on my mac

https://docs.aws.amazon.com/eks/latest/userguide/getting-started.html#eks-create-cluster

Admins-MacBook-Pro:~ Harshin$ kubectl version --short --client

Client Version: v1.10.3

please help me!!

-- Harshin_
amazon-eks
kubectl
kubernetes

5 Answers

2/18/2020

You may have used sudo in the wrong place. Chown your home directory:

sudo chown -R loggedonuser .
-- Octavian
Source: StackOverflow

9/10/2018

Make a copy of the config file and resolve this issue:

sudo mkdir ~/.kube
sudo cp /etc/kubernetes/admin.conf ~/.kube/

cd ~/.kube

sudo mv admin.conf config
sudo service kubelet restart
-- Hareesh R
Source: StackOverflow

7/1/2018

you need to specify kubeconfig for kubectl like this.

kubectl --kubeconfig .kube/config  get nodes
-- sfgroups
Source: StackOverflow

8/21/2019

kubectl consumes an interface exposed by a Container Service(GCP, ACS or AWS) When you receive that error it could be that you didn't configure the authentication to that Container Service(GCp, ACS, AWS, or etc) For example in Google Container Service you can do: gcloud auth login

Finally

gcloud container clusters get-credentials [cluster-name] --zone cluster-zone
[cluster-zone]

There will be an output like this one:

Fetching cluster endpoint and auth data.
kubeconfig entry generated for website.

The last line is what we were searching for

-- Virgilio Lino
Source: StackOverflow

6/7/2019

The problem is that the connection defaults to localhost:8080, just change kubectl.cfg specifying where you desire it to connect to. Another possible problem is the path to it not being set correctly, in the variable KUBECONFIG. Good luck

-- user113420
Source: StackOverflow