Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

127.0.0.1:8001 refused to connect when kubectl proxy to access kubernetes dashboard

I deploy a cluster (neo4j) with kubeadm based on this guide. Now I have these pods :

NAME           READY   STATUS    RESTARTS   AGE
neo4j-core-0   1/1     Running   0          20h
neo4j-core-1   1/1     Running   0          20h
neo4j-core-2   1/1     Running   0          20h

and these services :

NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)             AGE
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP             60d
neo4j        ClusterIP   None             <none>        7474/TCP,6362/TCP   20h
nginx        ClusterIP   None             <none>        80/TCP              25h

Then I install kubernetes dashboard :

kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml

So when I do kubectl proxy to access the dashboard, with below link, it says 127.0.0.1 refused to connect.

http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/.

What should I do to access the dashboard?

I also create sample user following this guide.

like image 592
Majid Rajabi Avatar asked Dec 09 '18 11:12

Majid Rajabi


People also ask

How do I access Kubernetes dashboard with token?

To access the dashboard endpoint, open the following link with a web browser: http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#!/login . Choose Token, paste the authentication-token output from the previous command into the Token field, and choose SIGN IN.

What is kubectl proxy command?

kubectl proxy --address="127.0.0.1" port: You've already seen this in the example command we used above. It enables you to choose which port the proxy will be exposed from. If you do not provide this option, port 8001 will be used for exposing the proxy.

How does kube-proxy work in Kubernetes?

kube-proxy is a network proxy that runs on each node in your cluster, implementing part of the Kubernetes Service concept. kube-proxy maintains network rules on nodes. These network rules allow network communication to your Pods from network sessions inside or outside of your cluster.


2 Answers

Kubernetes dashboard fully rely on Apiserver. Connection refused means there is an issue with communication with apiserver. Please see https://github.com/kubernetes/dashboard/wiki/Accessing-Dashboard---1.7.X-and-above#kubectl-proxy

Also you can try to run

kubectl proxy --address='0.0.0.0' --port=8002 --accept-hosts='.*'

And check if on other interface(port 8002) rather than 127.0.0.1 it works.

like image 79
coolinuxoid Avatar answered Sep 28 '22 15:09

coolinuxoid


Quick fix, edit the kubernetes-dashboard yaml file >> selector type is "ClusterIP" to "NodePort" if you are running on localhost. then visit "https://master_ip:exposed_port"

i think this helps.

like image 41
defender Avatar answered Sep 28 '22 14:09

defender