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 pg_hba.conf
the "host address"/ "IP" of the pod. It is clear that I can temporarily use the address of the node, e.g. someNode.online-server.cloud.
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.
CodePudding user response:
It's documented that the address field can be a CIDR.
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.
Therefore, you can add the CIDR of the subnet of your cluster, given the assumption, this is within a private network.
This might look something like this:
# TYPE DATABASE USER ADDRESS METHOD
host app app 192.168.0.0/16 scram-sha-256
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.
Alternatively, you can also use a hostname.