Installing MariaDB Enterprise Kubernetes Operator on Ubuntu VM

spacer

Introduction

MariaDB Enterprise Kubernetes Operator simplifies the deployment and management of MariaDB databases within a Kubernetes environment. This guide walks you through installing the operator on an Ubuntu VM, which can be used for testing before implementing in a production environment.

Overview

Before proceeding, ensure you have: Ubuntu VM (20.04 or later)

  1. Install Docker
  2. Install Kubernetes cluster (Minikube for testing)
  3. Install kubectl to interact with the cluster
  4. Add customer credentials access to docker.mariadb.com
  5. Installed Helm kubernetes package manager
  6. Add MariaDB Enterprise Operator to helm repository
  7. Install MariaDB Enterprise Operator
  8. Deploy a MariaDB Instance
  9. Verify Deployment
  10. Interacting with the instance

Installation Instructions

  1. Install Docker to run minikube
    Official guide: Ubuntu
-- Add current user to sudoers (if not already added)
su -
adduser skhaire sudo

-- Run the following command to uninstall all conflicting packages:
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

-- Setup the Docker apt repository.
-- Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

-- Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

-- Install the latest version
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

-- Verify that the installation is successful by running the hello-world image:
sudo docker run hello-world

2. Install minikube & start minikube
minikube sets up a local Kubernetes cluster
Offical guide: minikube start

curl -LO https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64 
sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64

minikube start

Note: In case of ‘permission denied’ error as below,

skhaire@Ubuntu:~$ minikube start

  • minikube v1.36.0 on Ubuntu 22.04 (vbox/amd64)
  • Unable to pick a default driver. Here is what was considered, in preference order:
    • docker: Not healthy: “docker version –format {{.Server.Os}}-{{.Server.Version}}:{{.Server.Platform.Name}}” exit status 1: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get “http://%2Fvar%2Frun%2Fdocker.sock/v1.49/version“: dial unix /var/run/docker.sock: connect: permission denied

Add your user to ‘docker’ group

sudo usermod -aG docker $USER && newgrp docker

3. Install kubectl
Official guide: Install and Set Up kubectl on Linux

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.33/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
sudo chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg

echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.33/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo chmod 644 /etc/apt/sources.list.d/kubernetes.list # helps tools such as command-not-found to work correctly

sudo apt-get update
sudo apt-get install -y kubectl

4. Customer access to docker.mariadb.com

kubectl create secret docker-registry mariadb-enterprise \
--docker-server=docker.mariadb.com \
--docker-username=<email> \
--docker-password=<customer-download-token>

5. Install helm

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

-- Check installation
helm version

6. Add MariaDB Enterprise Operator Helm repository to Helm configuration and Install CRDs (Custom Resource Definitions) for the MariaDB Enterprise Operator into your Kubernetes cluster.

helm repo add mariadb-enterprise-operator https://operator.mariadb.com
helm install mariadb-enterprise-operator-crds mariadb-enterprise-operator/mariadb-enterprise-operator-crds

7. Install mariadb-enterprise-operator

a. Create a directory

mkdir mariadb-enterprise-operator
cd mariadb-enterprise-operator

b. Create a values.yaml file

imagePullSecrets:
- name: mariadb-enterprise

webhook:
imagePullSecrets:
- name: mariadb-enterprise

certController:
imagePullSecrets:
- name: mariadb-enterprise

c. Now proceed to install the operator

helm install mariadb-enterprise-operator mariadb-enterprise-operator/mariadb-enterprise-operator -f values.yaml

8. Deploy a standalone instance of MariaDB Enterprise Server

  • Create secret.yaml file for the root password
apiVersion: v1
kind: Secret
metadata:
name: mariadb
stringData:
password: MariaDB11!
  • Create the secret
kubectl apply -f secret.yaml
  • Create mariadb.yaml for deployment
apiVersion: enterprise.mariadb.com/v1alpha1
kind: MariaDB
metadata:
name: mariadb
spec:
rootPasswordSecretKeyRef:
name: mariadb
key: password
image: docker.mariadb.com/enterprise-server:latest
imagePullPolicy: Always
imagePullSecrets:
- name: mariadb-enterprise

replicas: 1

port: 3306

storage:
size: 1Gi

myCnf: |
[mariadb]
bind-address=*
default_storage_engine=InnoDB
binlog_format=row
innodb_autoinc_lock_mode=2
innodb_buffer_pool_size=800M
max_allowed_packet=256M

resources:
requests:
cpu: 500m
memory: 1Gi
limits:
memory: 1Gi

metrics:
enabled: true
  • Deploy the instance
kubectl apply -f mariadb.yaml

9. Check the status of the deployment/troubleshooting

  • Monitor the status of the pod mariadb-0 until it transitions to ‘Running
kubectl get pods
  • For more details about the deployment, run
kubectl describe pod/mariadb-0
  • For mariadb logs from the pod
kubectl logs mariadb-0

10. Interact with your newly installed mariadb server on a kubernetes cluster

kubectl exec -it mariadb-0 -- /bin/bash

mariadb -uroot -pMariaDB11!

Note: If you encounter any issues with deployment like the following:

kubectl get pods

Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 3m6s default-scheduler Successfully assigned default/mariadb-0 to minikube
Normal Killing 35s (x3 over 2m15s) kubelet Container mariadb failed startup probe, will be restarted
Normal Pulled 34s (x4 over 3m3s) kubelet Container image "docker.mariadb.com/enterprise-server:latest" already present on machine
Normal Created 34s (x4 over 3m2s) kubelet Created container: mariadb
Normal Started 34s (x4 over 3m2s) kubelet Started container mariadb
Warning Unhealthy 5s (x10 over 2m35s) kubelet Startup probe failed: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

This indicates that there may be issues with Minikube installation itself.

To resolve this, follow these steps to delete the Minikube cluster and start fresh:

minikube stop

minikube delete --all --purge

Getting Started

The MariaDB Enterprise Kubernetes Operator is available with a MariaDB Enterprise Platform Plus subscription. Customers with that subscription plan can download the operator here.

Conclusion

Running MariaDB in Kubernetes offers several advantages, like

  1. High Availability & Fault Tolerance
    • Kubernetes ensures automatic failover and self-healing of MariaDB instances.
    • StatefulSets maintain persistent storage, preventing data loss during pod restarts.
  2. Scalability & Load Balancing
    • Easily scale MariaDB instances horizontally or vertically based on workload demands.
    • Kubernetes load balancing distributes traffic efficiently across database replicas.
  3. Automated Deployment & Management
    • MariaDB Kubernetes Operator simplifies database provisioning, backups, and upgrades.
    • Helm charts allow declarative configuration, reducing manual intervention.
  4. Improved Security & Isolation
    • Kubernetes network policies and RBAC (Role-Based Access Control) enhance security.
    • Secrets management ensures secure credential storage for database authentication.
  5. Efficient Resource Utilization
    • Kubernetes optimizes CPU and memory allocation, preventing resource wastage.
    • Containers ensure consistent performance across different environments.

Hopefully, this blog helps you to get started with deploying the mariadb-enterprise-operator in kubernetes.