Deploy mariadb galera cluster in kubernetes/docker swarm

9/29/2019

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.

-- hamedb71
galera
kubernetes
mariadb

1 Answer

9/29/2019

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
Source: StackOverflow