Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I model a PostgreSQL failover cluster with Docker/Kubernetes?

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 (pgpool-II, repmgr, pick your poison).

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 postgresql-standby replication controller separately from a postgresql-master 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 postgresql replication controller after all.

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.

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

Is that the correct approaach, or is there any other cleaner way?

like image 550
Nikolai Prokoschenko Avatar asked Apr 04 '15 21:04

Nikolai Prokoschenko


People also ask

What is high availability in PostgreSQL?

HA is the measure of system resiliency in response to underlying infrastructure failure. In this document, HA refers to the availability of PostgreSQL clusters either within a single cloud region or between multiple regions, depending on the HA architecture.


1 Answers

There's an example in OpenShift: https://github.com/openshift/postgresql/tree/master/examples/replica 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)

like image 173
Clayton Avatar answered Sep 20 '22 11:09

Clayton