Search code examples
kuberneteswindows-10minikube

Minikube Services cannot be accessed over NodePort or ClusterIP on Windows10


I am testing something out on my local minikube cluster on a Windows10 machine. I deployed my test deployment on my local minikube cluster and added a service to it to access over NodePort, but I cannot access it.

PS C:\Users\Admin> kubectl get all -n web -o wide
NAME                                          READY   STATUS    RESTARTS   AGE    IP           NODE       NOMINATED NODE   READINESS GATES
pod/nginx-webserver-deploy-79b6588b5f-mllnf   1/1     Running   0          134m   172.17.0.5   minikube   <none>           <none>
pod/nginx-webserver-deploy-79b6588b5f-rvtxt   1/1     Running   0          134m   172.17.0.7   minikube   <none>           <none>
pod/nginx-webserver-deploy-79b6588b5f-xqzwz   1/1     Running   0          134m   172.17.0.6   minikube   <none>           <none>

NAME                              TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE    SELECTOR
service/nginx-webserver-service   NodePort   10.96.115.194   <none>        80:30008/TCP   132m   app=nginx-webserver,tier=frontend

NAME                                     READY   UP-TO-DATE   AVAILABLE   AGE    CONTAINERS        IMAGES         SELECTOR
deployment.apps/nginx-webserver-deploy   3/3     3            3           134m   nginx-webserver   nginx:1.20.2   app=nginx-webserver,tier=frontend

NAME                                                DESIRED   CURRENT   READY   AGE    CONTAINERS        IMAGES         SELECTOR
replicaset.apps/nginx-webserver-deploy-79b6588b5f   3         3         3       134m   nginx-webserver   nginx:1.20.2   app=nginx-webserver,pod-template-hash=79b6588b5f,tier=
frontend


PS C:\Users\Admin> kubectl describe svc nginx-webserver-service -n web
Name:                     nginx-webserver-service
Namespace:                web
Labels:                   <none>
Annotations:              <none>
Selector:                 app=nginx-webserver,tier=frontend
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.96.115.194
IPs:                      10.96.115.194
Port:                     http  80/TCP
TargetPort:               80/TCP
NodePort:                 http  30008/TCP
Endpoints:                172.17.0.5:80,172.17.0.6:80,172.17.0.7:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

But I am not able to connect using nodeport method:

PS C:\Users\Admin> curl 10.96.115.194:30008
curl : Unable to connect to the remote server
At line:1 char:1
+ curl 10.96.115.194:30008
+ ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

I tried disabling the Windows firewall fully but no luck.

I must be missing something core but could not figure out yet.


Solution

  • I found the solution.

    Unlike on Linux, accessing NodePort using the specified port on the service definition yaml file is not a straightforward thing on Windows10.

    On Windows10, it has to be done as follows:

    PS C:\Users\Admin> minikube service nginx-webserver-service -n web
    |-----------|-------------------------|-------------|---------------------------|
    | NAMESPACE |          NAME           | TARGET PORT |            URL            |
    |-----------|-------------------------|-------------|---------------------------|
    | web       | nginx-webserver-service | http/80     | http://192.168.49.2:30008 |
    |-----------|-------------------------|-------------|---------------------------|
    * Starting tunnel for service nginx-webserver-service.
    |-----------|-------------------------|-------------|------------------------|
    | NAMESPACE |          NAME           | TARGET PORT |          URL           |
    |-----------|-------------------------|-------------|------------------------|
    | web       | nginx-webserver-service |             | http://127.0.0.1:61410 |
    |-----------|-------------------------|-------------|------------------------|
    * Opening service web/nginx-webserver-service in default browser...
    ! Because you are using a Docker driver on windows, the terminal needs to be open to run it.
    * Stopping tunnel for service nginx-webserver-service.
    

    This will open the exposed service on your default web-browser automatically.

    Otherwise, you can have it just generated the URL instead of opening automatically.

    PS C:\Users\Admin> minikube service nginx-webserver-service -n web --url
    * Restarting the docker service may improve performance.
    * Starting tunnel for service nginx-webserver-service.
    |-----------|-------------------------|-------------|------------------------|
    | NAMESPACE |          NAME           | TARGET PORT |          URL           |
    |-----------|-------------------------|-------------|------------------------|
    | web       | nginx-webserver-service |             | http://127.0.0.1:52665 |
    |-----------|-------------------------|-------------|------------------------|
    http://127.0.0.1:52665
    ! Because you are using a Docker driver on windows, the terminal needs to be open to run it.
    * Stopping tunnel for service nginx-webserver-service.