MariaDB & K8s: How to replicate MariaDB in K8s

In the previous blog we have seen how to create a statefulset MariaDB application. Also, we learned how replication works in MariaDB in this blog. Now, we will try to create a replicated statefulset application. As good references for creating this blog, I would like to give credit to the Kubernetes documentation as well as an example from Alibaba Cloud.

Configure replication

To replicate a MariaDB application we are going to create a statefulset that will consist of a single init container and one application container.

Cyber Protection – best practices for backing up data

A few weeks ago we hosted a webinar together with Acronis and CPanel on security and backup best practices as both provide software in this space. Acronis develops Cyber Security cloud based software particularly specializing in backup and disaster recovery for other service providers. CPanel in turn helps those service providers to enable their customers to administer their systems via a fully fledged dashboard. The webinar was a follow-up on another join presentation at CloudFest. The webinar presented quite a number of good ideas and I highly recommend you watch it.

Create statefulset MariaDB application in K8s

In the previous blog we created a stateless application, deployed with K8s resource Deployment, which allows one to replicate the application, but where data is lost when Pods are restarted, meaning there were no data consistency. In the same blog we used PersistentVolumeClaim for dynamic provisioning of PersistentVolume, but we used Deployment, meant for stateless application, and this way is *not recommended* for statefulset application where each replica should have its own persistent volume. The proper way to achieve that is through the Statefulset resource and this post we will cover that.

In K8s one can create a stateful application, an application like a database, which needs to save data to persistent disk storage for use by the server/clients/other applications, to keep track of its state and to be able to replicate and be used in distributed systems.

MariaDB & K8s: Deploy MariaDB and WordPress using Persistent Volumes

In the previous blog, MariaDB & K8s: Create a Secret and use it in MariaDB deployment, we used the Secrets resource to hide confidential root user data, and in the blog before that in the series, MariaDB & K8s: Communication between containers/Deployments, we created 2 containers (namely MariaDB and phpmyadmin) in a Pod. That kind of deployment didn’t have any persistent volumes.

In this blog we are going to create separate Deployments for MariaDB and WordPress applications as well as a Service for both in order to connect them. Additionally we will create Volume in a Pods of a MariaDB Deployment.

MariaDB & K8s: Communication between containers/Deployments

In the previous blog, a background Deployment resource was created from a YAML file, consisting of a single container (MariaDB) that acts as a background container.

In this blog we are going to proceed to create the frontend container to communicate with the backend through a Service and other resources.

About Services

When an application is run through the Deployment Pods are created and destroyed dynamically. When created, they get the internal IP address in a cluster, and since they are ephemeral, there needs to be a stable way to allow communications between Pods.

Start MariaDB in K8s

This is the first in a series of blogs explaining how to use MariaDB in Kubernetes (K8s), as well as explaining some important concepts of K8s and of MariaDB.

This blog explains how to start MariaDB as a stateless application in K8s using the CLI and explores different commands you can run on your CLI.

The prerequisites are that you have installed kubectl (which will also install Docker runtime) and minikube (local K8s).

Let’s first start the minikube

$ minikube start && kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane,master 104d v1.22.2

The Pod is a K8s resource and the smallest unit in K8s.

10.7 preview feature JSON Histograms

MariaDB has had support for histograms as part of Engine Independent Table Statistics since 10.0. As part of Google Summer of Code (MDEV-21130), Michael Okoko, together with his mentor Sergey Petrunia, have implemented a new format (using JSON) for histograms that significantly improves the accuracy and flexibility of histograms. For those just interested in the feature details, you can skip to the “New format”, however if one is unfamiliar with the purpose of histograms, read on.

Why statistics are needed

Histograms are important for queries where the WHERE clause uses columns that are not indexed.

Webinar: AI in MariaDB with MindsDB

MindsDB is an AutoML framework that lets software engineers do machine learning, without having to go through the whole data science pipeline. Additionally, MindsDB has done a seamless integration with MariaDB, by making use of the Connect Storage Engine.

If you want to learn more about how you can do AI straight from inside MariaDB, register for the webinar on 18th of May 16:00 GMT. MariaDB Foundation, together with MindsDB will cover the following topics in detail:

  • Why AI inside the database makes sense
  • How MariaDB is built to facilitate AI integrations.