Accessing and Setting Up Your New Galera Cluster:
Now that we have a running, three node MariaDB cluster… Let’s make something useful out of it.
I use a free tool called DBeaver to manage databases from my MacBook. Take a look at it here.
-
We need to access the running MariaDB instance through a command line so that we can setup password access over port 3306. We will do this through the OpenShift console. In the console, navigate to your
mariadb-galeraproject and get the list of running pods.
-
Now, select the mariadb-galera-0 pod. We’ll open a terminal into this pod.

-
Select the
terminaltab. You will see a command prompt.
-
From the command line, connect to mariadb and grant access to the
mysqluser fromlocalhost.
OK, we have connected to our new MariaDB cluster by directly accessing the terminal from one of the PODs. Not particularly useful, right?
So, let’s make it a bit more useful, and connect to it with DBeaver.
-
Note that we do not have any means to connect to the MariaDB cluster from outside of OpenShift. In fact, we can’t even connect to it from outside of the
mariadb-galeranamespace. This is by design. Unless you REALLY need external applications to connect to this database, do NOT create aroutethat exposes port3306outside of the OpenShift cluster. Instead, we can make this MariaDB cluster available for connection to applications deployed in OpenShift by either making themariadb-galeranamespace globally accessible within the OKD cluster, or we can connect specific namespace networks together, like this:oc adm pod-network join-projects --to=mariadb-galera my-application-namespaceTo make the
mariadb-galeranamespace accessible to all other namespaces:oc adm pod-network make-projects-global mariadb-galera -
However, this still does not enable me to externally manage the MariaDB cluster. And… as much as I love the command line, I really don’t relish the idea of connecting to a pod terminal every time I need to do something. I sure can’t use that method to import data… Enter the
port-forwardcapability of OpenShift. Usingport-forwardI can temporarily expose a port from a POD to my local workstation as though it were a local port.oc port-forward mariadb-galera-0 3306 -n mariadb-galeraI can now connect a database management tool like DBeaver to the locally exposed port.
-
Assuming that you have already installed DBeaver, launch it and create a new connection to port
3306onlocalhostuse themysqluser with the password that you set above.
-
You are now connected to your MariaDB cluster!

When you are done managing your database, simply terminate the oc port-forward command.
Note: Your load balancer may terminate your port-forward command after a period of inactivity.
The last thing to discuss, is how to properly shutdown and start up your MariaDB cluster. The proper procedure is to use oc scale to bring it up and down.
-
To gracefully shutdown your cluster:
oc scale statefulsets mariadb-galera --replicas=0 -n mariadb-galera -
To gracefully start it back up:
oc scale statefulsets mariadb-galera --replicas=3 -n mariadb-galeraNote: If you originally had 3 PODs running, then you want to restart with 3 PODs. If you scale with less than you had previously, your cluster will run, but will not have the same scalability or redundancy. If you scale up more than you previously had running, do so with intent. Because you will be adding nodes to your cluster and consuming more storage. Remember, every node is a complete copy of the database. There is probably little reason to run more than three replicas.
Have fun with your new MariaDB Galera cluster!