<p>I have the following architecture for the PostgreSQL cluster:</p>
<p><a href="https://i.stack.imgur.com/TlP1l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TlP1l.png" alt="enter image description here" /></a></p>
<p>Here, there are multiple clients that interacts with PostgreSQL pods via pgpool, the issue is, when the pod (could be <code>pgpool</code> or <code>PostgreSQL</code> pod) terminates (for multiple reasons) the client is getting impacts and have to recreate the connection. For example in this diagram, if <code>postgresql-1</code> pod terminates then <code>client-0</code> will have to recreate the connection with the cluster.</p>
<p>Is there a way in kubernetes to handle it so that connections to <code>pgpool k8s service</code> are load balanced/ recreated to other pods so that the clients do not see the switch over <strong>and are not impacted</strong>?</p>
<p>Please note these are TCP connections and not HTTP connections (which are stateless). Also, all the PostgreSQL pods are <a href="https://www.postgresql.org/docs/10/runtime-config-wal.html#SYNCHRONOUS-COMMIT-MATRIX" rel="nofollow noreferrer">always in sync with remote_apply</a>.</p>

Vishrant
<p>Without substantial custom code to allow TCP connection transfers between hosts, you kind of can't. When a process shuts down, all TCP streams it has open will be closed, that's how normal Linux networking functions. If you poke a round on your search engine of choice for things like &quot;TCP connection migration&quot; you'll find a lot of research efforts on this but little actual code. More often you just terminate the TCP connection at some long-lived edge proxy and if <em>that</em> has to restart you eat the reconnects.</p>
