<p>I want to connect GKE (Google Kubernetes Engine) cluster to MongoDB Atlas. But I need to green the IP of my nodes (allow them). But sometimes I have 3 nodes, sometimes I have 10 and sometimes nodes are falling down and re-creating - constant changing means no single IP.</p>
<p>I have tried to create NAT on the GCP followed this guide: <a href="https://medium.com/google-cloud/using-cloud-nat-with-gke-cluster-c82364546d9e" rel="nofollow noreferrer">https://medium.com/google-cloud/using-cloud-nat-with-gke-cluster-c82364546d9e</a></p>
<p>Also I want to green my cluster's IP in the Google Maps APIs so I can use the Directions API, for example.</p>
<p>This is a common situation, since there may be many other third party APIs that I want to enable that require incoming requests from certain IPs only, besides Atlas or Google Maps..</p>
<p>How can I achieve this?</p>

<p>Private GKE cluster means the nodes do not have public IP addresses but you mentioned</p>
<blockquote>
<p>the actual outbound transfer goes from the node's IP instead of
the NAT's</p>
</blockquote>
<p>Looks like you have a public cluster of GKE, you have to use the same NAT option to get outbound egress <strong>single IP</strong>.</p>
<p>If you are using the <strong>ingress</strong> which means there is a <strong>single point</strong> for incoming request to <strong>cluster</strong> but if your Nodes have <strong>public IP</strong> PODs will use <strong>Node's IP</strong> when there is an outgoing request unless you use <strong>NAT</strong> or so.</p>
<p>Your single outbound IP will be there, so all requests going out of PODs won't have node's IP instead they will use the <strong>NAT</strong> IP.</p>
<p><strong>how to set up the NAT gateway</strong></p>
<p><a href="https://registry.terraform.io/modules/GoogleCloudPlatform/nat-gateway/google/latest/examples/gke-nat-gateway" rel="nofollow noreferrer">https://registry.terraform.io/modules/GoogleCloudPlatform/nat-gateway/google/latest/examples/gke-nat-gateway</a></p>
<p>Here is terraform ready for the GKE clusters, you just have to run this terraform example bypassing <strong>project ID</strong> and others <strong>vars</strong>.</p>
<p>The above terraform example will create the NAT for you and verify the PODs IP as soon as NAT is set. You mostly won't require any changes in NAT terraform script.</p>
<p>GitHub link: <a href="https://github.com/GoogleCloudPlatform/terraform-google-nat-gateway/tree/v1.2.3/examples/gke-nat-gateway" rel="nofollow noreferrer">https://github.com/GoogleCloudPlatform/terraform-google-nat-gateway/tree/v1.2.3/examples/gke-nat-gateway</a></p>
<p>if you dont have idea of terraform you can follow this article to setup the NAT which will stop the SNAT for PODs : <a href="https://rajathithanrajasekar.medium.com/google-cloud-public-gke-clusters-egress-traffic-via-cloud-nat-for-ip-whitelisting-7fdc5656284a" rel="nofollow noreferrer">https://rajathithanrajasekar.medium.com/google-cloud-public-gke-clusters-egress-traffic-via-cloud-nat-for-ip-whitelisting-7fdc5656284a</a></p>
