Related
Secure Federated Chat: Self Host Matrix on Kubernetes
How to self host a Matrix.org server
Popular topics
02 min reading in—DevOps
This straightforward guide will walk you through deploying and exposing a basic MariaDB database on your microk8s Kubernetes cluster.
Every now and then, when setting up a simple staging environment, the need for a quick-setup database that retains state consistently arises. In such situations, I often lean towards MariaDB, specifically utilizing the Bitnami Helm Chart, with slight tweaks to achieve the following:
This post is operating under the assumption that you have a microk8s Kubernetes cluster already set up, complete with cert-manager, ingress, dns and an active and configured letsencrypt-prod cluster issuer.
Note: To jumpstart your setup, you might find this Blog Post on Microk8s Private Cluster Setup quite helpful.
For a swift deployment of this configuration:
./create_mariadb.sh \
RELEASE_NAME="<release-name>" \
K8_NAMESPACE="<installation-namespace>" \
DB_USERNAME="<db-username>" \
DB_PASSWORD="<your-super-secure-password>" \
DB_NAME="<db-name>" \
TARGET_PORT="<desired-port>" \
HOST_BACKUP_PATH="<your host backup volume>"
Remember to expose the desired port through your firewall with a
sudo ufw allow $TARGET_PORTcommand.
Execute the following command:
microk8s helm uninstall $RELEASE_NAME
Use this command to establish a connection to the database:
docker run -it --rm mysql mysql --host <your-host-domain> --port <your-port> --user <your-user> --password --protocol=TCP
Or use this with --network="host" if your testing a local server.
Remember to enter the admin password when prompted.
Here's a simple docker command for accomplishing this:
docker run --network="host" --rm mysql:5.7 mysqldump -h localhost -P 30004 -u <your-user> -p<your-admin-password> --protocol=TCP <your-db-name> > backup.sql
A straightforward example of a cron job that allows your database to be backed up regularly is created as follows:
microk8s kubectl create secret generic mariadb-creds --from-literal=password='$DB_PASSWORD' --from-literal=username='$DB_USER' -n $K8_NAMESPACE
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: backup-job
spec:
schedule: "0 * * * *"
jobTemplate:
spec:
template:
spec:
volumes:
- name: backup-volume
hostPath:
path: "$HOST_BACKUP_PATH"
containers:
- name: backup-container
image: mysql:5.7
volumeMounts:
- name: backup-volume
mountPath: /backup
env:
- name: MYSQL_PWD
valueFrom:
secretKeyRef:
name: mariadb-creds
key: password
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: mariadb-creds
key: username
command: ["sh", "-c", 'mysqldump -h database-host -P 30004 -u $MYSQL_USER --protocol=TCP database-name > /backup/backup-$(date +%Y%m%d-%H%M%S).sql']
restartPolicy: OnFailure
With this configuration in place, you would have a CronJob that executes hourly backups of the database.
Related
How to self host a Matrix.org server
Related
How Open-Chats Federation Enables anybody to host anything anywhere
Related
A n8n workflow setup, that synchronizes workflow and credential changes directly to github