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

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.



Solution 1:[1]

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.

Solution 2:[2]

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>

Solution 3:[3]

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 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chanaka udaya
Solution 2 Pierre.Vriens
Solution 3 Joshua Blanco