Docker for Desktop runs the Kubernetes - Ip address is not working

7/13/2019

kubectl describe node docker-for-desktop This gets the IP address of Docker desktop for Windows.

But we run it on browser with ip:nodeport it is not working.

nodeport - is the port number that we mention in the services file of kubernetes cluster.

Please find myservice.yaml file in the code section.

apiVersion: v1
kind: Service
metadata:
  name: xxxx

spec:
  # This defines which pods are going to be represented by this Service
  # The service becomes a network endpoint for either other services
  # or maybe external users to connect to (eg browser)
  selector:
    mykey: webapp
    release: "0-5"

  ports:
    - name: http
      port: 80
      nodePort: 30080
      #this is port number greater than 30000, and it is port of the Node where this cluster is present.

  type: NodePort

http://<dockerDesktopIdaddress>:<nodeport>

nodeport is the port number in the service file of kubernetes cluster.

always gives error.

-- Rajasekar Murugesan
desktop
docker
ip
kubernetes

2 Answers

7/13/2019

Docker For Windows , Docker For MAC , or Docker for anything uses minikube for kubernetes , and you need to get the external ip of minikube machine.

You need the external IP instead of internal IP , the kubectl is showing only the internal IP.

C02W84XMHTD5:test iahmad$ 
C02W84XMHTD5:test iahmad$ 
C02W84XMHTD5:test iahmad$ 
C02W84XMHTD5:test iahmad$ kubectl describe node minikube | grep -i ip
  InternalIP:  10.0.2.15
C02W84XMHTD5:test iahmad$ 
C02W84XMHTD5:test iahmad$ 
C02W84XMHTD5:test iahmad$ kubectl get svc
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP        30d
nginx        NodePort    10.107.66.154   <none>        80:32622/TCP   4m
C02W84XMHTD5:test iahmad$ 
C02W84XMHTD5:test iahmad$ 
C02W84XMHTD5:test iahmad$ curl 10.0.2.15:32622


รงรงรงรง^C
C02W84XMHTD5:test iahmad$ 
C02W84XMHTD5:test iahmad$ 
C02W84XMHTD5:test iahmad$ minikube ssh
                         _             _            
            _         _ ( )           ( )           
  ___ ___  (_)  ___  (_)| |/')  _   _ | |_      __  
/' _ ` _ `\| |/' _ `\| || , <  ( ) ( )| '_`\  /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )(  ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)

$ 
$ ip a s | grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0
$ 
$ ip a s | grep eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 192.168.99.105/24 brd 192.168.99.255 scope global dynamic eth1
$ 
$ logout
C02W84XMHTD5:test iahmad$ 
C02W84XMHTD5:test iahmad$ curl 192.168.99.105:32622
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

Edit:

As suggested in the comments , if you don't want to see inside the minikube machine , you can use the following command to get the external IP:

 minikube ip
-- Ijaz Ahmad Khan
Source: StackOverflow

1/28/2020

I had the same issue and the resolution was simple. curl localhost:$NODE_PORT

Docker for Mac runs on the same host and you can call the service through localhost.

-- Chanaka udaya
Source: StackOverflow