<p>I'm still wrapping my head around Kubernetes and how that's supposed to work. Currently, I'm struggling to understand how to model something like a PostgreSQL cluster with streaming replication, scaling out and automatic failover/failback (<code>pgpool-II</code>, <code>repmgr</code>, pick your poison).</p>

<p>My main problem with the approach is the dual nature of a PostgreSQL instance, configuration-wise -- it's either a master or a cold/warm/hot standby. If I increase the number of replicas, I'd expect them all to come up as standbys, so I'd imagine creating a <code>postgresql-standby</code> replication controller separately from a <code>postgresql-master</code> pod. However I'd also expect one of those standbys to become a master in case current master is down, so it's a common <code>postgresql</code> replication controller after all.</p>

<p>The only idea I've had so far is to put the replication configuration on an external volume and manage the state and state changes outside the containers.</p>

<p><em>(in case of PostgreSQL the configuration would probably already be on a volume inside its <code>data</code> directory, which itself is obviously something I'd want on a volume, but that's beside the point)</em></p>

<p>Is that the correct approaach, or is there any other cleaner way?</p>

<p>There's an example in OpenShift: <a href="https://github.com/openshift/postgresql/tree/master/examples/replica">https://github.com/openshift/postgresql/tree/master/examples/replica</a> The principle is the same in pure Kube (it's not using anything truly OpenShift specific, and you can use the images in plain docker)</p>
