How to access services exposed via ClusterIP when using Docker For Windows:

3/25/2020

I installed Docker for windows and the built in k8s single node cluster for dev purposes on a local workstation (windows 10 pro).

I'd like to know how to access services hosted on this cluster. It's not documented very well

I don't have a load balancer installed and don't need a K8s Ingress. How can I access a service hosted at 10.105.245.65:80 . localhost and 127.0.0.1 don't work and 10.105.245.65 has no meaning on the host windows machine .

I could use NodePort (that works) but I'd like to understand how to access via ClusterIP .

C:\Users\balamuvi>kubectl get svc
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP   52m
webserver    ClusterIP   10.105.245.65   <none>        80/TCP    48m ===> how do I access this service

C:\Users\balamuvi>kubectl cluster-info
Kubernetes master is running at https://kubernetes.docker.internal:6443 =======> resolves to localhost
KubeDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
-- Vinay B
docker
kubernetes

2 Answers

3/26/2020

CLusterIP cannot be accessible from outside the cluster. Other method beside execing into pod (as mentioned by Arghya) would be using kubectl port-forward command.

Just run:

kubectl port-forward pods/<pod-name> <local-port>:<pod-port>

and then you can access the pod under localhost:<local-port>

Refer to kubernetes documentation for more information about port forwarding.

-- HelloWorld
Source: StackOverflow

3/25/2020

ClusterIP is not accessible from outside the cluster. You will have to exec into another pod and use curl to access it.

-- Arghya Sadhu
Source: StackOverflow