MariaDB on MicroK8s: Setup The Fork of MySQL on Single Node Kubernetes Cluster

MariaDB is a community-driven, open-source RDBMS that was created as a fork of MySQL in 2009 by the original developers of MySQL.

MariaDB on MicroK8s: Setup The Fork of MySQL on Single Node Kubernetes Cluster
MariaDB

Introduction

MariaDB is an open-source relational database management system (RDBMS) that has gained significant popularity in recent years. As a fork of MySQL, MariaDB has a fascinating origin story and continues to evolve to meet the needs of modern enterprises. In this article, we’ll delve into the world of MariaDB, exploring its history, differences from MySQL, enterprise support, adoption by major companies, and integration with Kubernetes and cloud-native environments.

What is MariaDB

MariaDB is a community-driven, open-source RDBMS that was created as a fork of MySQL in 2009 by the original developers of MySQL. It is designed to be highly compatible with MySQL while offering additional features, improved performance, and enhanced security. MariaDB supports a wide range of storage engines, including InnoDB, MyRocks, and Aria, and is used by organizations of all sizes for various purposes, such as web development, data warehousing, and e-commerce applications.

Why does MariaDB exist?

MariaDB was created in response to concerns about the future of MySQL after it was acquired by Oracle Corporation in 2009. The original MySQL developers, led by Michael “Monty” Widenius, wanted to ensure that the open-source community would have a high-quality, feature-rich, and actively maintained RDBMS, even if Oracle’s stewardship of MySQL were to falter. By creating MariaDB, the development team sought to preserve the original vision and values of the MySQL project while fostering an independent, community-driven environment for innovation and collaboration.

How is MariaDB different from MySQL

MariaDB is highly compatible with MySQL, as it uses the same APIs, protocols, and libraries. This compatibility allows for a seamless transition from MySQL to MariaDB in most cases. However, MariaDB has implemented several improvements over MySQL:

  1. Enhanced performance: MariaDB often outperforms MySQL due to optimizations and performance-enhancing features, such as thread pool support and more efficient query execution. The MariaDB optimizer is more advanced, with improvements in subquery optimization, join optimization, and more.
  2. Additional storage engines: MariaDB supports a broader range of storage engines than MySQL, including MyRocks, which is optimized for write-heavy workloads and provides better compression, and Aria, an improvement on the MyISAM engine that offers better caching and crash recovery features.
  3. Improved security: MariaDB has introduced features like role-based access control, data-at-rest encryption, and password validation plugins, which enhance security and facilitate compliance with regulatory requirements. MariaDB also includes a built-in firewall to protect against SQL injection attacks and unauthorized access.

Despite these differences, MariaDB has maintained a strong commitment to ensuring compatibility with MySQL, making it a viable alternative for organizations looking to transition from one RDBMS to another.

MariaDB Architecture

MyRocks and Aria Storage Engine

MyRocks and Aria are two of the storage engines supported by MariaDB, each offering unique benefits and use cases.

MariaDB Storage Engines

MyRocks

MyRocks is a storage engine based on RocksDB, an embedded key-value store developed by Facebook. RocksDB itself is derived from Google's LevelDB, which is designed to provide high performance and efficiency for read and write-heavy workloads.

MyRocks in MariaDB has several advantages over traditional storage engines like InnoDB:

  1. Improved write efficiency: MyRocks is designed for write-heavy workloads, and its Log-Structured Merge-Tree (LSM-Tree) data structure allows for more efficient writes, reducing write amplification and improving overall performance.
  2. Better compression: MyRocks provides better data compression than InnoDB, which can lead to significant space savings. This is especially important for large-scale applications where storage costs can become a major concern.
  3. Crash-safe and replication-friendly: MyRocks is crash-safe, meaning it can recover data after unexpected shutdowns or crashes without data loss. It also supports native MariaDB replication features, making it a suitable option for distributed environments.

Aria

Aria is a storage engine developed by the MariaDB team as an improvement over the older MyISAM engine. It is designed to be a general-purpose storage engine that is both crash-safe and efficient. Aria offers several advantages over MyISAM and other storage engines:

  1. Crash-safe: Aria maintains a transactional log to ensure data consistency and crash recovery. This feature prevents data corruption and loss that may occur due to unexpected system failures, making Aria more reliable than MyISAM.
  2. Improved caching: Aria features an advanced caching mechanism that supports both row and index caching, leading to better performance for read-heavy workloads. This caching system also reduces disk I/O and helps optimize system resources.
  3. Enhanced performance: Aria offers better performance for concurrent read and write operations, making it suitable for various use cases, including web applications, content management systems, and data warehousing.
  4. MVCC support: Aria also supports Multi-Version Concurrency Control (MVCC), allowing for better concurrency and isolation in multi-user environments.

