MariaDB Operator: Run full featured MariaDB in Kubernetes
Introduction
MariaDB is a community-developed, commercially supported fork of the MySQL relational database management system. MariaDB is a drop-in replacement for MySQL and is designed to be a more robust, scalable, and secure database solution.
The MariaDB Operator is a tool that allows you to run a full featured MariaDB in Kubernetes. It is a great way to run a MariaDB server in Kubernetes and it is a great way to manage your MariaDB server in Kubernetes.
The benefits are:
- It is a full featured MariaDB server solution
- It is a great way to run a MariaDB server in Kubernetes
- You don't have to manage the MariaDB server manually for backups, upgrades, etc.
- There are build-in ways to scale the MariaDB server
- Easily extensible with MaxScale, Replications with auto-failover, GaleraDB...and easily customizable
Before starting, you need to have a Kubernetes cluster.
Installation
First, you need to install the MariaDB Operator with Helm:
For best practices and later usage, I advise to set the metrics and resources like:
You can update the mariadb-operator
chart with the following values file (simply add -f mariadb-operator-override-values.yaml
to the helm install command).
If you check your pods, you should see something like this:
Single instance configuration
You can configure a single instance of MariaDB with the following configuration:
Regarding the StorageClass, I'm using OpenEBS LVM for the best performance. It's not mandatory and you can use any other storage class. However, for maximum performances, you should use local storage.
Apply this configuration with kubectl:
And you should see the MariaDB instance running:
Create a user
You can decide to create a dedicated secret for this new user or use the same secret as the MariaDB instance. Here we're going to update the existing secret:
You can now create a user on the MariaDB instance with the following configuration:
You can now apply this configuration with kubectl:
Grant privileges
You can grant privileges to a user with the following configuration:
High availability
The MariaDB Operator also supports multiple High Availability solutions like:
- Replications with auto-failover: a master-master replication solution with auto-failover capabilities, also called SemiSync replication.
- Galera: a multi-master replication solution with auto-failover capabilities.
- MaxScale: a proxy solution with failover and load balancing capabilities
We'll take a look here at the Replications with auto-failover solution. I like this one because it's built-in and it's very easy to configure for a home lab. Prefer the Galera solution if you need a multi-master solution. And use MaxScale if you need a more complex solution with failover and load balancing capabilities.
Replications with auto-failover
Here is a configuration with only 2 nodes (not perfect because of the missing Qorum) but it's a good start for a home lab.
Once applied, you can check replication status with:
Troubleshooting
If you encounter issues, you can check the logs of the MariaDB instance with the following command: