How to Deploy Cloud-Native MariaDB on Kubernetes

Galaxy Glossary

How do I deploy a cloud-native MariaDB instance on Kubernetes?

A step-by-step approach to running MariaDB as a fault-tolerant, autoscaling service inside Kubernetes.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Why run MariaDB cloud-native?

Containers let you version, replicate, and scale MariaDB quickly. Kubernetes adds self-healing, rolling updates, and declarative infrastructure—ideal for microservices and CI/CD.

What prerequisites are needed?

Install kubectl, helm, and a Kubernetes cluster (kind, Minikube, EKS, GKE, or AKS). Ensure kubectl get nodes returns Ready nodes.

How do I launch MariaDB with Helm?

Helm charts abstract YAML complexity. The official Bitnami chart provisions deployment, service, PVC, and secrets in one command.

helm repo add bitnami https://charts.bitnami.com/bitnami
helm install shop-db bitnami/mariadb \
--set auth.rootPassword=Str0ngP@ss! \
--set primary.persistence.size=10Gi \
--set architecture=replication

What parameters matter most?

auth.* sets credentials, primary.persistence.* controls storage, and architecture toggles single-primary vs. replication.

How do I connect from an app pod?

Retrieve credentials stored in the Kubernetes Secret and reference the service name shop-db-mariadb as the hostname. Example env:

env:
- name: DB_HOST
value: shop-db-mariadb
- name: DB_USER
valueFrom:
secretKeyRef:
name: shop-db-mariadb
key: mariadb-user
- name: DB_PASS
valueFrom:
secretKeyRef:
name: shop-db-mariadb
key: mariadb-password

How do I seed ecommerce tables?

Use a Kubernetes Job or kubectl exec into the primary:

kubectl exec -it $(kubectl get pod -l app.kubernetes.io/component=primary -o name) -- \
mariadb -u root -pStr0ngP@ss! -e "CREATE DATABASE shop; USE shop; ..."

How do I scale reads?

Set architecture=replication and increase replica count:

helm upgrade shop-db bitnami/mariadb --set replica.replicaCount=3

Kubernetes automatically attaches the replicas to the primary and exposes a read-only service.

How do I back up?

Schedule kubectl exec + mysqldump in a CronJob or use Velero to snapshot PVCs. Store dumps in S3 or GCS.

Best practices for production?

Enable TLS, use separate PVC classes for SSD vs. backups, limit CPU/memory, and configure liveness/readiness probes. Automate password rotation via External Secrets.

What SQL looks like inside?

After connecting, standard MariaDB syntax applies. The example below queries Customers, Orders, and Products.

Why How to Deploy Cloud-Native MariaDB on Kubernetes is important

How to Deploy Cloud-Native MariaDB on Kubernetes Example Usage


SELECT c.name, o.id AS order_id, SUM(oi.quantity * p.price) AS order_total
FROM Customers c
JOIN Orders o   ON o.customer_id = c.id
JOIN OrderItems oi ON oi.order_id    = o.id
JOIN Products p ON p.id             = oi.product_id
WHERE o.order_date >= CURDATE() - INTERVAL 30 DAY
GROUP BY c.name, o.id
ORDER BY order_total DESC;

How to Deploy Cloud-Native MariaDB on Kubernetes Syntax


Docker local test:
  docker run -d --name maria-shop -e MARIADB_ROOT_PASSWORD=Str0ngP@ss! -p 3306:3306 mariadb:11

Kubernetes with Helm:
  helm install shop-db bitnami/mariadb \
      --set auth.rootPassword=<root_pwd> \
      --set primary.persistence.size=10Gi \
      --set architecture=replication \
      --set replica.replicaCount=2

Basic SQL inside container (ecommerce context):
  CREATE TABLE Customers (
      id INT PRIMARY KEY AUTO_INCREMENT,
      name VARCHAR(80),
      email VARCHAR(120),
      created_at DATETIME DEFAULT CURRENT_TIMESTAMP
  );

  CREATE TABLE Orders (
      id INT PRIMARY KEY AUTO_INCREMENT,
      customer_id INT,
      order_date DATE,
      total_amount DECIMAL(10,2),
      FOREIGN KEY (customer_id) REFERENCES Customers(id)
  );

  CREATE TABLE Products (
      id INT PRIMARY KEY AUTO_INCREMENT,
      name VARCHAR(100),
      price DECIMAL(8,2),
      stock INT
  );

  CREATE TABLE OrderItems (
      id INT PRIMARY KEY AUTO_INCREMENT,
      order_id INT,
      product_id INT,
      quantity INT,
      FOREIGN KEY (order_id) REFERENCES Orders(id),
      FOREIGN KEY (product_id) REFERENCES Products(id)
  );

Common Mistakes

Frequently Asked Questions (FAQs)

Can I upgrade MariaDB without downtime?

Use a rolling update strategy: helm upgrade with a new image tag. Kubernetes replaces pods one by one, keeping the service available.

How do replicas handle writes?

Replicas are read-only. Point write traffic to the primary service (shop-db-mariadb) and reads to the replica service (shop-db-mariadb-read).

Does MariaDB Operator add value over Helm?

Yes. The Operator manages backups, automatic failover, and version upgrades declaratively, which Helm alone cannot.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.