Component Configuration File

This article will introduce how to mount configuration files for components in Kato and configure file sharing between multiple components. It is suitable for scenarios where multiple components need to use the same configuration file. It can be shared directly without editing the settings multiple times; The shared configuration file will only parse the environment variables of the current component; the following will take MariaDB as an example to demonstrate the use of the configuration file.

Overview

Kato combines configuration files implemented by Kubernetes' ConfigMap. It is a special storage type. This type allows users to directly define file content, usually referred to as configuration files. Configuration files have two major features: dynamic rendering of environment variables and configuration file sharing.

The official image of MariaDB, which shows two ways to customize the configuration file

###Item 1

A configuration file is required on the host machine, and this configuration file is mounted to the container’s /etc/mysql/conf.d directory when the container starts?, the configuration under /etc/mysql/conf.d The file will overwrite the default configuration file /etc/mysql/my.cnf in the container.

This method is not flexible enough. It is impossible to confirm which node the Pod will be scheduled on when the component is created (the data center is usually a cluster). After the component is created, the configuration file can be mounted, and then the component can be restarted. It takes effect.

###Item 2

Pass in relevant parameters in the docker run command when the container is started, for example, modify the default encoding and proofreading rules through the two parameters of character-set-server and collation-server:

docker run --name some-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

This method is also not flexible enough. If there are many parameters to be set, the docker run command will be very long.

Kato Configuration Method

Kato combines the configuration file implemented by k8s ConfigMap? This method is more flexible, can dynamically render environment variables, and can also be shared with other components. The following demonstrates Kato’s configuration file mounting and sharing configuration file methods.

Prerequisites

  1. You can connect to the external network, pull the GitHub code, use the source code to build the MariaDB project, set the subdirectory to 10.5;
  2. Have a MariaDB configuration file.

Sample configuration file

# MariaDB-specific config file.
# Read by /etc/mysql/my.cnf

[client]
# Default is Latin1, if you need UTF-8 set this (also in server section)
default-character-set = ${DEFAULT_CHARACTER_SET:utf8}

[mysqld]
#
# * Character sets
#
# Default is Latin1, if you need UTF-8 set all this (also in client section)
#
character-set-server = ${CHARACTER_SET_SERVER:utf8}
collation-server = ${COLLATION_SERVER:utf8_general_ci}
character_set_server = ${CHARACTER_SET_SERVER:utf8}
collation_server = ${COLLATION_SERVER:utf8_general_ci}

default_storage_engine = ${DEFAULT_STORAGE_ENGINE:innodb}

# Import all .cnf files from configuration directory
!includedir /etc/mysql/mariadb.conf.d/

###Configuration File Explanation

In this configuration file, dynamic rendering configuration file parsing environment variables are used, and DEFAULT_CHARACTER_SET, CHARACTER_SET_SERVER, DEFAULT_STORAGE_ENGINE and other variables that can parse environment variables are set, and default values ​​are set for them, If the specified environment variable exists in the component, Kato will parse the value of the environment variable into the configuration file; if the environment variable does not exist in the component, then Kato will parse the default value into the configuration file; if specified If the environment variable does not exist and the default value is not set, Kato will not parse it.

The syntax of dynamic rendering configuration file parsing environment variables:

${environment variable name}
${Environment variable name: default value}

Steps

  1. Create MariaDB component from source code, do not check build and start when creating

  1. In the component management page Environment Configuration –> Configuration File Settings, click Add Configuration File, use the above example configuration file, and the mount path is /etc/mysql/mariadb.cnf ;as the picture shows:

  1. Add environment variables

On the component management page Environment Configuration –> Custom Environment Variables –> Add Variables Add environment variables DEFAULT_STORAGE_ENGINE=myisam and MYSQL_ROOT_PASSWORD=kato for the component

Show Results

  1. Build MariaDB components, enter the container after successful startup? Check the contents of /etc/mysql/mariadb.cnf

<img src=“https://drive.google.com/file/d/1Se0s4QJ-q1fpnWrn6QSpGHp4yfDvOpfN/view?usp=sharing” width=“100%” / >

It can be found that Kato did not find DEFAULT_CHARACTER_SET, CHARACTER_SET_SERVER etc. variables corresponding to the environment variables, and then used their corresponding default values ​​for analysis; found the environment variables corresponding to DEFAULT_STORAGE_ENGINE, then use the environment variable DEFAULT_STORAGE_ENGINE The? value of myisam is parsed.

  1. Log in to MySQL to check whether the configuration takes effect:
# Login to MySQL
root@gr52b3ee-0:/# mysql -uroot -pkato

# Check coding and proofreading rules
MariaDB [(none)]> show variables like "%character%";
+--------------------------+---------------------- ------+
| Variable_name | Value |
+--------------------------+---------------------- ------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ | |
+--------------------------+---------------------- ------+

# View storage engine
MariaDB [(none)]> SHOW STORAGE ENGINES;
+--------------------+---------+------------------ -------------------------------------------------- --------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+------------------ -------------------------------------------------- --------------+--------------+------+------------+
| MRG_MyISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| CSV | YES | Stores tables as CSV files | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| MyISAM | DEFAULT | Non-transactional engine with good performance and small data footprint | NO | NO | NO |
| Aria | YES | Crash-safe tables with MyISAM heritage | NO | NO | NO |
| InnoDB | YES | Supports transactions, row-level locking, foreign keys and encryption for tables | YES | YES | YES |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| SEQUENCE | YES | Generated tables filled with sequential values ​​| YES | NO | YES |
+--------------------+---------+------------------ -------------------------------------------------- --------------+--------------+------+------------+

It can be seen that the encoding, proofreading rules, and storage engine settings have all taken effect.

Configure file sharing

Prerequisites

The configuration file has been mounted for MariaDB through the above steps

Steps

  1. Re-create a MariaDB component,
  2. In the component management interface Environment Configuration –> Shared Configuration File –> Mount Shared Configuration File Find the MariaDB configuration file above and fill in the mount path to update the component, as shown in the figure:

Show results

After the creation is complete, enter the container to view the content of the configuration file /etc/mysql/mariadb.cnf as follows:

# MariaDB-specific config file.
# Read by /etc/mysql/my.cnf

[client]
# Default is Latin1, if you need UTF-8 set this (also in server section)
default-character-set = utf8

[mysqld]
#
# * Character sets
#
# Default is Latin1, if you need UTF-8 set all this (also in client section)
#
character-set-server = utf8
collation-server = utf8_general_ci
character_set_server = utf8
collation_server = utf8_general_ci

default_storage_engine = innodb

# Import all .cnf files from configuration directory

As you can see, because the DEFAULT_STORAGE_ENGINE variable is not set in the current component, Kato uses its default? value innodb for analysis, and other configurations have taken effect.