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

+2 votes

I'm trying to create a simple service on kubernetes

kubectl create serviceaccount dashboard -n default

but it throws the following error

The connection to the server localhost:8080 was refused - did you specify the right host or port?
Sep 4, 2018 in Kubernetes by Hannah
• 18,410 points

4 answers to this question.

0 votes

Run the following command as a normal user

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

answered Sep 4, 2018 by Kalgi
• 51,970 points
Thanks that worked!
Glad to help. :)
i got error in second step :

cp: cannot stat '/etc/kubernetes/admin.conf': No such file or directory
Try running these commands,
mkdir ~/.kube
vim ~/.kube/config
and copy the config file from mster node to nodes config file.
This did not work for me

Try to restart your cluster. Or check the configuration file.

$ kubectl config view
+1 vote

I had the exact same error when I was trying to create a cluster on GCP. This is how I got it sorted:

  • Log in to Google Cloud Platform
  • Navigate to Container Engine Google Cloud Platform, Container Engine
  • Click CONNECT on Cluster
  • Use login Credentials to access Cluster [NAME] in your Terminal
answered Apr 26, 2019 by Vinay
+1 vote

Try using --server to specify your master:

kubectl --server= get pod -o wide
answered Apr 26, 2019 by Jobin
+1 vote

I was trying to get status from a remote system using ansible and I was facing the same issue.
I tried and it worked.

kubectl --kubeconfig ./admin.conf get pods --all-namespaces -o wide
answered Apr 26, 2019 by Sumit

Related Questions In Kubernetes

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Kubernetes error: Did you speciy the right host or port

Try and auto generate your kubeconfig. Use: gcloud container ...READ MORE

answered Jan 9, 2019 in Kubernetes by DareDev
• 6,870 points
+1 vote
0 answers

The connection to the server localhost:8080 was refused

$ kubectl get svc The connection to the ...READ MORE

Aug 8, 2019 in Kubernetes by Lakshminarayanan
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
+4 votes
1 answer

Installing Web UI (Dashboard):kubernetes-dashboard on main Ubuntu 16.04.6 LTS (Xenial Xerus) server

Follow these steps: $ kubeadm reset $ kubeadm init ...READ MORE

answered Apr 11, 2019 in Kubernetes by Kalgi
• 51,970 points

reshown Apr 12, 2019 by Kalgi 2,810 views
0 votes
2 answers

Error saying “Error from server (NotFound): the server could not find the requested resource”

official Documentation says: A client should be skewed ...READ MORE

answered Sep 19, 2018 in Kubernetes by Nilesh
• 6,980 points