<p>I have an Nginx service deployed in GKE with a NodePort exposed and i want to connect it from my Compute Engine instances through internal IP address only. When i try to connect to the Nginx with the cluster IP i only receive Timeout.</p>
<p>I think that clusterIP is only reachable inside a cluster but when i activated the NodePort might be works.</p>
<p>I am not know well the difference between NodePort and ClusterIP.</p>

Luna
<h2>Background</h2>
<p>You can expose your application outside cluster using <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="nofollow noreferrer">NodePort</a> or <a href="https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer" rel="nofollow noreferrer">LoadBalancer</a>. <code>ClusterIP</code> allows connection only inside the cluster and it's default <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">Service type</a>.</p>
<ul>
<li>ClusterIP:</li>
</ul>
<blockquote>
<p>Exposes the Service on a cluster-internal IP. Choosing this value makes the Service only reachable from within the cluster. This is the default ServiceType</p>
</blockquote>
<ul>
<li>NodePort:</li>
</ul>
<blockquote>
<p>Exposes the Service on each Node's IP at a static port (the NodePort). A ClusterIP Service, to which the NodePort Service routes, is automatically created. You'll be able to contact the NodePort Service, from outside the cluster, by requesting :.</p>
</blockquote>
<ul>
<li>LoadBalancer</li>
</ul>
<blockquote>
<p>Exposes the Service externally using a cloud provider's load balancer. NodePort and ClusterIP Services, to which the external load balancer routes, are automatically created.</p>
</blockquote>
<p>In short, when you are using <code>NodePort</code> you need to use <code>NodePublicIP:NodePort</code>. When you are using <code>LoadBalancer</code> it will create <code>Network LB</code> with <code>ExternalIP</code>.</p>
<p>In your GKE cluster you have something called <a href="https://cloud.google.com/vpc/docs/overview" rel="nofollow noreferrer">VPC - Virtual Private Cloud</a> which provides networking for your cloud-based resources and services that is global, scalable, and flexible.</p>
<h2>Solution</h2>
<p><strong>Using VPC-Native CLuster</strong>
Wit <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/alias-ips" rel="nofollow noreferrer">VPC-native clusters</a> you'll be able to reach to Pod's IPs directly. You will need to create <code>subnet</code> in order to do it. Full guide can be found <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/alias-ips" rel="nofollow noreferrer">here</a></p>
<p><strong>Using VPC Peering</strong>
If you would like to connect from 2 different projects in GKE, you will need to use <a href="https://cloud.google.com/vpc/docs/vpc-peering" rel="nofollow noreferrer">VPC Peering</a>.</p>
<p><strong>Access from outside the cluster using NodePort</strong></p>
<p>If you would like to reach your nginx service from outside you can use <code>NodeIP:NodePort</code>.
<code>NodeExternalIP</code> (keep in mind that this node must have application pod on it. If you have 3 nodes and only 1 application replica, you must use <code>NodeExternalIP</code> where this pod was deployed. Another node, you need to allow <code>NodePort</code> access on <code>Firewall</code>.</p>
<pre><code>$ kubectl get nodes -o wide
NAME                                       STATUS   ROLES    AGE     VERSION             INTERNAL-IP   EXTERNAL-IP     OS-IMAGE                             KERNEL-VERSION   CONTAINER-RUNTIME
gke-cluster-1-default-pool-faec7b51-n5hm   Ready    &lt;none&gt;   3h23m   v1.17.14-gke.1600   10.128.0.26   23.236.50.249   Container-Optimized OS from Google   4.19.150+        docker://19.3.6

$ kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
nginx        NodePort    10.8.9.10    &lt;none&gt;        80:30785/TCP   39m

$ curl 23.236.50.249:30785
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Welcome to nginx!&lt;/title&gt;
</code></pre>
