Home > Mobile >  Cannot access deployed services when Minikube cluster is installed in WSL2
Cannot access deployed services when Minikube cluster is installed in WSL2

Time:03-11

I have a Minikube cluster setup in WSL 2 of Windows 10 pro, where the docker-for-windows is used with WSL2 integration. Minikube was started with default docker driver.

$ minikube version
minikube version: v1.25.2
commit: 362d5fdc0a3dbee389b3d3f1034e8023e72bd3a7

If I follow the enter image description here

Is there any way that I can pre-configure a port to access the service (nodePort), and can access the service even if it is deployed in Minikube in WSL2?

Note:

I tried using other drivers from WSL like --driver=none. But that setup would be much more complicated because it has systemd, conntrack and other packages as dependencies, which WSL2 doesn't have currently.

Also tried to setup a Virtualbox vagrant Ubuntu box in Windows 10 and installed docker and started minikube with docker driver there. Everything works inside that VM. But cannot access the services from windows host as minikube ip is a host-only ip address available inside that VM only.

CodePudding user response:

Minikube in WSL2 with docker driver, creates a docker container with name minikube when minikube start command is executed. That container has some port mappings that helps kubectl and clients to connect to the server.

Notice that kubectl cluster-info connects to one of those ports as server. (Normally, the control plane would be running at port 8443, here it is a random high port, which is a mapped one).

$ kubectl cluster-info

Kubernetes control plane is running at https://127.0.0.1:55757
CoreDNS is running at https://127.0.0.1:55757/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

$ docker ps

CONTAINER ID   IMAGE                                 COMMAND                  CREATED         STATUS         PORTS
                                                                                                                    NAMES
9cc01654bd2f   gcr.io/k8s-minikube/kicbase:v0.0.30   "/usr/local/bin/entr…"   7 minutes ago   Up 7 minutes   127.0.0.1:55758->22/tcp, 127.0.0.1:55759->2376/tcp, 127.0.0.1:55756->5000/tcp, 127.0.0.1:55757->8443/tcp, 127.0.0.1:55760->32443/tcp   minikube

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

If you can provide a fixed nodePort to your app's service, then you can add a custom port mapping on minikube from that nodePort (of minikube host/VM) to a hostPort (of WSL2). And then you can acccess the service with localhost:hostPort.

For example,

You want to create a service with nodePort 30080.

In that case, make sure you start the minikube with a custom port mapping that includes this node port:

$ minikube start --ports=127.0.0.1:30080:30080

enter image description here

Now if you deploy the service with nodePort=30080 you will be able to access it via http://localhost:30080/.

There were issues like this in Minikube installation on MacOS. Here are some details about the workaround: https://github.com/kubernetes/minikube/issues/11193

  • Related