<p>I have multiple services running across nodes.</p>
<p>I want to be able to query a postgres db from the pods of these services - This postgres db will only allow connections from whitelisted IPs - I will need to share a static IP with the admin of postgres db to be able to connect to it.</p>
<p>How can I ensure that no matter which node my pod is on, I can connect to the postgres db using a predefined static IP?</p>
<p>My current set up is :</p>
<p>NGINX INGRESS (Static IP) --&gt; host based routing to certain services.</p>
<blockquote>
<p>123.abc.com --&gt; Service A --&gt; Pod A --&gt; Node A --&gt; External IP A</p>
<p>456.abc.com --&gt; Service B --&gt; Pod B --&gt; Node B --&gt; External IP B</p>
</blockquote>
<p>Pods of these services get external IP of the node they are on. Services are of type NodePort.</p>
<p>__
Possible Solution :</p>
<p>I am now trying to set up a common service - Service Postgres - that will query the Postgres DB. All other services will just query postgres service explicitly everytime they want to access postgres.</p>
<p>I assigned an External IP to the Service. But the pod queries from the IP of the node. It seems the external IP in the load balancer is for incoming requests? How do we assign a fixed IP to outgoing requests?</p>

crossvalidator
<p><a href="https://stackoverflow.com/questions/41133755/static-outgoing-ip-in-kubernetes">Outgoing IP for pods in K8s - Question on Stackoverflow</a></p>

<p>The answers on that question are satisfactory. </p>

<ol>
<li><p>Create a helper service that talks to PostgreSQL. Schedule it on a specific node in a new node pool using node selector. Assign that node a static IP using the steps mentioned in the above link. (haven't tested this step yet) (<a href="https://blog.doit-intl.com/kubeip-automatically-assign-external-static-ips-to-your-gke-nodes-for-easier-whitelisting-without-2068eb9c14cd" rel="nofollow noreferrer">KubeIP</a> seems like a neat solution for this) </p></li>
<li><p>Use NAT Gateway in GKE in a private cluster. <a href="https://cloud.google.com/nat/docs/gke-example" rel="nofollow noreferrer">NAT Gateway GKE</a></p></li>
</ol>

<p>1st option seems easier to implement, 2nd one is more generic. </p>
