Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The connection to the server localhost:8080 was refused

Tags:

kubernetes

I was able to cluster 2 nodes together in Kubernetes. The master node seems to be running fine but running any command on the worker node results in the error: "The connection to the server localhost:8080 was refused - did you specify the right host or port?"

From master (node1),

$ kubectl get nodes
NAME       STATUS    AGE       VERSION
node1       Ready     23h       v1.7.3
node2       Ready     23h       v1.7.3

From worker (node 2),

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

$ telnet localhost 8080
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused

$ ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.032 ms

I am not sure how to fix this issue. Any help is appreciated.

On executing,"journalctl -xeu kubelet" I see: "CNI failed to retrieve network namespace path: Cannot find network namespace for the terminated container", but this seems to be related to installing a pod network ... which I am not able to because of the above error.

Thanks!

like image 940
lex Avatar asked Aug 17 '17 00:08

lex


People also ask

How do you fix the connection to the server localhost 8080 was refused Did you specify the right host or port?

The solution for this issue is to use appropriate user to use kubectl. Don't use sudo. Using sudo will give error.

What is the meaning of localhost 8080?

So if in a browser, if http://localhost:8080 is entered, it simply means to server web-pages from local web-server which is listening for web-requests on 8080 port. The machine might not be connected to internet at all and still web-pages can be rendered in browser from local hard-drive.


2 Answers

kubectl interfaces with kube-apiserver for cluster management. The command works on the master node because that's where kube-apiserver runs. On the worker nodes, only kubelet and kube-proxy is running.

In fact, kubectl is supposed to be run on a client (eg. laptop, desktop) and not on the kubernetes nodes.

like image 183
Eugene Chow Avatar answered Oct 05 '22 20:10

Eugene Chow


from master you need ~/.kube/config pass this file as argument for kubectl command. Copy the config file to other server or laptop then pass the argument as for kubectl command

eg:

kubectl --kubeconfig=~/.kube/config

like image 22
sfgroups Avatar answered Oct 05 '22 22:10

sfgroups