Skip to main content
Version: 1.0.0

MariaDB/MySQL

The Managed MariaDB service offers a powerful and widely used relational database solution. This service allows you to easily create and manage a replicated MariaDB cluster.


Configuration Example

Here is a YAML configuration example for a MariaDB deployment with two replicas and enabled backups:

apiVersion: apps.cozystack.io/v1alpha1
kind: MySQL
metadata:
name: mariadb-example
spec:
external: true
size: 20Gi
replicas: 2
storageClass: "replicated"
users:
admin:
password: "secure-password"
databases:
mydb:
roles:
admin:
- admin
backup:
enabled: false
# s3Region: "us-east-1"
# s3Bucket: "s3.tenant.hikube.cloud/mariadb-backups"
# schedule: "0 2 * * *"
# cleanupStrategy: "--keep-last=3 --keep-daily=3 --keep-within-weekly=1m"
# s3AccessKey: "your-s3-access-key"
# s3SecretKey: "your-s3-secret-key"
# resticPassword: "your-restic-password"

Using the kubeconfig provided by Hikube and this example yaml, saved as a manifest.yaml file, you can easily test the application deployment using the following command:

kubectl apply -f manifest.yaml

Configurable Parameters

General Parameters

NameDescriptionDefault Value
externalAllows external access from outside the cluster.false
sizeSize of the persistent volume for data.10Gi
replicasNumber of MariaDB replicas.2
storageClassStorage class used."replicated" or "local"

Configuration Parameters

NameDescriptionDefault Value
usersUsers configuration.{}
databasesDatabases configuration.{}

Backup Parameters

NameDescriptionDefault Value
backup.enabledEnables or disables periodic backups.false
backup.s3RegionAWS S3 region for backups.us-east-1
backup.s3BucketS3 bucket used for backups.s3.example.org/mariadb-backups
backup.scheduleBackup schedule (Cron format).0 2 * * *
backup.cleanupStrategyStrategy for cleaning up old backups.--keep-last=3 --keep-daily=3 --keep-within-weekly=1m
backup.s3AccessKeyAWS S3 access key for authentication.oobaiRus9pah8PhohL1ThaeTa4UVa7gu
backup.s3SecretKeyAWS S3 secret key for authentication.ju3eum4dekeich9ahM1te8waeGai0oog
backup.resticPasswordPassword for Restic encryption.ChaXoveekoh6eigh4siesheeda2quai0

Tutorials

Master/Slave Failover

  1. Modify the MariaDB instance to set a new primary replica. Use the following command to edit the instance:
kubectl edit mariadb <instance>
  1. Modify the configuration to set the primary pod:
spec.replication.primary.podIndex: 1
  1. Check the cluster status:
kubectl get mariadb

Restoring a Backup

  1. Find an available snapshot in your S3 bucket:
restic -r s3:s3.tenant.hikube.cloud/mariadb-backups/database_name snapshots
  1. Restore the latest snapshot:
restic -r s3:s3.tenant.hikube.cloud/mariadb-backups/database_name restore latest --target /tmp/

Additional Resources

To deepen your knowledge of MariaDB and its operator, check the following resources: