Initialize database on Kubernetes
The purpose of this tutorial is to show how to initialize a MariaDB database required for Soffid IAM installation.installation on Kubernetes.
Prerequisites
First of all, you sould install a database required in the Soffid IAM installation.
The supported databases are:
MySQLMariaDBPostgreSQLOracleMicrosoft SqlServer
MySQL/MariaDB
InTo orderinitialize toMariaDB configureon MySQLKubernetes databasefirst of all you need access to the database administration tool (mysql) with superuser permissions using a TCP/IP connection. If needed, pleasemust create a userPersistent forVolume. the Soffid installation. If you don't have such a user, or don't know its password, please access MySQL as root, execute the mysql tool and create the user with grant command (where ADMIN_USER is the user to be used during the installation process to create the soffid repository database and ADMIN_PASSWORD is the required password).
|
In addition, in order to be able to manage big files, like process definition or software addons, we have to modify max_allowed_packet parameter on MySQL. This parameter is commonly allocated on the /etc/mysql/my.cnf file.
|
If the version of MariaDB is 10.1.38, or newer, the recommended value for max_allowed_packet is 512M
Note:Storage in the case wecluster will obtainbe provisioned using Storage Classes.
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-pv3
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /home/ulocal/kubernetes-disk3
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- soffid123
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mariadb-claim3
spec:
storageClassName: local-storage
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
Path "/home/ulocal/kubernetes-disk3" must be exists.
Then you must define the nextMariaDB 'Thedeployment:
apiVersion: ofapps/v1
BLOB/TEXTkind: dataDeployment
insertedmetadata:
name: mariadb3
labels:
app: soffid
instance: "Soffid-3"
type: database
spec:
strategy:
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
type: RollingUpdate
replicas: 1
selector:
matchLabels:
app: soffid
instance: "Soffid-3"
type: database
template:
metadata:
labels:
app: soffid
instance: "Soffid-3"
type: database
spec:
restartPolicy: Always
containers:
- name: mariadb3
image: mariadb
resources:
limits:
memory: 2Gi
requests:
memory: 400Mi
args:
- "--max-allowed-packet=175M"
- "--innodb-log-file-size=256M"
- "--character-set-server=utf8"
- "--collation-server=utf8_bin"
- "--net-read-timeout=3600"
- "--net-write-timeout=3600"
- "--innodb-buffer-pool-size=100M"
ports:
- containerPort: 3306
name: db-port
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mariadb
key: root_password
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: mariadb
key: username
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mariadb
key: password
- name: MYSQL_DATABASE
value: soffid
volumeMounts:
- name: mysql-persistent-storage3
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage3
persistentVolumeClaim:
claimName: mariadb-claim3
---
apiVersion: v1
kind: Service
metadata:
name: mariadb3-service
namespace: default
spec:
clusterIP: None
ports:
- name: mariadb
port: 3306
protocol: TCP
targetPort: 3306
selector:
app: soffid
instance: "Soffid-3"
type: database
type: ClusterIP
Finally you must create resources in onea transaction is greater than 10% of redo log size. Increase the redo log size using innodb_log_file_size.' error trying to upload an addon, we may update the default value of this mysql/mariadb parameter. This parameter is commonly allocated on the /etc/mysql/my.cnf file.cluster:
kubectl apply -f mariadb-pv-file.yaml
kubectl apply -f
[mysqld]mariadb-deployment-file.yaml
innodb_log_file_size=256M
If you are installing on a Ubuntu 18.04 server, default character set is set to utf8mb4. Using this character set can cause problems, as many index sizes will exceed maximum key size of 767 bytes. To prevent this problem, change following settings:
|
Alternatively, if UTF character set is required, write the following settings:
|
Following this link you will find the steps to setup a two nodes database cluster.
Video Tutorial
MariaDB initialization using Docker
MariaDB initialization in Kubernetes
Oracle
A new database instance should be created. Optionally two tablespaces should be created (SOFFID_DATA and SOFFID_INDEX) to separate soffid tables and indexes.
|
To create the tablespace is necessary to provide the full path name, its size and MANAGEMENT AUTOALLOCATE option. The autoallocate option is needed because the tables are not sized by database creation scripts. Also, the Oracle Listener must have a TCP/IP port accepting connections.
Microsoft SQLServer
You must enable the SQL Server Browser Service at startup and the authentication method have to be set to “SQL Server and Windows Authentication mode”.
In addition, you must ensure that 'READ_COMMITTED_SNAPSHOT" parameter is enabled, you can do so with the following command:
|