<p><strong>Requirement</strong> : With private GKE ( version : <strong>1.21.11-gke.1100</strong> ), each pod is required to have a dedicated public IP as source IP when reaching to internet. It is not required for ingress but only for egress.</p>
<p><strong>Solution tried</strong> : Cloud NAT. Works partially. Meaning, suppose we have 10 pods and each of them is made to run on a distinct node. Cloud NAT does not assign an unique IP to each pod even when the <code>Minimum ports per VM instance</code> is set to the maximum possible value of <code>57344</code>.</p>
<p><strong>Experiment Done</strong>: 10 NAT gateway IPs are assigned to the NAT Gateway. 8 pods are created, each running on a dedicated node. Cloud NAT assigned only 3 Cloud NAT IPs instead of 8 even though there aee 10 IPs available.</p>
<p>Cloud NAT is configured as below :</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Configuration</th>
<th>Setting</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Manual NAT IP address assignment</code></td>
<td><strong>true</strong></td>
</tr>
<tr>
<td><code>Dynamic port allocation</code></td>
<td><code>disabled</code></td>
</tr>
<tr>
<td><code>Minimum ports per VM instance</code></td>
<td><code>57344</code>. This decides how many VMs can be assigned to the same Cloud NAT IP.</td>
</tr>
<tr>
<td><code>Endpoint-Independent Mapping</code></td>
<td><code>disabled</code></td>
</tr>
</tbody>
</table>
</div>
<p><strong>Instead of converting to a Public GKE cluster</strong>, is there an easier way of achieving this goal?</p>
<p>Has anyone ever done such a setup which is proved to work?</p>

Baskar Lingam Ramachandran
<p>You can create the <strong>NAT gateway instance</strong> and forward the traffic from there.</p>
<p>Here terraform script to create : <a href="https://github.com/GoogleCloudPlatform/terraform-google-nat-gateway/tree/master/examples" rel="nofollow noreferrer">https://github.com/GoogleCloudPlatform/terraform-google-nat-gateway/tree/master/examples</a></p>
<p><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>If you are looking to use cloud NAT with route you can checkout this : <a href="https://github.com/GoogleCloudPlatform/gke-private-cluster-demo/blob/master/README.md#private-clusters" rel="nofollow noreferrer">https://github.com/GoogleCloudPlatform/gke-private-cluster-demo/blob/master/README.md#private-clusters</a></p>
<p>TF code for NAT : <a href="https://github.com/GoogleCloudPlatform/gke-private-cluster-demo/blob/master/terraform/network.tf#L84" rel="nofollow noreferrer">https://github.com/GoogleCloudPlatform/gke-private-cluster-demo/blob/master/terraform/network.tf#L84</a></p>
<p>Demo architecture : <a href="https://github.com/GoogleCloudPlatform/gke-private-cluster-demo/blob/master/README.md#demo-architecture" rel="nofollow noreferrer">https://github.com/GoogleCloudPlatform/gke-private-cluster-demo/blob/master/README.md#demo-architecture</a></p>
