Mirosław Haręza
Mirosław Haręza

Reputation: 81

minikube on WSL2 (windows 10) - minikube ip not reachable

I've installed the minikube instance on my local computer (--driver=docker). The minikube ip is 192.168.49.2. When I start minikube (minikube start --memory 7168) I get no errors on console. But trying to ping the minikube ip fails. What I do wrong?

$ kubectl get nodes -o wide
NAME       STATUS   ROLES                  AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION                   CONTAINER-RUNTIME
minikube   Ready    control-plane,master   9d    v1.20.2   192.168.49.2   <none>        Ubuntu 20.04.1 LTS   5.4.72-microsoft-standard-WSL2   docker://20.10.3

Upvotes: 8

Views: 12383

Answers (5)

Hossein
Hossein

Reputation: 1768

Run this command:

minikube service --all

This is a sample output:

|-----------|------------|-------------|--------------|
| NAMESPACE |    NAME    | TARGET PORT |     URL      |
|-----------|------------|-------------|--------------|
| default   | kubernetes |             | No node port |
|-----------|------------|-------------|--------------|
😿  service default/kubernetes has no node port
|-----------|---------------|-------------|--------------|
| NAMESPACE |     NAME      | TARGET PORT |     URL      |
|-----------|---------------|-------------|--------------|
| default   | mongo-service |             | No node port |
|-----------|---------------|-------------|--------------|
😿  service default/mongo-service has no node port
|-----------|----------------|-------------|---------------------------|
| NAMESPACE |      NAME      | TARGET PORT |            URL            |
|-----------|----------------|-------------|---------------------------|
| default   | webapp-service |        3000 | http://192.168.49.2:30100 |
|-----------|----------------|-------------|---------------------------|
🏃  Starting tunnel for service kubernetes.
🏃  Starting tunnel for service mongo-service.
🏃  Starting tunnel for service webapp-service.
|-----------|----------------|-------------|------------------------|
| NAMESPACE |      NAME      | TARGET PORT |          URL           |
|-----------|----------------|-------------|------------------------|
| default   | kubernetes     |             | http://127.0.0.1:34355 |
| default   | mongo-service  |             | http://127.0.0.1:43027 |
| default   | webapp-service |             | http://127.0.0.1:45361 |
|-----------|----------------|-------------|------------------------|
🎉  Opening service default/kubernetes in default browser...
👉  http://127.0.0.1:34355
🎉  Opening service default/mongo-service in default browser...
👉  http://127.0.0.1:43027
🎉  Opening service default/webapp-service in default browser...
👉  http://127.0.0.1:45361
❗  Because you are using a Docker driver on linux, the terminal needs to be open to run it.

And at the end you can see list of ip/ports that you can access from Windows. For example, I can open my "default/webapp-service" service using "http://127.0.0.1:45361". It will go throught the tunnel made by minikube. No extra configuration is needed.

And here is the command documentation and details:

Returns the Kubernetes URL(s) for service(s) in your local cluster. In the case
of multiple URLs they will be printed one at a time.

Available Commands:
  list          Lists the URLs for the services in your local cluster

Options:
    --all=false:
        Forwards all services in a namespace (defaults to "false")

    --https=false:
        Open the service URL with https instead of http (defaults to "false")

    --interval=1:
        The initial time interval for each check that wait performs in seconds

    -n, --namespace='default':
        The service namespace

    --url=false:
        Display the Kubernetes service URL in the CLI instead of opening it in
        the default browser

    --wait=2:
        Amount of time to wait for a service in seconds

Usage:
  minikube service [flags] SERVICE [options]

Use "minikube service <command> --help" for more information about a given
command.
Use "minikube options" for a list of global command-line options (applies to all
commands).

Upvotes: 1

bizimunda
bizimunda

Reputation: 1035

Solution is to run by the name of your service

minikube service <<*your_service_name*>> 

has worked for me as well. And this is the same solution I have seen on the minikube's official website. They have given an example of how to create a service. And if you want to expose that service then you have run the same command as above.

