Skip to content

MariaDB Setup on a NFS volume

Overview 

  • Using persistence.accessMode=ReadWriteOnce as we don’t have multiple Mariadb Instances accessing our NFS storage
  • Note: Using persistence.accessMode=ReadWriteMany fails during setup
  • Use the primary prefix like  primary.persistence.storageClass
  • These settings simplifies Mariadb Setup a lot 
  • In case of a failure  Mariadb pod will be scheduled at a different Node running the following steps:
    • This NFS file system holding the database files gets mounted on the new node 
    • The database recovery process takes place and finally the mariadb gets opened   

Install MariaDB

# export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
#  helm install --debug -n keycloak-oidc-ns keycloak-oidc-db bitnami/mariadb --set primary.persistence.storageClass=managed-nfs-storage-db --set primary.persistence.size=1Gi
install.go:172: [debug] Original chart version: ""
install.go:189: [debug] CHART PATH: /root/.cache/helm/repository/mariadb-9.4.2.tgz

client.go:122: [debug] creating 5 resource(s)
NAME: keycloak-oidc-db
LAST DEPLOYED: Thu Aug 25 07:46:08 2022
NAMESPACE: keycloak-oidc-ns
STATUS: deployed
REVISION: 1
TEST SUITE: None
USER-SUPPLIED VALUES:
primary:
  persistence:
    size: 1Gi
    storageClass: managed-nfs-storage-db

Get root password 
$(kubectl get secret --namespace keycloak-oidc-ns keycloak-oidc-db-mariadb -o jsonpath="{.data.mariadb-root-password}" | base64 --decode)
Lz...

Start Maria db client and open a bash Shell
 #  kubectl run keycloak-oidc-db-mariadb-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mariadb:10.5.12-debian-10-r0 --namespace keycloak-oidc-ns --command -- bash

Connect to Mysql 
@keycloak-oidc-db-mariadb-client:/$   mysql -h keycloak-oidc-db-mariadb.keycloak-oidc-ns.svc.cluster.local -uroot -p
Enter password:

MariaDB [(none)]> show databases;

+--------------------+
| Database           |
+--------------------+
| information_schema |
| my_database        |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.004 sec)



Create database

Connect to Mysql as user root
@keycloak-oidc-db-mariadb-client:/$   mysql -h keycloak-oidc-db-mariadb.keycloak-oidc-ns.svc.cluster.local -uroot -p
Enter password:

MariaDB [(none)]>  CREATE DATABASE keycloak_oidc_db CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Query OK, 1 row affected (0.025 sec)

MariaDB [(none)]> CREATE USER 'keycloak_user'@'%' IDENTIFIED BY 'keycloak_user';
Query OK, 0 rows affected (0.012 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON keycloak_oidc_db.* TO 'keycloak_user'@'%';
Query OK, 0 rows affected (0.003 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

Test your database connection as Keycloak user

$ mysql -h keycloak-oidc-db-mariadb.keycloak-oidc-ns.svc.cluster.local -ukeycloak_user -Dkeycloak_oidc_db -p
Enter password:

MariaDB [keycloak_oidc_db]> show databases
;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| keycloak_oidc_db   |
| test               |
+--------------------+
Published inKubernetes

Be First to Comment

Leave a Reply