How syncing data is possible in different instances of a database image running as containers in different nods?

12/24/2019

In a scenario where there are multiple containers running multiple instances of a database, when data in one instance is changed, how that change is applied to other instances so the data consistency preserved? it should be taken into consideration that containers may have bee placed in different nodes, so they can't share a common volume.

-- Metti
containers
database
kubernetes

2 Answers

12/24/2019

If you are going with normal deployment with an application that just uses folder to access data it is advisable to use Persistent volumes, it could be either be nfs or several other options mentioned in the documentation where you mount the same volume inside all different pods having access to same data.

And if you are trying to host a database which is an application with state, it is advisable to use a statefulset instead of normal deployment when coming to applications like mongodb, mysql, etc.

Here is a how the statefulset works. But there are several online resources that gives you the differences between using a deployment vs statefulset for databases. But however, before statefulsets were introduced into k8s many of our database applications were deployed using PVC, it also has lot of overhead.

Hope this is helpful.

-- BinaryMonster
Source: StackOverflow

12/25/2019

Deploying database to Kubernetes in high-availability mode is a quite complex task.

To save a lot of time, please consider using Kubernetes operators. This way you can automate most of complex manual operations. Kubernetes operators allow you to describe desired configuration of an application (or database) in declarative way.

Kubernetes operator in general is a set of additional objects (pods, services, configmaps, secrets, RBAC, custom resources definitions, PV, PVC, ...) responsible to create and maintain complex application lifecycle.

Usually Kubernetes operators related to database applications take care about deploying database cluster of the desired size to Kubernetes and creating all required resources. Also they keep desired number of replicas, implement backup/restore procedures, configure data replication, forward client traffic to a healthy database pod and more.

Most of well-known databases have ready-to-use operators already. You can find some resources below:

Mysql Resources:

Percona Resources:

PostgreSQL resources:

MongoDB resources:

In case you are planning to use different type of database, please check for available operator from DB vendor searching "DBname kubernetes operator"

-- VAS
Source: StackOverflow