The connection to the server localhost:8080 was refused

8/17/2017

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!

-- lex
kubernetes

2 Answers

8/17/2017

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.

-- Eugene Chow
Source: StackOverflow

8/17/2017

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

-- sfgroups
Source: StackOverflow