10

I have two kubernetes objects,

apiVersion: v1
kind: Pod
metadata:
  name: client-pod
  labels:
    component: web
spec:
  containers:
  - name: client
    image: stephengrider/multi-client
    resources:
      limits:
        memory: "128Mi"
        cpu: "500m"
    ports:
      - containerPort: 3000

apiVersion: v1
kind: Service
metadata:
  name: client-node-port
spec:
  type: NodePort
  selector:
    component: web
  ports:
  - port: 3050
    targetPort: 3000
    nodePort: 31515

and i applied both using kubectl apply -f <file_name> after that, here is the output

kubectl get services
NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
client-node-port      NodePort    10.100.230.224   <none>        3050:31515/TCP   30m

the pod output

NAME                                  READY   STATUS    RESTARTS   AGE
client-pod                            1/1     Running   0          28m

but when i run minikube ip it returns 127.0.0.1, i'm using minikube with docker driver.

After following this issue https://github.com/kubernetes/minikube/issues/7344. i got the node-ip using

kubectl get node -o json |
        jq --raw-output \
          '.items[0].status.addresses[]
            | select(.type == "InternalIP")
              .address
          '

But even then i am not able to access the service. After more searching i find out

minikube service --url client-node-port
  Starting tunnel for service client-node-port.
|-----------|------------------|-------------|------------------------|
| NAMESPACE |       NAME       | TARGET PORT |          URL           |
|-----------|------------------|-------------|------------------------|
| default   | client-node-port |             | http://127.0.0.1:52694 |
|-----------|------------------|-------------|------------------------|
http://127.0.0.1:52694
❗  Because you are using a Docker driver on darwin, the terminal needs to be open to run it.

i can access the service using minikube service.

Question:

  1. But i want to know why the nodePort exposed didn't work ?
  2. why did i do this workaround to access the application.

More Information:

minikube version
minikube version: v1.10.1
commit: 63ab801ac27e5742ae442ce36dff7877dcccb278

docker version
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:21:11 2020
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:29:16 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

kubectl version
Client Version: version.Info{Major:"1", Minor:"16+", GitVersion:"v1.16.6-beta.0", GitCommit:"e7f962ba86f4ce7033828210ca3556393c377bcc", GitTreeState:"clean", BuildDate:"2020-01-15T08:26:26Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2", GitCommit:"52c56ce7a8272c798dbc29846288d7cd9fbae032", GitTreeState:"clean", BuildDate:"2020-04-16T11:48:36Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}

if you need more info, i'm willing to provide.

minikube ssh

docker@minikube:~$ ip -4 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    inet 172.18.0.1/16 brd 172.18.255.255 scope global docker0
       valid_lft forever preferred_lft forever
945: eth0@if946: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default  link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
Sathish
  • 2,056
  • 3
  • 26
  • 40
  • What URL are you trying to connect to? What error do you get? – David Maze Jun 14 '20 at 17:43
  • @DavidMaze applications runs inside the container in port 3000, containerPort is 3000, port - 3050, targetPort is 3000 & nodePort is 31515, i am trying to access the base url of my applications, meaing http://:/ E.g: http://minikube_ip:31515/ – Sathish Jun 14 '20 at 19:23
  • Wouldn't it be easier to simply list the available network interfaces and their IPv4 addresses on your minikube host ? What does `ip -4 a` show when you run it on your Minikube host/node ? – mario Jun 17 '20 at 16:42
  • @mario thank you for responding. Have added the `ip -4 a` response in the post please check it. – Sathish Jun 18 '20 at 07:41
  • So cannot you reach your app via `http://172.17.0.2:31515` ? – mario Jun 18 '20 at 22:42
  • Yeah. @mario . Are you on twitter / on other platform where i can chat with you ? Just to understand this bug. I guess i am lacking basic networking concept or something. – Sathish Jun 19 '20 at 05:12
  • Actually I'm not but you can ask here as many questions as you need :) We can also move this conversation to chat if there is such need. However, looking at the **GitHub** issue you posted, it looks like the fact that `minikube ip` returns `127.0.0.1` is not a bug as mentioned [here](https://github.com/kubernetes/minikube/issues/7344#issuecomment-607318525): _"This is a design decision (for the docker driver), and not really a bug per se."_ – mario Jun 25 '20 at 19:43
  • So, how were you guys able to get the IP. I tried looking at the #7344 but didn't get the solution. – Ashish Bansal Jul 15 '20 at 17:33

3 Answers3

17

I had the same problem. The issue is not with the IP 127.0.0.1. The issue was that I was calling the port I have defined in the YAML file for NodePort. It looks like minikube will assign a different port for external access.

The way I did:

  • List all services in a nice formatted table:
    $minikube service list 
    
  • Show IP and external port:
    $minikube service Type-Your-Service-Name
    

If you do that minikube will open the browser and will run your app.

oscarmlage
  • 1,445
  • 2
  • 12
  • 23
Marcio
  • 186
  • 4
2

This command will help.

minikube service --url $SERVICE
  • Port defined in service is not what minikube expose. In service I have define 30007 and the above command returns 41975 and is the correct port (working) – Adrian Jan 24 '23 at 06:35
1

I had the same problem.

  • Download and install VirtualBox(VirtualBox.org)

  • Install minikube

  • brew reinstall minikube (if already install)

  • minikube start --vm-driver=virtualbox

  • minikube ip (This will return IP)

Which can be used to open in browser and will run your app.