简体   繁体   English

如果我在 k8s 中声明 2 个 PostgreSQL StatefulSet pod 副本,它们是同一个数据库还是只是共享卷?

[英]If I declare 2 replicas of PostgreSQL StatefulSet pods in k8s, are they the same database or they just share the volume?

After making 2 replicas of PostgreSQL StatefulSet pods in k8s, are the the same database?在 k8s 中制作了 2 个 PostgreSQL StatefulSet pod 副本后,是同一个数据库吗? If they do, why I created DB and user in one pod, and can not find the value in the other.如果他们这样做,为什么我在一个 pod 中创建了 DB 和用户,而在另一个中找不到值。 If they not, is there no point of creating replicas?如果没有,创建副本就没有意义了吗?

There isn't one simple answer here, it depends on how you configured things.这里没有一个简单的答案,这取决于您如何配置事物。 Postgres doesn't support multiple instances sharing the same underlying volume without massive corruption so if you did set things up that way, it's definitely a mistake. Postgres 不支持多个实例共享相同的底层卷而不会出现大量损坏,因此如果您确实以这种方式设置,那绝对是一个错误。 More common would be to use the volumeClaimTemplate system so each pod gets its own distinct storage.更常见的是使用 volumeClaimTemplate 系统,这样每个 pod 都有自己独特的存储。 Then you set up Postgres streaming replication yourself.然后您自己设置 Postgres 流复制。

Or look at using an operator which handles that setup (and probably more) for you.或者考虑使用为您处理该设置(可能还有更多)的操作员。

To add the answer in coderanger, as he said it's not easy to say how Postgres will work with the multi replicas, and data replication across the cluster unless checking more in-depth.在 coderanger 中添加答案,正如他所说,除非进行更深入的检查,否则很难说 Postgres 将如何处理多副本以及跨集群的数据复制。 Setting the multiple replicas directly without reading the document of replication of data might lead to big issue.直接设置多个副本而不阅读数据复制文档可能会导致大问题。

Here is one nice example from google for ref : https://cloud.google.com/architecture/deploying-highly-available-postgresql-with-gke这是 google 的一个很好的例子,用于 ref : https : //cloud.google.com/architecture/deploying-highly-available-postgresql-with-gke

For the example of Postgres database replication example and clustering config files : https://github.com/CrunchyData/crunchy-containers/tree/master/examples/kube对于 Postgres 数据库复制示例和集群配置文件的示例: https : //github.com/CrunchyData/crunchy-containers/tree/master/examples/kube

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM