본문 바로가기
Kubernetes/DBMS

MariaDB

by 여행을 떠나자! 2021. 10. 4.

1. 개요

- MariaDB

   MariaDB is a fast, reliable, scalable, and easy to use open-source relational database system.

   MariaDB Server is intended for mission-critical, heavy-load production systems as well as for embedding into mass-deployed software.
   https://mariadb.com/

- MariaDB helm chart

   This chart bootstraps a MariaDB replication cluster deployment on a Kubernetes cluster using the Helm package manager.

   https://github.com/bitnami/charts/tree/master/bitnami/mariadb/

   https://bitnami.com/stack/mariadb/helm

 

 

2. Environments

- helm chart bitnami/mariadb 9.6.1 

- MariaDB 10.15.12

- Helm 3.3.1

- Kubernetes 1.16.15

 

 

3. Install

- chart repository 추가

$ helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories
$ helm repo list
NAME                	URL
bitnami             	https://charts.bitnami.com/bitnami
…
$ helm repo update
…
...Successfully got an update from the "bitnami" chart repository
...Successfully got an update from the "nvidia" chart repository
Update Complete. ⎈Happy Helming!⎈
$ helm search repo mariadb 
NAME                   	CHART VERSION	APP VERSION	DESCRIPTION
bitnami/mariadb        	9.6.1        	10.5.12    	Fast, reliable, scalable, and easy to use open-...
bitnami/mariadb-cluster	1.0.2        	10.2.14    	DEPRECATED Chart to create a Highly available M...
bitnami/mariadb-galera 	5.14.0       	10.5.12    	MariaDB Galera is a multi-master database clust...
stable/mariadb         	7.3.14       	10.3.22    	DEPRECATED Fast, reliable, scalable, and easy t...
bitnami/phpmyadmin     	8.2.14       	5.1.1      	phpMyAdmin is an mysql administration frontend
stable/phpmyadmin      	4.3.5        	5.0.1      	DEPRECATED phpMyAdmin is an mysql administratio...
$

 

- helm chart용 parametes yaml 파일 생성 및 변경

   ✓ rootPassword, database, service type paramete 변경

   ✓ parametes에 대한 자세한 설명은 아래 링크 참조

       https://github.com/bitnami/charts/tree/master/bitnami/mariadb/#parameters

$ helm inspect values bitnami/mariadb --version 9.6.1 > mariadb_9.6.1_yoosung-jeon.values
$ vi mariadb_9.6.1_yoosung-jeon.values
…
auth:
  ## @param auth.rootPassword Password for the `root` user. Ignored if existing secret is provided.
  ## ref: https://github.com/bitnami/bitnami-docker-mariadb#setting-the-root-password-on-first-run
  ##
  rootPassword: "********"       # default: ""
  ## @param auth.database Name for a custom database to create
  ## ref: https://github.com/bitnami/bitnami-docker-mariadb/blob/master/README.md#creating-a-database-on-first-run
  ##
  database: ysjeon_database      # default: "my_database"
…
  service:
    ## @param primary.service.type MariaDB Primary Kubernetes service type
    ##
    type: NodePort               # default: ClusterIP
…
$

 

- MariaDB 설치

$ helm install ysjeon-mariadb bitnami/mariadb --create-namespace --namespace yoosung-jeon --values mariadb_9.6.1_yoosung-jeon.values
NAME: ysjeon-mariadb
LAST DEPLOYED: Mon Oct  4 15:41:44 2021
NAMESPACE: yoosung-jeon
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
** Please be patient while the chart is being deployed **

Tip:
  Watch the deployment status using the command: kubectl get pods -w --namespace yoosung-jeon -l app.kubernetes.io/instance=ysjeon-mariadb

Services:
  echo Primary: ysjeon-mariadb.yoosung-jeon.svc.cluster.local:3306

Administrator credentials:
  Username: root
  Password : $(kubectl get secret --namespace yoosung-jeon ysjeon-mariadb -o jsonpath="{.data.mariadb-root-password}" | base64 --decode)

To connect to your database:
  1. Run a pod that you can use as a client:
      kubectl run ysjeon-mariadb-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mariadb:10.5.12-debian-10-r32 --namespace yoosung-jeon --command -- bash

  2. To connect to primary service (read/write):
      mysql -h ysjeon-mariadb.yoosung-jeon.svc.cluster.local -uroot -p ysjeon_database

To upgrade this helm chart:
  1. Obtain the password as described on the 'Administrator credentials' section and set the 'auth.rootPassword' parameter as shown below:
      ROOT_PASSWORD=$(kubectl get secret --namespace yoosung-jeon ysjeon-mariadb -o jsonpath="{.data.mariadb-root-password}" | base64 --decode)
      helm upgrade --namespace yoosung-jeon ysjeon-mariadb bitnami/mariadb --set auth.rootPassword=$ROOT_PASSWORD
$ helm list -n yoosung-jeon
NAME          	NAMESPACE   	REVISION	UPDATED                             	STATUS  	CHART        	APP VERSION
ysjeon-mariadb	yoosung-jeon	1       	2021-10-04 15:41:44.400256 +0900 KST	deployed	mariadb-9.6.1	10.5.12
$

 

- 생성된 리소스 확인

