0

I have a structure like shown in the image below: cluster with two nodes and service for the database (postgres).

Is the data shared between those two pods of postgres images or is it possible to set it to share data?

This is scenario which I want the answer to:

  • Connect to database with host db.domain.com (load balancer point me to node1)
  • Insert 1 (and only) record in table
  • Disconnect
  • Connect to database again with host db.domain.com (load balancer points me to other node)
  • List items in table
  • Will I get the inserted row from node1?

Also if I scale up to 10 nodes, 10 instances of same service will be deployed, so 10 images of posgres, do the all share data?

1 Answer 1

1

Is the data shared between those two pods of postgres images or is it possible to set it to share data?

Each pod has its own filesystem; there is no sharing between pods by default.

With the right storage driver in your Kubernetes clusters, you can create persistent volumes that are shared between pods. However, this is usually not appropriate for a database, which typically requires exclusive access to its storage directory.

To achieve your goal of having two database instances with the same content, you will need to set up postgres replication. In this model, your database instances form a cluster and writes to the primary server are automatically replicated to secondary servers. You can only write to the master, but you can read (i.e., perform select queries) from any of the replicas.

There are a number of operators that will help set up postgres clusters in Kubernetes. For example:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.