1
votes

I want to start two maria-db pod with same persistent storage and any point of time I should be able to access both the instance and data should be in sync between them.

I am trying to start two mariadb instance using same volume persistent storage in kubernetes. I am able to start both the instance. I am performing the below steps.

  1. Creating a persistent volume
  2. Creating a persistent volume claim
  3. Using the same claim name starting mariadb-instance-1.
  4. Starting mariadb-instance-2 using same storage claim name.
  5. Creating two services for both the instance to access from outside.

I am able to access instance-1 but when I am trying to access instance-2 its giving me error. MySQL Error: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’.

Please find the attached dockerfiles.

Any help will be appreciated.

Please find the below git repo for db and storage yaml file which I used to create the deployment.

https://github.com/chandan493/db-as-docker

1
Which type of Persistent Volume you using? Can you show logs of pod to where you cannot connect to?Anton Kostenko
I am creating glusterfs type volume.Chandan Ghosh
Who told you that having two databases writing to same storage is a good idea?N.B.

1 Answers

4
votes

You can not run two MariaDB engines on the same storage, and if I understood you right this is what you expected. Even if you'd mount an RWX volume on two pods, if you put /var/lib/mysql of containers in two separate MaraiaDB pods in the same place, it will result in a conflict between database engines. For MariaDB clustering lookup MariaDB Galera - an almoust-fully-synchronous replication for MariaDB. But you'll need three db engines running for it to make sense.