<p>I have GKE with public nodes(nodes having its external IP), I want to connect with the MySql database which is running inside a VM in a different project. I tried to connect with the load balancer but it's getting timed out. I tried with cloud NAT, still I cannot make the connection.</p>
<p>However, I am able to connect if I whitelist the exact external IP of the node where the pod is running (from where I want to connect with the database). But I cannot add all the node external IPs to the firewall since it has a lot of nodes.</p>
<p>What is the way to create single external IP which I can use to whitelist so I can make connection to the VM from Public GKE Cluster?</p>

abbas gori
<p>You have to set the <strong>NAT gateway</strong> in front of all the VMs or nodes running your GKE cluster.</p>
<p>So all the outgoing traffic goes from a single <strong>egress</strong> point.</p>
<p>You can check : <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>you can directly apply it and your GKE will be running behind the NAT and all traffic from the pod will be going out from the single point.</p>
<p>to verify <strong>egress</strong> is working or not</p>
<p>you can <code>exec</code> into the pod and send <code>curl ifconfig.me</code> request in response you get your external IP.</p>
<p>Try from the pods scheduled on <strong>different nodes</strong>.</p>
<p>Once everything is set you can <strong>whitelist</strong> the <strong>NAT IP</strong> in the database.</p>
