1

I'm trying to deploy scalable mariadb galera cluster in kubernetes or docker swarm. Since each pod or containers needs its own galera config, how should i create my deployment so i could be able to scale it without any manual work? I think we can't use ConfigMap cause for a 10 node cluster there have to be 10 configmaps!

Example of mariadb galera config of a node:

wsrep_cluster_address="gcomm://ip_1,ip_2,ip_3"    
wsrep_node_address="ip_1"    
wsrep_node_name="node_1"
wsrep_cluster_name="mariadb-cluster"

For such applications which have different config for each node, what is the best way of deployment?

Note: I can create pods/containers and do the config my self (join new nodes to the cluster) but i think this isn't right way and i need it to be auto scalable.

David Maze
  • 130,717
  • 29
  • 175
  • 215
hamedb71
  • 141
  • 1
  • 8

1 Answers1

3

You almost definitely want to use a StatefulSet to deploy this in Kubernetes. Among other things, this has the property that each Pod will get its own PersistentVolumeClaim for storage, and that the names of individual Pods are predictable and sequential. You should create a matching headless Service and then each Pod will have a matching DNS name.

That solves a couple of parts of the riddle:

# You pick this
wsrep_cluster_name="mariadb-cluster"

# You know what all of these DNS names will be up front
wsrep_cluster_address="gcomm://galera-0.galera.default.svc.cluster.local,...,galera-9.galera.default.svc.cluster.local"

For wsrep_node_name, the MariaDB documentation indicates that it defaults to the host name. In Kubernetes, the host name defaults to the pod name, and the pod name is one of the sequential galera-n for pods managed by a StatefulSet, so you don't need to manually set this.

wsrep_node_address is trickier. Here the documentation indicates that there are heuristics to guess it (with a specific caveat that it might not be reliable for containers). You can't know an individual pod's IP address before it's created. You can in principle use the downward API to inject a pod's IP address into an environment variable. I'd start by hoping the heuristics would guess the pod IP address and this works well enough (it is what the headless Service would ultimately resolve to).

That leaves you with the block above in the ConfigMap, and it's global across all of the replicas. The other remaining per-Galera-node values should be automatically guessable.

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • Ok, i think this will work (although i'm a little worried about unreliable autoguessing wsrep_node_address) so i'm gonna try this and let you know the result. – hamedb71 Sep 30 '19 at 04:14
  • I couldn't deploy the cluster yet (second node doesn't join the cluster) but i'm trying and i think this the only way. – hamedb71 Oct 01 '19 at 11:03
  • @hamedb71 do you have any news ? – ZedTuX Nov 13 '19 at 09:20
  • @ZedTuX I could deploy the cluster using David method, but not in enterprise level cause i do somethings manually and i wanted to be automatic. I don't know, maybe my implementation wasn't right or it isn't possible yet! – hamedb71 Nov 16 '19 at 09:30
  • @hamedb71 have you in the meantime had success in setting up your cluster? I am trying to do the same using a helm chart by bitnami but am running into some issues that the lifeness was not confirmed (Issue described here: [github](https://github.com/bitnami/charts/issues/6270)). I would be interested to see how you automated the cluster setup and especially which version you are using. I would like to have something up to date like mariadb 10.5.9 or at least mariadb 10.5.8 hence why I thought bitnami was a good version to go with but I can't get that running. – realShadow May 03 '21 at 02:12
  • @realShadow Yes, We managed to deploy cluster using bitnami charts but for reason that i can't remember, instead of GALERA we used MASTER/SLAVE deployment. mariadb docker version which we used was 10.3 if i remember correctly. – HBasiri May 05 '21 at 11:18