K
Q

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

July 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
docker
kubernetes
ip
desktop

4 Answers

January 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

October 9, 2020

Another good command to use is

kubectl describe service your-service-name
. This way you can see all the kubernetes network objects

kubectl describe service configuration-service-service

Name:                     configuration-service-service
Namespace:                default
Labels:                   none
Annotations:              none
Selector:                 app=configuration-service-deployment
Type:                     NodePort
IP:                       10.109.61.232
LoadBalancer Ingress:     localhost
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  30001/TCP
Endpoints:                10.1.0.40:8080,10.1.0.41:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
-- Taras Gleb
Source: StackOverflow

May 1, 2022

Double-check if an External IP is defined for the node.

kubectl get nodes -o wide

Lookup the LoadBalancer Ingress defined in the service

kubectl describe svc service_name 

Write down the LoadBalancer Ingress: in this case "localhost"

so finally, you can try :

curl http://localhost:PORT 
-- Joshua Blanco
Source: StackOverflow

July 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
Source: StackOverflow