Deploy MariaDB on Jetstream 2 on top of Kubernetes


June 6, 2022

In this tutorial we will install a MariaDB instance backed by a persistent volume on Jetstream 2. It will be in the jhub namespace, so that it can be accessed by the JupyterHub users and from no other namespace.

As usual all configuration files and scripts are in my reference repository:

gh repo clone zonca/jupyterhub-deploy-kubernetes-jetstream
cd jupyterhub-deploy-kubernetes-jetstream/mariadb

Install via Helm

Bitnami provides a nicely prepackaged MariaDB instance via Helm, modify the mariadb/values.yaml file, in particular set all the passwords to randomly generated values.

I have configured the recipe so that:

  • database name is mariadbk8s
  • non root username is mariadbuser

Install it with


Load data from a SQL dump

Once the database is running, follow the printout of the Helm recipe on how to get a temporary pod to connect to the database.

Once that is running, you will have a terminal running, there you can get your SQL dump for example from gist:

cd /tmp
curl --output dump.sql -L

Finally ingest the data (will need to paste the root password from values.yaml):

mysql -h mariadb.jhub.svc.cluster.local -uroot -p mariadbk8s < dump.sql

Add support in user containers

Finally you need to make sure that the mariadb-client package is installed in the Jupyter single user OS, and in the Python environment you will need the mariadb package and possibly sqlalchemy.

For example Centos 7 needs the MariaDB custom repositories and the packages:

MariaDB-devel MariaDB-connect-engine

The connection string for SQLAlchemy will be:

from urllib.parse import quote_plus as urlquote
pw = urlquote('xxxxxxxxxxxxxxxxxxxx')
engine = sqlalchemy.create_engine(f"mariadb+mariadbconnector://mariadbuser:{pw}@mariadb.jhub.svc.cluster.local:3306/mariadbk8s")