22
votes

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
7

7 Answers

32
votes

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
16
votes

you need to specify kubeconfig for kubectl like this.

kubectl --kubeconfig .kube/config  get nodes
8
votes

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

6
votes

I was facing the same issue when I was trying to access an AWS EKS cluster. Here's the command that I had to run and it resolved the issue for me:

aws eks update-kubeconfig --name <EKS_Cluster_Name> --region <Region_Name>
2
votes

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

0
votes

It seems like you have not set up the cluster. Run below in master.

sudo kubeadm init --pod-network-cidr=10.244.0.0/16
-2
votes

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

sudo chown -R loggedonuser .