Running multiple pods for postgres in kubernetes. Is it safe for production?

10/30/2018

My kubernetes cluster has 3 pods for postgres. I have configured persistent volume outside of the cluster on a separate virtual machine. Now as per kubernetes design, multiple pods will be responding to read/write requests of clients. Is their any dead lock or multiple writes issues that can occur between multiple postgres pods?

-- Meta-Coder
containers
devops
devops-services
kubernetes
postgresql

2 Answers

10/30/2018

I agree with the previous answer. In the case you've asked it is better if you use a postgres cluster where only a instance acts as primary the others act as secondary. When the primary is failed, one of the secondary becomes primary and later when the failed primary is back it is added as a secondary of the new primary instance. The leader election is responsible for raising a secondary as new primary instance. That's how cluster is managed.

Besides the previous one you can use kubedb for kubernetes.

-- Shudipta Sharma
Source: StackOverflow

10/30/2018

You would need a leader election system between them. There can be only one active primary in a Postgres cluster at a time (give or take very very niche cases). I would recommend https://github.com/zalando-incubator/postgres-operator instead.

-- coderanger
Source: StackOverflow