lex
lex

Reputation: 1871

The connection to the server localhost:8080 was refused

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!

Upvotes: 17

Views: 46438

Answers (6)

sfgroups
sfgroups

Reputation: 19133

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

Upvotes: 13

Eugene_S
Eugene_S

Reputation: 110

Ensure what context is selected if you're running Kubernetes in the Docker Desktop.

Kubernetes is enabled in Docker Desktop settings

Once you've selected it right, you'll be able to run the kubectl commands without any exception:

% kubectl cluster-info                              
Kubernetes control plane is running at https://kubernetes.docker.internal:6443
CoreDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

% kubectl get nodes
NAME             STATUS   ROLES                  AGE     VERSION
docker-desktop   Ready    control-plane,master   2d11h   v1.22.5

Upvotes: 0

ICeZer0
ICeZer0

Reputation: 588

To solve the issue The connection to the server localhost:8080 was refused - did you specify the right host or port?, you may be missing a step.

My Fix:

On MacOS if you install K8s with brew, you still need to brew install minikube, afterwards you should run minikube start. This will start your cluster.

Run the command kubectl cluster-info and you should get a happy path response similar to:

Kubernetes control plane is running at https://127.0.0.1:63000
KubeDNS is running at https://127.0.0.1:63308/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

Kubernetes install steps: https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/

Minikube docs: https://minikube.sigs.k8s.io/docs/start/

Upvotes: 0

Isaac Philip
Isaac Philip

Reputation: 575

As a hint, the message being prompted indicates its related to network. So one potential answer could also be, which worked for my resolution, is to have a look at the key cluster value for context within contexts.

My error was that I had placed an incorrect cluster name there.

Having the appropriate cluster name is crucial to finding it for respective context and the error will disappear.

Upvotes: 0

Anish Sapkota
Anish Sapkota

Reputation: 814

This worked for me after executing following commands:

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

Upvotes: 4

Eugene Chow
Eugene Chow

Reputation: 1706

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.

Upvotes: 21

Related Questions