<p>I am trying to access an external postgres from my pod. The problem is that in order to do this, I need to allow in the external database <code>pg_hba.conf</code> the &quot;host address&quot;/ &quot;IP&quot; of the pod. It is clear that I can temporarily use the address of the node, e.g. someNode.online-server.cloud.</p>
<p>The problem is that of course, if the pod restarts, it might restart on another node. For the converse problem, I could use a service/endpoint that would provide an anchor for all external traffic to go through... Is there a way to do something like this in my case? I am thinking port forwarding on a host can be both ways, but not sure what to do in K8s.</p>

ntg
<p>It's <a href="https://www.postgresql.org/docs/current/auth-pg-hba-conf.html" rel="nofollow noreferrer">documented</a> that the address field can be a CIDR.</p>
<blockquote>
<p>Specifies the client machine address(es) that this record matches. This field can contain either a host name, an IP address range, or one of the special key words mentioned below.</p>
</blockquote>
<p>Therefore, you can add the CIDR of the subnet of your cluster, given the assumption, this is within a private network.</p>
<p>This might look something like this:</p>
<pre><code># TYPE  DATABASE        USER            ADDRESS                 METHOD
host    app             app             192.168.0.0/16          scram-sha-256
</code></pre>
<p>If this goes through the public web, all pods are likely to go through the same gateway and therefore get the same IP assigned, which you can use.</p>
<p>Alternatively, you can also use a hostname.</p>