$ k get statefulsets.apps ysjeon-mariadb -n yoosung-jeon
NAME             READY   AGE
ysjeon-mariadb   1/1     7m11s
$ k get pod -n yoosung-jeon -l app.kubernetes.io/name=mariadb
NAME               READY   STATUS    RESTARTS   AGE
ysjeon-mariadb-0   1/1     Running   0          8m13s
$ k get pvc -n yoosung-jeon -l app.kubernetes.io/name=mariadb
NAME                    STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
data-ysjeon-mariadb-0   Bound    pvc-c40fe9a8-e89d-4d49-b47c-734a47c62fe5   8Gi        RWO            nfs-sc-iap     9m20s
$ k get svc -n yoosung-jeon -l app.kubernetes.io/name=mariadb
NAME             TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
ysjeon-mariadb   NodePort   10.98.69.148   <none>        3306:30957/TCP   9m51s
$

 

 

4. DB  접속

a. Kubernetes 내부에서 접속

- MariaDB Client용 Pod 생성 및 DB 접속

   Kubernetes Pod에서 실행되는 어플리케이션들이 사용할 MariaDB 접속 정보는 아래와 같음

       Host: ysjeon-mariadb.yoosung-jeon.svc.cluster.local

       Port: 3306 (default)

$ kubectl run ysjeon-mariadb-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mariadb:10.5.12-debian-10-r32 --namespace yoosung-jeon --command -- bash
If you don't see a command prompt, try pressing enter.
I have no name!@ysjeon-mariadb-client:/$ mysql -h ysjeon-mariadb.yoosung-jeon.svc.cluster.local -uroot -p ysjeon_database
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 256
Server version: 10.5.12-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [ysjeon_database]> select version();
+-----------------+
| version()       |
+-----------------+
| 10.5.12-MariaDB |
+-----------------+
1 row in set (0.000 sec)

MariaDB [ysjeon_database]>

 

- MariaDB Client용 Pod 생성후 재 접속 시

   "kubectl exec" 명령어를 사용 할 것

$ kubectl run ysjeon-mariadb-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mariadb:10.5.12-debian-10-r32 --namespace yoosung-jeon --command -- bash
Error from server (AlreadyExists): pods "ysjeon-mariadb-client" already exists
$ kubectl exec ysjeon-mariadb-client --namespace yoosung-jeon --tty -i -- bash
I have no name!@ysjeon-mariadb-client:/$

 

b. Kubernetes 외부에서 접속

- DBeaver 클라이언트 툴에서 DB 접속

   Server Host: 14.52.244.136 (Kubernetes node IP)

   Port: 30957 (생성한 MariaDB의 NodePort : 'k get svc -n yoosung-jeon -l app.kubernetes.io/name=mariadb')

 

 

5. MariaDB replication cluster 구성

- https://engineering.bitnami.com/articles/deploy-a-production-ready-mariadb-cluster-on-kubernetes-with-bitnami-and-helm.html

   ✓ To make it easy to deploy MariaDB in production environments, Bitnami now offers a MariaDB Helm chart.

   ✓ One of its key features is data replication, which allows data to be mirrored across multiple nodes.

   ✓ Data automatically replicates from the master node to all slave nodes using the binary log.

   ✓ The master node receives all write operations, while the slave nodes are used for read operation.

- 참조: MariaDB - replication

 

 

6. MariaDB 설치 (추가 정보)

- 위에서 설명한 Helm chart (bitnami/mariadb)외에 MariaDB를 설치 하는 추가적인 방법들은 아래와 같음

 

a. MariaDB Galena

- MariaDB Galena helm chart

   https://bitnami.com/stack/mariadb-galera/helm

- What is MariaDB Galera Cluster?

   ✓ MariaDB Galera Cluster is a virtually synchronous multi-primary cluster for MariaDB. 

       It is available on Linux only, and only supports the InnoDB storage engine 

   ✓ Features

       ▷ Virtually synchronous replication

       ▷ Active-active multi-primary topology

       ▷ Read and write to any cluster node

       ▷ Automatic membership control, failed nodes drop from the cluster

       ▷ Automatic node joining

       ▷ True parallel replication, on row level

       ▷ Direct client connections, native MariaDB look & feel

   ✓ Benefits

       ▷ The above features yield several benefits for a DBMS clustering solution, including:

       ▷ No replica lag

       ▷ No lost transactions

       ▷ Read scalability

       ▷ Smaller client latencies

 

b.Kubernetes Operators for MariaDB

- https://mariadb.com/kb/en/kubernetes-operators-for-mariadb/

- https://operatorhub.io/operator/mariadb-operator-app

- OperatorHub.io has a MariaDB operator. At the time of this writing (21.9.2) it is in alpha stage, so please check its maturity before using it.

- This operator enables you to create MariaDB server and database easily by defining simple Custom Resource. Operator's features are as follows:

   ✓ Setup a MariaDB server with configured version

   ✓ Create a custom database along with a user credential set for the custom database

   ✓ Operator uses Persistent Volume where MariaDB can write its data files

   ✓ Seamless upgrades of MariaDB is possible without loosing existing data

   ✓ Take full backup of Database at user defined location - mariabackup

   ✓ Schedule backup at regular intervals

   ✓ Monitor metrics for mariadb node - Prometheus

'Kubernetes > DBMS' 카테고리의 다른 글

MariaDB - replication  (0) 2021.10.29
Crunchy PostgreSQL Managements  (0) 2021.09.23
Crunchy PostgreSQL Operator #2  (0) 2021.09.23
Crunchy PostgreSQL Operator #1  (0) 2021.09.23

댓글