enter image description here

Upvotes: 0

SteveSims
SteveSims

Reputation: 635

On your windows system, after the creation of the container that is created by the initial "minikube start", you can see the "minikube instance" by typing "docker ps". This is the minikube 'master' node running in this container.

It would look something like this:

CONTAINER ID   IMAGE                                 COMMAND                  CREATED       STATUS             PORTS                                                                                                                                  NAMES
6293ca0ba5b0   gcr.io/k8s-minikube/kicbase:v0.0.25   "/usr/local/bin/entr…"   2 hours ago   Up About an hour   127.0.0.1:59539->22/tcp, 127.0.0.1:59540->2376/tcp, 127.0.0.1:59537->5000/tcp, 127.0.0.1:59538->8443/tcp, 127.0.0.1:59536->32443/tcp   minikube

In the PORTS column you will see ports that are forwarded by virtue of the way that minikube start the docker container. You can see these kinds of forwards are handled by docker the same as for any contain that you might do a "docker run -p port:port"

Notice that the first port forward in this list is the ssh port: "127.0.0.1:59539->22/tcp".

When you do a "minikube tunnel", minikube will open ssh.exe instances that you can see in your windows task manager if you enable the Command Line display in the column settings.

Those 'tunnels' would look like this:

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -N [email protected] -p 59539 -i C:\Users\steve.sims\.minikube\machines\minikube\id_rsa "-L 8080:10.102.174.166:8080"

If I take that command apart and only run this from the command prompt:

ssh [email protected] -p 59539 -i C:\users\steve.sims\.minikube\machines\minikube\id_rsa

Then I get an interactive remote window into the minikube VM (or node). Typing 'ifconfig eth0' I get:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.49.2  netmask 255.255.255.0  broadcast 192.168.49.255

So, indeed my minikube ip is 192.168.49.2, but it is an internal address as the folks above mentioned.

Other than that, the -N parameter on the ssh means "no command" and the -L on the end is the port forward flag in port-to-forward:destination-socket format. Of course, so all of the tunnels are coming across that initial docker -p port:port forward that minikube established when the container was started.

If it is useful, you can create your own ssh instances from that line's format by script and they will work just as well.

Upvotes: 1

acid_fuji
acid_fuji

Reputation: 6853

Just to add a bit on top of the previous answer. There is docker bridge limitation that makes it impossible to route the traffic to Linux containers. That is why the minikube tunnel and service were implemented as workaround for that.

minikube tunnel runs as a process, creating a network route on the host to the service CIDR of the cluster using the cluster’s IP address as a gateway. The tunnel command exposes the external IP directly to any program running on the host operating system.

Alternative way to that you may find interesting would be using an ingress which was enabled in #9761 pull request:

.\minikube-windows-amd64.exe addons enable ingress                                                                                           I1121 00:59:39.443965    3000 translate.go:89] Failed to load translation file for en: Asset translations/en.json not found
* After the addon is enabled, please run "minikube tunnel" and your ingress resources would be available at "127.0.0.1"
* Verifying ingress addon...
* The 'ingress' addon is enabled

Upvotes: 4

hagrawal7777
hagrawal7777

Reputation: 14688

Recall that minikube is local Kubernetes - it runs a single-node Kubernetes cluster on your personal computer so that you can try out Kubernetes. Now, it doesn't run the Kubernetes cluster in your local box, it runs it inside a VM.

That is why you can't simply access Node IP from your local. Another way to see it is that in Kubernetes you can create NodePort Service to access your workload outside of your cluster but this doesn't work when you are running Kubernetes using minikube - and the reason is the same as mentioned above.

Now, how you work around that is by using minikube service <<YOUR_SERVICE_NAME>> command. This will create a tunnel to access your application - which is exposed using the Service - from outside of the K8S cluster.


You can try minikube tunnel as mentioned by @Hackerman but I have never tried it.

Upvotes: 14

Related Questions