<p>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.</p>
<pre><code>$ minikube version
minikube version: v1.25.2
commit: 362d5fdc0a3dbee389b3d3f1034e8023e72bd3a7
</code></pre>
<p>If I follow the <a href="https://minikube.sigs.k8s.io/docs/start/" rel="nofollow noreferrer">getting started guide</a>,after creating the <code>hellow-minikube</code> service, I should be able to connect to the service either via <code>&lt;minikube-ip&gt;:nodeport</code> or via <code>minikube service</code> command.</p>
<p>But the first method didn't worked. Because it was impossible to even ping the minikube ip from WSL 2:
(This works in Minikube setup on a pure Ubuntu installation. The problem is in WSL2 - Windows subsystem for linux).</p>
<pre><code>$ minikube ip
192.168.49.2

$ ping 192.168.49.2
PING 192.168.49.2 (192.168.49.2) 56(84) bytes of data.
^C
--- 192.168.49.2 ping statistics ---
293 packets transmitted, 0 received, 100% packet loss, time 303708ms
</code></pre>
<p>The second method <code>minikube service hello-minikube</code> also didn't worked because it was again giving the access url with minikube IP.</p>
<pre><code>$ minikube service hello-minikube

🏃  Starting tunnel for service hello-minikube.
🎉  Opening service default/hello-minikube in default browser...
👉  **http://192.168.49.2:30080**
❗  Because you are using a Docker driver on linux, the terminal needs to be open to run it.
</code></pre>
<p>But this was actually working in previous Minikube versions, as it was actually exposing a host port to the service, and we could connect to the host port to access the service. It needed a manual intervention as the hostport access was available only until the <code>minikube service</code> command keeps running.</p>
<p><a href="https://i.stack.imgur.com/4BOFm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4BOFm.png" alt="enter image description here" /></a></p>
<p>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?</p>
<p><strong>Note:</strong></p>
<p>I tried using other drivers from WSL like <code>--driver=none</code>. But that setup would be much more complicated because it has <code>systemd</code>, <code>conntrack</code> and other packages as dependencies, which WSL2 doesn't have currently.</p>
<p>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.</p>

<p>Minikube in WSL2 with docker driver, creates a docker container with name <code>minikube</code> when <code>minikube start</code> command is executed. That container has some port mappings that helps kubectl and clients to connect to the server.</p>
<p>Notice that <code>kubectl cluster-info</code> 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).</p>
<pre><code>$ 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   &quot;/usr/local/bin/entr…&quot;   7 minutes ago   Up 7 minutes   127.0.0.1:55758-&gt;22/tcp, 127.0.0.1:55759-&gt;2376/tcp, 127.0.0.1:55756-&gt;5000/tcp, 127.0.0.1:55757-&gt;8443/tcp, 127.0.0.1:55760-&gt;32443/tcp   minikube
</code></pre>
<p>To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.</p>
<p>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 <code>localhost:hostPort</code>.</p>
<p>For example,</p>
<p>You want to create a service with nodePort <code>30080</code>.</p>
<p>In that case, make sure you start the minikube with a custom port mapping that includes this node port:</p>
<pre><code>$ minikube start --ports=127.0.0.1:30080:30080
</code></pre>
<p><a href="https://i.stack.imgur.com/KHDAq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/KHDAq.png" alt="enter image description here" /></a></p>
<p>Now if you deploy the service with <code>nodePort=30080</code> you will be able to access it via <strong>http://localhost:30080/</strong>.</p>
<p>There were issues like this in Minikube installation on MacOS.
Here are some details about the workaround: <a href="https://github.com/kubernetes/minikube/issues/11193" rel="noreferrer">https://github.com/kubernetes/minikube/issues/11193</a></p>
