MariaDB
MariaDB is an open-source relational database management system usually known as a replacement for MySQL. One of MariaDB's most important advantages over MySQL is its improved performance and scalability. MariaDB has made many optimizations to MySQL's original code, which make queries run faster and improve its performance.
In the Arvancloud Cloud Container, you can install and manage MariaDB using operators. These operators use version 0.0.29 of the MariaDB project.
Setting Up MariaDB
Save the following file with a name of your choice, such as mariadb.yaml:
apiVersion: k8s.mariadb.com/v1alpha1
kind: MariaDB
metadata:
name: mariadb
spec:
rootPasswordSecretKeyRef:
name: mariadb
key: root-password
generate: true
username: mariadb
passwordSecretKeyRef:
name: mariadb
key: password
generate: true
database: mariadb
image: mariadb:10.11.7
imagePullPolicy: IfNotPresent
port: 3306
storage:
size: 1Gi
service:
type: ClusterIP
# type: LoadBalancer
# metadata:
# annotations:
# metallb.universe.tf/loadBalancerIPs: 172.18.0.20
myCnf: |
[mariadb]
bind-address=*
default_storage_engine=InnoDB
binlog_format=row
innodb_autoinc_lock_mode=2
max_allowed_packet=256M
metrics:
enabled: false
Then run the following command to deploy it:
kubectl apply -f mariadb.yaml -n [namespace]
Replace [namespace] with your project's name in the Arvancloud Cloud Container.
Note that to use
spec.passwordSecretKeyRef.generate=trueand for MariaDB to work correctly, you need to edit the Secret, add the valuepassword:BASE64to it, and then delete the Pod.
Configuring the MariaDB Database
Save the following file with a name of your choice, such as database.yaml:
apiVersion: k8s.mariadb.com/v1alpha1
kind: Database
metadata:
name: data-test
spec:
# If you want the database to be created with a different name than the resource name
# name: data-custom
mariaDbRef:
name: mariadb
characterSet: utf8
collate: utf8_general_ci
requeueInterval: 30s
retryInterval: 5s
Then run the following command to deploy it:
kubectl apply -f database.yaml -n [namespace]
Replace [namespace] with your project's name in the Arvancloud Cloud Container.
Creating a User in MariaDB
Save the following file with a name of your choice, such as user.yaml:
apiVersion: k8s.mariadb.com/v1alpha1
kind: User
metadata:
name: user
spec:
# If you want the user to be created with a different name than the resource name
# name: user-custom
mariaDbRef:
name: mariadb
passwordSecretKeyRef:
name: mariadb
key: password
# This field is immutable and defaults to 10
maxUserConnections: 20
host: "%"
retryInterval: 5s
Then run the following command to deploy it:
kubectl apply -f user.yaml -n [namespace]
Replace [namespace] with your project's name in the Arvancloud Cloud Container.
Managing Permissions in MariaDB
Save the following file with a name of your choice, such as grant.yaml:
apiVersion: k8s.mariadb.com/v1alpha1
kind: Grant
metadata:
name: grant
spec:
mariaDbRef:
name: mariadb
privileges:
- "SELECT"
- "INSERT"
- "UPDATE"
# - "ALL PRIVILEGES"
database: "*"
table: "*"
username: user
grantOption: true
host: "%"
requeueInterval: 30s
retryInterval: 5s
Then run the following command to deploy it:
kubectl apply -f grant.yaml -n [namespace]
Replace [namespace] with your project's name in the Arvancloud Cloud Container.
For more details and examples, see the MariaDB operator documentation.