[英]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. 我仍在围绕Kubernetes进行工作,这应该如何工作。 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). 目前,我正在努力了解如何使用流复制,扩展和自动故障转移/故障回复( pgpool-II
, repmgr
,选择毒药)对诸如PostgreSQL集群的模型进行建模。
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. 我的方法的主要问题是PostgreSQL实例的双重属性,即配置方面的问题-它既可以是主实例,也可以是冷/热/热备用实例。 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. 如果我增加副本的数量,我希望他们都来充当备用,所以我想像创造了postgresql-standby
从单独复制控制器postgresql-master
舱。 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. 但是我也希望那些备用数据库中的一个能够在当前主数据库发生故障的情况下成为主数据库,因此毕竟这是一个常见的postgresql
复制控制器。
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) (在PostgreSQL的情况下,配置可能已经在其data
目录内的某个卷上,这显然是我想要在卷上执行的操作,但这不重要)
Is that the correct approaach, or is there any other cleaner way? 这是正确的方法,还是还有其他更清洁的方法?
OpenShift中有一个示例: https : //github.com/openshift/postgresql/tree/master/examples/replica该原理在纯Kube中是相同的(它没有使用任何真正的OpenShift特定的东西,您可以使用纯图像码头工人)
You can give PostDock a try, either with docker-compose or Kubernetes. 你可以给PostDock与码头工人,撰写或Kubernetes一试,无论是。 Currently I have tried it in our project with docker-compose, with the schema as shown below: 目前,我已经在我们的项目中使用docker-compose对其进行了尝试,其架构如下所示:
pgmaster (primary node1) --|
|- pgslave1 (node2) --|
| |- pgslave2 (node3) --|----pgpool (master_slave_mode stream)----client
|- pgslave3 (node4) --|
|- pgslave4 (node5) --|
I have tested the following scenarios, and they all work very well: 我已经测试了以下方案,它们都运行良好:
As for the client application, these changes are all transparent. 对于客户端应用程序,这些更改都是透明的。 The client just points to the pgpool node, and keeps working fine in all the aforementioned scenarios. 客户端仅指向pgpool节点,并在上述所有情况下都能正常工作。
Note : In case you have problems to get PostDock up running, you could try my forked version of PostDock . 注意 :如果您在启动PostDock时遇到问题,可以尝试使用我的PostDock分支版本 。
A problem with the aforementioned architecture is that pgpool is the single point of failure. 前述架构的一个问题是pgpool是单点故障。 So I have also tried enabling Watchdog for pgpool-II with a delegated virtual IP, so as to avoid the single point of failure. 因此,我还尝试了使用委派的虚拟IP 为pgpool-II启用Watchdog,以避免出现单点故障。
master (primary node1) --\
|- slave1 (node2) ---\ / pgpool1 (active) \
| |- slave2 (node3) ----|---| |----client
|- slave3 (node4) ---/ \ pgpool2 (standby) /
|- slave4 (node5) --/
I have tested the following scenarios, and they all work very well: 我已经测试了以下方案,它们都运行良好:
As for the client application, these changes are all transparent. 对于客户端应用程序,这些更改都是透明的。 The client just points to the virtual IP, and keeps working fine in all the aforementioned scenarios. 客户端仅指向虚拟IP,并在上述所有情况下都能正常工作。
You can find this project at my GitHub repository on the watchdog branch . 您可以在watchdog分支的GitHub存储库中找到此项目。
Kubernetes's statefulset is a good base for setting up the stateful service. Kubernetes的有状态集是设置有状态服务的良好基础。 You will still need some work to configure the correct membership among PostgreSQL replicas. 您仍然需要一些工作来配置PostgreSQL副本之间的正确成员资格。
Kubernetes has one example for it. Kubernetes就是一个例子。 http://blog.kubernetes.io/2017/02/postgresql-clusters-kubernetes-statefulsets.html http://blog.kubernetes.io/2017/02/postgresql-clusters-kubernetes-statefulsets.html
You can look at one of the below postgresql open-source tools 您可以查看以下Postgresql开源工具之一
1 Crunchy data postgresql 1松散的数据PostgreSQL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.