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.
I think that clusterIP is only reachable inside a cluster but when i activated the NodePort might be works.
I am not know well the difference between NodePort and ClusterIP.
2
Answers
Cluster IP address is only accessible within cluster; so that’s why it is giving timeout message. Nodeport use to expose a port on Public IP of every node of cluster; so it may work.
Background
You can expose your application outside cluster using NodePort or LoadBalancer.
ClusterIP
allows connection only inside the cluster and it’s default Service type.In short, when you are using
NodePort
you need to useNodePublicIP:NodePort
. When you are usingLoadBalancer
it will createNetwork LB
withExternalIP
.In your GKE cluster you have something called VPC – Virtual Private Cloud which provides networking for your cloud-based resources and services that is global, scalable, and flexible.
Solution
Using VPC-Native CLuster
Wit VPC-native clusters you’ll be able to reach to Pod’s IPs directly. You will need to create
subnet
in order to do it. Full guide can be found hereUsing VPC Peering
If you would like to connect from 2 different projects in GKE, you will need to use VPC Peering.
Access from outside the cluster using NodePort
If you would like to reach your nginx service from outside you can use
NodeIP:NodePort
.NodeExternalIP
(keep in mind that this node must have application pod on it. If you have 3 nodes and only 1 application replica, you must useNodeExternalIP
where this pod was deployed. Another node, you need to allowNodePort
access onFirewall
.