简体   繁体   中英

Accessing minikube dashboard - (Ubuntu20.04 server)VM running on Windows 10 host with VirtualBox 6.1

I'm trying to access minikube dashboard from host OS (Windows 10).

Minikube is running on my virtual machine Ubuntu 20.04 server.

The host is Windows 10 and I use VirtualBox to run my VM.

These are the commands I ran on Ubuntu:

tomas@ubuntu20:~$ minikube start
* minikube v1.22.0 on Ubuntu 20.04 (vbox/amd64)
* Using the docker driver based on existing profile
* Starting control plane node minikube in cluster minikube
* Pulling base image ...
* Updating the running docker "minikube" container ...
* Preparing Kubernetes v1.21.2 on Docker 20.10.7 ...
* Verifying Kubernetes components...
  - Using image gcr.io/k8s-minikube/storage-provisioner:v5
  - Using image kubernetesui/dashboard:v2.1.0
  - Using image kubernetesui/metrics-scraper:v1.0.4
* Enabled addons: storage-provisioner, default-storageclass, dashboard
* kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

tomas@ubuntu20:~$ kubectl get po -A
    
Command 'kubectl' not found, but can be installed with:
    
sudo snap install kubectl

tomas@ubuntu20:~$ minikube kubectl -- get po -A
NAMESPACE              NAME                                         READY   STATUS    RESTARTS   AGE
kube-system            coredns-558bd4d5db-9p9ck                     1/1     Running   2          72m
kube-system            etcd-minikube                                1/1     Running   2          72m
kube-system            kube-apiserver-minikube                      1/1     Running   2          72m
kube-system            kube-controller-manager-minikube             1/1     Running   2          72m
kube-system            kube-proxy-xw766                             1/1     Running   2          72m
kube-system            kube-scheduler-minikube                      1/1     Running   2          72m
kube-system            storage-provisioner                          1/1     Running   4          72m
kubernetes-dashboard   dashboard-metrics-scraper-7976b667d4-r9k7t   1/1     Running   2          54m
kubernetes-dashboard   kubernetes-dashboard-6fcdf4f6d-c7kwf         1/1     Running   2          54m

And then I open another terminal window and I run:

tomas@ubuntu20:~$ minikube dashboard
* Verifying dashboard health ...
* Launching proxy ...
* Verifying proxy health ...
* Opening http://127.0.0.1:36337/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
  http://127.0.0.1:36337/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

Now on my Windows 10 host machine I go to web browser type in:

http://127.0.0.1:36337/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

But I get error:

This site can’t be reached 127.0.0.1 refused to connect.

How can I access minikube dashboard from my host OS web browser?

Reproduction

I reproduced this behaviour on Windows 10 and ubuntu 18.04 LTS virtual machine running using VirtualBox .

I have tried both minikube drivers : docker and none (last one means that all kube.netes components will be run on localhost) and behaviour is the same.

What happens

Minikube is designed to be used on localhost machine. When minikube dashboard command is run, minikube downloads images (metrics scraper and dashboard itsefl), launches them, test if they are healthy and then create proxy which is run on localhost . It can't accept connections outside of the virtual machine (in this case it's Windows host to ubuntu VM).

This can be checked by running netstat command (cut off some not useful output):

$ minikube dashboard
🔌  Enabling dashboard ...
🚀  Launching proxy ...
🤔  Verifying proxy health ...
👉  http://127.0.0.1:36317/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

$ sudo netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name     
tcp        0      0 127.0.0.1:36317         0.0.0.0:*               LISTEN      461195/kubectl

How to resolve it

Once minikube dashboard command has been run, kube.netes dashboard will remain running in kube.netes-dashboard namespace.

Proxy to it should be open manually with following command:

kubectl proxy --address='0.0.0.0' &

Or if you don't have kubectl installed on your machine:

minikube kubectl proxy -- --address='0.0.0.0' &

It will start a proxy to kube.netes api server on port 8001 and will serve on all addresses (it can be changed to default Virtual box NAT address 10.2.0.15 ).

Next step is to add port-forwarding in VirtualBox. Go to your virtual machine -> settings ->.network -> NAT -> advanced -> port-forwarding

Add a new rule:

  • host IP = 127.0.0.1
  • host port = any free one, eg I used 8000
  • guest IP = can be left empty
  • guest port = 8001 (where proxy is listening to)

Now you can go to your browser on Windows host, paste the URL, correct the port which was assigned in host port and it will work:

http://127.0.0.1:8000/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

Useful links:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM