<p>I am trying to create Kubernetes cluster using three VMs(Master – 10.x.x.4, Node1  – 10.x.x.150, Node2  – 10.x.x.160).</p>

<p>I was able to create the guestbook application successfully following this link: <a href="http://kubernetes.io/v1.0/examples/guestbook/" rel="noreferrer">http://kubernetes.io/v1.0/examples/guestbook/</a>.  Only one change I made to frontend-service.yaml: to use NodePort. I can access the frontend service using nodes IP and port number(10.x.x.150:30724 or 10.x.x.160:30724). So everything is working as expected but I am not able to access the frontend service using ClusterIP address(in my case 10.x.x.79).</p>

<p>My understanding of NodePort is that the service can be accessed through cluster IP and also on a port on each node of the cluster. How can I access the service through ClusterIP so that I don’t have to access the each node?  Am I missing something here?</p>

<p><strong>service and pod details</strong></p>

<p><strong>$sudo kubectl describe service frontend</strong></p>

<pre><code>Name:                   frontend
Namespace:              default
Labels:                 name=frontend
Selector:               name=frontend
Type:                   NodePort
IP:                     10.x.x.79
Port:                   &lt;unnamed&gt;       80/TCP
NodePort:               &lt;unnamed&gt;       30724/TCP
Endpoints:              172.x.x.13:80,172.x.x.14:80,172.x.x.11:80
Session Affinity:       None

No events.
</code></pre>

<p><strong>$sudo kubectl describe pod frontend-2b5us</strong></p>

<pre><code>Name:                           frontend-2b5us
Namespace:                      default
Image(s):                       gcr.io/google_samples/gb-frontend:v3
Node:                           10.x.x.150/10.x.x.150
Labels:                         name=frontend
Status:                         Running
Reason:
Message:
IP:                             172.x.x.11
Replication Controllers:        frontend (3/3 replicas created)
Containers:
  php-redis:
    Image:              gcr.io/google_samples/gb-frontend:v3
    State:              Running
      Started:          Fri, 30 Oct 2015 04:00:40 -0500
    Ready:              True
    Restart Count:      0
</code></pre>

<p>I tried to search but would not find any solution for my exact problem but I did find similar problem  that looks like for GCE.</p>

<p><a href="https://stackoverflow.com/questions/32618437/why-cant-i-access-my-kubernetes-service-via-its-ip">Why can&#39;t I access my Kubernetes service via its IP?</a></p>

<p>You do not have ClusterIP service. You do have a NodePort service. To access it, you connect to the NodePort on any of your nodes in the cluster, as you've already discovered. You do get load-balancing here. Even though you connect to a cluster node, the pod you get does not necessarily run on that particular node.</p>

<p>Read the relevant section in the documentation at <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services---service-types" rel="noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services---service-types</a> to learn about additional service types. You probably do not want NodePort on GCP.</p>

<p>Talking about ClusterIP. To access a ClusterIP service for debugging purposes, you can run <code>kubectl port-forward</code>. You will not actually access the service, but you will directly connect to one of the pods.</p>

<p>For example</p>

<pre><code>kubectl port-forward frontend-2b5us 80 8080
</code></pre>

<p>Now connect to localhost:8080</p>

<p>More sophisticated command, which discovers the port on its own, given namespace <code>-n weave</code> and a selector. Taken from <a href="https://www.weave.works/docs/scope/latest/installing/" rel="noreferrer">https://www.weave.works/docs/scope/latest/installing/</a></p>

<pre><code>kubectl port-forward -n weave \
    "$(kubectl get -n weave pod \
         --selector=weave-scope-component=app \
         -o jsonpath='{.items..metadata.name}')" \
    4040
</code></pre>
