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

8

31

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
Disobey answered 1/7, 2018 at 7:5 Comment(0)
A
41

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
Arrogant answered 10/9, 2018 at 17:29 Comment(4)
What if you don't have that directory? I installed via homebrew and I do not have a /etc/kubernetes/admin.conf fileArtistry
I think you missed the step "kubeadm init"Felicle
I did not missed the kubeadm init step, after I signed out of the machine and signed in I too got into this situation, I can get the nodes except the new node role is shown <None>Tewfik
In Debian under root, this helped me export KUBECONFIG=/etc/kubernetes/admin.confCarnivorous
P
23

you need to specify kubeconfig for kubectl like this.

kubectl --kubeconfig .kube/config  get nodes
Palladian answered 1/7, 2018 at 10:50 Comment(3)
It did work for me, but not sure why. Can you elaborate?Chalcography
@Chalcography its because you're specifying the config in which you saved the credentials for your target AKS. I experienced the issue on WLS2 which isn't a very native environment for Azure CLI which makes sense for this workaround. Adding alias k="kubectl --kubeconfig .kube/config" to your .bashrc or .zshrc would make it easier for you to navigate.Kerb
I was also able to set this flag value with an environment variable, like this: export KUBECONFIG=".kube/config"Hux
W
21

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>
Winola answered 8/4, 2021 at 17:23 Comment(0)
M
9

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]

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

Mihe answered 21/8, 2019 at 13:3 Comment(2)
That's the most proper answerBehnken
One small issue here- there's an extra "cluster-zone" in the line above, I think I should be: gcloud container clusters get-credentials [cluster-name] --zone [custer-zone] where [cluster-zone] is something like us-west1-aColossians
W
2

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

Wick answered 7/6, 2019 at 23:12 Comment(0)
G
0

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
Gujranwala answered 12/4, 2021 at 6:56 Comment(0)
P
0

I got this error in AWS.

You might have not deleted your cluster properly. Go with

eksctl delete cluster --name <clusterName> --wait
Pul answered 7/4, 2022 at 6:43 Comment(0)
S
-2

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

sudo chown -R loggedonuser .
Shepp answered 18/2, 2020 at 22:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.