在 Kubernetes 部署中指定 [mysqld]

Specify [mysqld] in Kubernetes deployment

这是我的configMap。我正在尝试指定 [mysqld] 配置,但是当我将此文件单独与

一起使用时
helm upgrade -i eramba bitnami/mariadb --set auth.rootPassword=eramba,auth.database=erambadb,initdbScriptsConfigMap=eramba,volumePermissions.enabled=true,primary.persistence.existingClaim=eramba-storage --namespace eramba-1 --set mariadb.volumePermissions.enabled=true

我在我的数据库 pod 中没有看到指定的配置;但是,我确实看到应用了 c2.8.1.sql 文件。

apiVersion: v1
kind: ConfigMap
metadata:
  name: eramba
  namespace: eramba-1
data:
  my.cnf: |-
    [mysqld] 
    max_connections = 2000
    sql_mode=""
    max_allowed_packet="128000000"
    innodb_lock_wait_timeout="200"
  c2.8.1.sql: |
    CREATE DATABASE IF NOT EXISTS erambadb;
    #create user 'erambauser'@'eramba-mariadb' identified by 'erambapassword';
    #grant all on erambadb.* to 'erambauser'@'eramba-mariadb';
    #flush privileges;
    USE erambadb;
    #
    # SQL Export
    # Created by Querious (201067)
    # Created: 22 October 2019 at 17:39:48 CEST
    # Encoding: Unicode (UTF-8)
    #
    
    SET @PREVIOUS_FOREIGN_KEY_CHECKS = @@FOREIGN_KEY_CHECKS;
    SET FOREIGN_KEY_CHECKS = 0;
    .....

如果您查看 MariaDB helm chart 的 values.yaml 文件,您可以看到 3 种类型的 ConfigMap:

  • initdbScriptsConfigMap - 提供 Init 脚本 运行 在第一次启动数据库实例时
  • primary.existingConfigmap - 控制 MariaDB Primary 实例配置
  • secondary.existingConfigmap - 控制MariaDB Secondary实例配置

因此,它们中的每一个都用于特定目的,将这些设置混合在一个 ConfigMap 中并不是一个好主意。

我建议您为自定义 my.cnf 创建新的 ConfigMap eramba2,其中包含所有必要的值(不仅是新的),如下所示。

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: eramba2
      namespace: eramba-1
    data:
      my.cnf: |-
        [mysqld]
        skip-name-resolve
        explicit_defaults_for_timestamp
        max_connections = 2000
        sql_mode=""
        innodb_lock_wait_timeout="200"
        basedir=/opt/bitnami/mariadb
        plugin_dir=/opt/bitnami/mariadb/plugin
        port=3306
        socket=/opt/bitnami/mariadb/tmp/mysql.sock
        tmpdir=/opt/bitnami/mariadb/tmp
        max_allowed_packet=128000000
        bind-address=::
        pid-file=/opt/bitnami/mariadb/tmp/mysqld.pid
        log-error=/opt/bitnami/mariadb/logs/mysqld.log
        character-set-server=UTF8
        collation-server=utf8_general_ci
    
        [client]
        port=3306
        socket=/opt/bitnami/mariadb/tmp/mysql.sock
        default-character-set=UTF8
        plugin_dir=/opt/bitnami/mariadb/plugin
    
        [manager]
        port=3306
        socket=/opt/bitnami/mariadb/tmp/mysql.sock
        pid-file=/opt/bitnami/mariadb/tmp/mysqld.pid

创建 eramba2 ConfigMap:

kubectl create -f eramba2.yaml

然后使用 helm 使用新的 ConfigMap eramba2 创建 MariaDB:

helm upgrade -i eramba bitnami/mariadb --set auth.rootPassword=eramba,auth.database=erambadb,initdbScriptsConfigMap=eramba,volumePermissions.enabled=true,primary.persistence.existingClaim=eramba-storage,mariadb.volumePermissions.enabled=true,primary.existingConfigmap=eramba2 --namespace eramba-1

连接到 pod:

kubectl exec -it eramba-mariadb-0 -- /bin/bash

检查my.cnf文件:

cat /opt/bitnami/mariadb/conf/my.cnf