A step-by-step approach to running MariaDB as a fault-tolerant, autoscaling service inside Kubernetes.
Containers let you version, replicate, and scale MariaDB quickly. Kubernetes adds self-healing, rolling updates, and declarative infrastructure—ideal for microservices and CI/CD.
Install kubectl
, helm
, and a Kubernetes cluster (kind, Minikube, EKS, GKE, or AKS). Ensure kubectl get nodes
returns Ready nodes.
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
auth.*
sets credentials, primary.persistence.*
controls storage, and architecture
toggles single-primary vs. replication.
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
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; ..."
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.
Schedule kubectl exec
+ mysqldump
in a CronJob or use Velero to snapshot PVCs. Store dumps in S3 or GCS.
Enable TLS, use separate PVC classes for SSD vs. backups, limit CPU/memory, and configure liveness/readiness probes. Automate password rotation via External Secrets.
After connecting, standard MariaDB syntax applies. The example below queries Customers, Orders, and Products.
Use a rolling update strategy: helm upgrade
with a new image tag. Kubernetes replaces pods one by one, keeping the service available.
Replicas are read-only. Point write traffic to the primary service (shop-db-mariadb
) and reads to the replica service (shop-db-mariadb-read
).
Yes. The Operator manages backups, automatic failover, and version upgrades declaratively, which Helm alone cannot.