John Wu
John Wu

Reputation: 131

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? If they do, why I created DB and user in one pod, and can not find the value in the other. If they not, is there no point of creating replicas?

Upvotes: 0

Views: 1928

Answers (2)

Harsh Manvar
Harsh Manvar

Reputation: 30113

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. 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

For the example of Postgres database replication example and clustering config files : https://github.com/CrunchyData/crunchy-containers/tree/master/examples/kube

Upvotes: 0

coderanger
coderanger

Reputation: 54211

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. More common would be to use the volumeClaimTemplate system so each pod gets its own distinct storage. Then you set up Postgres streaming replication yourself.

Or look at using an operator which handles that setup (and probably more) for you.

Upvotes: 3

Related Questions