Both MyRocks and Aria storage engines serve different purposes and can be chosen based on the specific needs and requirements of the application. MariaDB's support for these storage engines, in addition to InnoDB, ensures that developers have a variety of options to optimize their database performance and functionality.

MariaDB in the Enterprise World

Support and cloud services MariaDB offers comprehensive support options for enterprises, including the MariaDB Enterprise subscription, which provides access to certified binaries, updates, bug fixes, and 24/7 technical support. MariaDB also offers a managed database service called MariaDB SkySQL, which delivers a fully managed, scalable, and secure cloud database solution that supports both transactional and analytical workloads.

For example, MariaDB SkySQL provides an intuitive web-based interface for managing databases, and it includes features like automatic backups, point-in-time recovery, and monitoring tools to ensure the performance, reliability, and security of the database environment.

Enterprise adoption of MariaDB

Community and Enterprise Contribution for MariaDB. Source: MariaDB

Notable companies leveraging MariaDB Many well-known companies have adopted MariaDB for their database needs. Some notable examples include:

  1. Google: Google migrated its internal MySQL databases to MariaDB for its enhanced performance and security features. The company also contributes to MariaDB development
  2. Wikipedia: The Wikimedia Foundation, which powers Wikipedia and other projects, switched from MySQL to MariaDB in 2013. They cited the benefits of MariaDB’s open-source nature, active development, and commitment to compatibility with MySQL as reasons for the change.
  3. Alibaba: Alibaba, the Chinese e-commerce giant, uses MariaDB as part of its cloud services platform, Alibaba Cloud. The company has also invested in MariaDB Corporation and contributes to MariaDB development.
  4. Booking.com: The popular travel platform Booking.com utilizes MariaDB for its database needs, taking advantage of its performance improvements and advanced features over MySQL.

These examples illustrate that MariaDB has been widely adopted by enterprises across various industries, highlighting its versatility and reliability as an RDBMS solution.

MariaDB and Kubernetes

Embracing the cloud-native world MariaDB has embraced the growing trend of containerization and cloud-native application development by providing support for Kubernetes, a popular container orchestration platform. MariaDB offers a Kubernetes Operator, which simplifies the deployment, scaling, and management of MariaDB clusters in a Kubernetes environment. This integration allows developers to leverage the power of MariaDB in their cloud-native applications while benefiting from the scalability and flexibility offered by Kubernetes.

For example, the MariaDB Kubernetes Operator enables users to create and manage MariaDB clusters with just a few commands, automatically handling tasks like deploying replica sets, configuring data persistence, and scaling the cluster as needed. Additionally, the operator can be integrated with other cloud-native technologies, such as Prometheus for monitoring and Grafana for visualization, to create a comprehensive and efficient database management solution.

Install MariaDB on Kubernetes Cluster

The most highly recommended method for installing MariaDB on Kubernetes is by utilizing Helm Charts. Bitnami offers excellent Helm Charts for MariaDB, which we will employ in this process. Bitnami is a reputable company specializing in providing a comprehensive library of pre-packaged, easy-to-deploy applications and development stacks tailored for a range of platforms.

To begin, we'll add Bitnami to the Helm repository with the following command:

~$ helm repo add bitnami https://charts.bitnami.com/bitnami
~$ helm update

Moving forward, we will set up our database instance. To do this, we require a Persistent Volume Claim (PVC) to store MariaDB files and databases. The following script can be used to create a PVC on MicroK8s:

Alternatively, if you prefer to install MariaDB on a managed Kubernetes cluster such as Google Kubernetes Engine (GKE), we suggest using NFS storage, as explained in the following article:

How to setup persistent storage with NFS on GKE
A Persistent Volume (PV) in Kubernetes is a storage resource abstraction that provides a way to store and manage persistent data for applications running in a Kubernetes cluster.

Next, we can create a values.yml file, which serves as the values file for the Helm Chart.

With everything set up, we can now proceed to install MariaDB on our MicroK8s cluster.

~$ kubectl apply -f volume.yml

~$ helm install mariadb -f mariadb-values.yml bitnami/mariadb

Verify installation

~$ kubectl get pods

NAME        READY   STATUS    RESTARTS   AGE
mariadb-0   1/1     Running   0          10s

Congratulations! You've successfully installed one of the most popular open-source databases, MariaDB, on your Kubernetes cluster.


About 8grams

We are a small DevOps Consulting Firm that has a mission to empower businesses with modern DevOps practices and technologies, enabling them to achieve digital transformation, improve efficiency, and drive growth.

Ready to transform your IT Operations and Software Development processes? Let's join forces and create innovative solutions that drive your business forward.

Subscribe to our newsletter for cutting-edge DevOps practices, tips, and insights delivered straight to your inbox!