创建实例

Alauda Database Service for MySQL-PXC 提供了一套在 Kubernetes 集群中创建和管理 MySQL 数据库实例的功能。用户可以通过配置资源规格、参数模板、账户信息、调度策略和 Pod 容忍规则,快速部署符合需求的 MySQL 实例。实例创建完成后,部分参数可以动态调整,但调度配置不可修改。

目录

前提条件

在创建 MySQL-PXC 实例之前,请确保您已查看 ,并确认当前集群支持该类型的存储类且有足够的可用空间。建议使用 TopoLVM 存储类。

操作步骤

CLI
Web Console
  1. 创建密码

    kubectl -n <namespace> create secret generic <name>  \
        --from-literal=clustercheck=<password> \
        --from-literal=monitor=<password> \
        --from-literal=operator=<password> \
        --from-literal=proxyadmin=<password> \
        --from-literal=root=<password> \
        --from-literal=xtrabackup=<password>
INFO
  • <name> 是用于标识实例的密码名称,必须唯一;建议与实例名称相同。此名称设置在实例的 spec.pxc.secretsName 字段中。
  • <namespace> 是实例所属的命名空间。
  • <password> 是密码,可以为上述多个用户设置不同的密码。
  1. 创建实例

    kubectl -n <namespace> apply -f - <<EOF
    apiVersion: middleware.alauda.io/v1
    kind: Mysql
    metadata:
      annotations:
        middleware.upgrade.component.version: ""
        middleware.upgrade.crVersion: ""
      labels:
        mysql/arch: pxc
      name: <name>
      namespace: <namespace>
    spec:
      params:
        mysql:
            client:
                default_character_set: "utf8mb4"
            mysql:
                default_character_set: "utf8mb4"
                prompt: mysql(\u@\h:\d) >
            mysqld:
                autocommit: "ON"
                big_tables: "OFF"
                binlog_cache_size: "32768"
                binlog_checksum: "crc32"
                binlog_format: "ROW"
                binlog_row_image: "FULL"
                binlog_rows_query_log_events: "1"
                bulk_insert_buffer_size: "8388608"
                character_set_server: "utf8mb4"
                collation_server: "utf8mb4_general_ci"
                connect_timeout: "28800"
                default_authentication_plugin: "mysql_native_password"
                default_password_lifetime: "0"
                default_storage_engine: "INNODB"
                default_time_zone: "+8:00"
                default_tmp_storage_engine: "INNODB"
                event_scheduler: "ON"
                expire_logs_days: "2"
                explicit_defaults_for_timestamp: "1"
                general_log: "OFF"
                init_connect: "SET NAMES utf8mb4"
                innodb_adaptive_flushing: "ON"
                innodb_adaptive_flushing_lwm: "10"
                innodb_adaptive_hash_index: "OFF"
                innodb_autoinc_lock_mode: "2"
                innodb_buffer_pool_dump_at_shutdown: "1"
                innodb_buffer_pool_dump_pct: "40"
                innodb_buffer_pool_instances: "2"
                innodb_buffer_pool_load_at_startup: "1"
                innodb_buffer_pool_size: "1536M"
                innodb_checksum_algorithm: "crc32"
                innodb_checksums: "ON"
                innodb_cmp_per_index_enabled: "OFF"
                innodb_compression_level: "6"
                innodb_deadlock_detect: "1"
                innodb_default_row_format: "DYNAMIC"
                innodb_doublewrite: "1"
                innodb_fast_shutdown: "1"
                innodb_file_format: "Barracuda"
                innodb_file_format_check: "ON"
                innodb_file_format_max: "Barracuda"
                innodb_file_per_table: "ON"
                innodb_flush_log_at_timeout: "1"
                innodb_flush_log_at_trx_commit: "1"
                innodb_flush_method: "O_DIRECT_NO_FSYNC"
                innodb_flush_neighbors: "0"
                innodb_flushing_avg_loops: "30"
                innodb_force_recovery: "0"
                innodb_log_file_size: "1G"
                innodb_log_files_in_group: "2"
                innodb_lru_scan_depth: "2048"
                innodb_max_dirty_pages_pct: "90"
                innodb_max_dirty_pages_pct_lwm: "10"
                innodb_max_purge_lag: "0"
                innodb_max_purge_lag_delay: "0"
                innodb_max_undo_log_size: "2G"
                innodb_numa_interleave: "1"
                innodb_online_alter_log_max_size: "32M"
                innodb_page_cleaners: "2"
                innodb_page_size: "16384"
                innodb_print_all_deadlocks: "1"
                innodb_print_lock_wait_timeout_info: "ON"
                innodb_purge_batch_size: "300"
                innodb_purge_rseg_truncate_frequency: "128"
                innodb_purge_threads: "2"
                innodb_random_read_ahead: "OFF"
                innodb_read_ahead_threshold: "56"
                innodb_read_io_threads: "4"
                innodb_rollback_on_timeout: "0"
                innodb_rollback_segments: "128"
                innodb_sort_buffer_size: "1M"
                innodb_status_output: "0"
                innodb_status_output_locks: "1"
                innodb_strict_mode: "1"
                innodb_support_xa: "1"
                innodb_undo_log_truncate: "1"
                innodb_undo_logs: "128"
                innodb_use_native_aio: "ON"
                innodb_write_io_threads: "8"
                interactive_timeout: "28800"
                internal_tmp_disk_storage_engine: "INNODB"
                join_buffer_size: "262144"
                lock_wait_timeout: "50"
                log_bin: "bin"
                log_error_verbosity: "3"
                log_queries_not_using_indexes: "1"
                log_slow_admin_statements: "1"
                log_slow_slave_statements: "1"
                log_throttle_queries_not_using_indexes: "10"
                long_query_time: "20"
                max_allowed_packet: "64M"
                max_binlog_size: "1024M"
                max_connect_errors: "10000"
                max_connections: "300"
                max_heap_table_size: "16M"
                max_join_size: "18446744073709551615"
                max_user_connections: "60"
                min_examined_row_limit: "100"
                open_files_limit: "65535"
                pxc_strict_mode: "ENFORCING"
                query_cache_type: "0"
                read_buffer_size: "131072"
                read_rnd_buffer_size: "262144"
                show_compatibility_56: "OFF"
                skip_external_locking: "1"
                skip_name_resolve: "1"
                skip_symbolic_links: "ON"
                slow_query_log: "0"
                sort_buffer_size: "262144"
                sql_mode: "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
                sync_binlog: "1"
                table_open_cache: "4096"
                table_open_cache_instances: "2"
                thread_handling: "pool-of-threads"
                thread_pool_idle_timeout: "60"
                thread_pool_max_threads: "1000"
                thread_pool_oversubscribe: "8"
                thread_pool_size: "4"
                tmp_table_size: "16M"
                transaction_isolation: "READ-COMMITTED"
                wait_timeout: "28800"
                wsrep_OSU_method: "TOI"
                wsrep_RSU_commit_timeout: "5000"
                wsrep_auto_increment_control: "ON"
                wsrep_causal_reads: "OFF"
                wsrep_certification_rules: "strict"
                wsrep_certify_nonPK: "ON"
                wsrep_convert_LOCK_to_trx: "OFF"
                wsrep_debug: "OFF"
                wsrep_desync: "OFF"
                wsrep_dirty_reads: "OFF"
                wsrep_drupal_282555_workaround: "OFF"
                wsrep_forced_binlog_format: "ROW"
                wsrep_load_data_splitting: "ON"
                wsrep_log_conflicts: "OFF"
                wsrep_max_ws_rows: "0"
                wsrep_max_ws_size: "2147483647"
                wsrep_on: "ON"
                wsrep_preordered: "OFF"
                wsrep_recover: "OFF"
                wsrep_reject_queries: "NONE"
                wsrep_replicate_myisam: "OFF"
                wsrep_restart_slave: "OFF"
                wsrep_retry_autocommit: "1"
                wsrep_slave_FK_checks: "ON"
                wsrep_slave_UK_checks: "OFF"
                wsrep_slave_threads: "4"
                wsrep_sync_wait: "0"
      pxc:
        proxysql:
          resources:
            limits:
              cpu: 500m
              memory: 512Mi
            requests:
              cpu: 500m
              memory: 512Mi
          size: 3
          volumeSpec:
            persistentVolumeClaim:
              resources:
                requests:
                  storage: <size>Gi
              storageClassName: <storageClassName>
        pxc:
          resources:
            limits:
              cpu: "2"
              memory: 4Gi
            requests:
              cpu: "2"
              memory: 4Gi
          size: 3
          volumeSpec:
            persistentVolumeClaim:
              resources:
                requests:
                  storage: <size>Gi
              storageClassName: <storageClassName>
        secretsName: <name>
      runAsRoot: false
      upgradeOption:
        autoUpgrade: true
      version: "5.7"
    EOF
INFO
  • <name> 是用于标识实例的实例名称,必须唯一。
  • <namespace> 是实例所属的命名空间。
  • <spec.pxc.secretsName> 是步骤 1 中创建的密码名称。
  • <spec.params.mysql> 是 MySQL 参数配置,选项对应 MySQL 5.7。
  • <spec.pxc.pxc.resources> 是 PXC Pod 的资源配置,对应 Pod 资源配置。
  • <spec.pxc.pxc.volumeSpec.persistentVolumeClaim> 是 PXC Pod 的数据卷配置。
  • <spec.pxc.pxc.size> 是 PXC Pod 的数量。
  • <spec.pxc.proxysql.resources> 是 ProxySQL Pod 的资源配置,对应 Pod 资源配置。
  • <spec.pxc.proxysql.volumeSpec.persistentVolumeClaim> 是 ProxySQL Pod 的数据卷配置。
  • <spec.pxc.proxysql.size> 是 ProxySQL Pod 的数量。
  1. 等待实例创建完成

    kubectl get mysql -n <namespace> <name> -w

执行命令,等待结果中的 STATE 字段变为 ready。

  1. 访问实例

实例创建成功后,您可以访问实例并检查实例连接状态。