will data be synced among all instances when use mongodb statefulset

8/24/2018

Take this case https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/ for example (suppose we need write to the database). Is the data synced among each mysql isntance? If not, if there is any way to do it?

-- ovvvvverff
kubernetes

1 Answer

8/24/2018

Is the data synced among each mysql isntance?

Disclaimer: although question title is centered around mongodb this answer is directed to your actual question (given example StatefulSet and mysql).

Yes. The StatefulSet in the link you provided is keeping one master pod and two read-only pods in sync.

Notes:

  • Services are configured in such a way that any pod will handle read operation (both master and any read-only-slave) while write operation must be done by writing to master pod exclusively since read-only-slaves are configured (using ConfigMap) to reject write operations.
  • InitContainers are used in each pod to distinguish configuration between master and read-only-slaves, as well as to do initial data load on restart.
  • Each mysql pod is consisting of two containers: mysql and xtrabackup. xtrabackup is tasked with syncing data with the master.
  • As noted in the documentation:

    this is not a production configuration. 
    In particular, MySQL settings remain on insecure defaults
    to keep the focus on general patterns for running stateful applications in Kubernetes.
-- Const
Source: StackOverflow