From 69aba216d4f5e73d4fbc181b7dda52480a87220c Mon Sep 17 00:00:00 2001 From: xuriwuyun Date: Wed, 22 Jan 2025 10:44:59 +0800 Subject: [PATCH] feat: mysql group replication (#1409) Co-authored-by: xuriwuyun --- README.md | 8 +- addons-cluster/mysql/templates/_helpers.tpl | 16 +-- addons-cluster/mysql/values.schema.json | 11 +- addons-cluster/mysql/values.yaml | 9 +- .../mysql/config/mysql-group-replication.tpl | 8 ++ addons/mysql/config/mysql5.7-config.tpl | 4 - addons/mysql/config/mysql8.0-config.tpl | 4 - addons/mysql/templates/_helpers.tpl | 48 ++++++- addons/mysql/templates/_names.tpl | 12 ++ addons/mysql/templates/clusterdefinition.yaml | 4 + addons/mysql/templates/cmpd-mysql80-mgr.yaml | 120 ++++++++++++++++ addons/mysql/templates/cmpd-mysql84-mgr.yaml | 108 ++++++++++++++ addons/mysql/templates/config-templates.yaml | 12 ++ addons/mysql/templates/cpmv-mgr.yaml | 134 ++++++++++++++++++ addons/mysql/values.yaml | 2 +- examples/mysql/cluster-mgr.yaml | 60 ++++++++ 16 files changed, 519 insertions(+), 41 deletions(-) create mode 100644 addons/mysql/config/mysql-group-replication.tpl create mode 100644 addons/mysql/templates/cmpd-mysql80-mgr.yaml create mode 100644 addons/mysql/templates/cmpd-mysql84-mgr.yaml create mode 100644 addons/mysql/templates/cpmv-mgr.yaml create mode 100644 examples/mysql/cluster-mgr.yaml diff --git a/README.md b/README.md index beadcb527..4cc562271 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,10 @@ KubeBlocks add-ons. | minio | minio-2024.6.29 | High Performance, Kubernetes Native Object Storage | fengluodb | | mogdb | mogdb-5.0.5 | A Helm chart for Kubernetes | yabinji shanshanying | | mongodb | mongodb-4.0.28
mongodb-4.2.24
mongodb-4.4.29
mongodb-5.0.28
mongodb-6.0.16
mongodb-7.0.12 | MongoDB is a document database designed for ease of application development and scaling. | xuriwuyun | -| mysql | mysql-5.7.44
mysql-8.0.30
mysql-8.0.31
mysql-8.0.32
mysql-8.0.33
mysql-8.0.34
mysql-8.0.35
mysql-8.0.36
mysql-8.0.37
mysql-8.0.38
mysql-8.0.39
mysql-8.4.0
mysql-8.4.1
mysql-8.4.2
mysql-orc-5.7.44
mysql-orc-8.0.30
mysql-orc-8.0.31
mysql-orc-8.0.32
mysql-orc-8.0.33
mysql-orc-8.0.34
mysql-orc-8.0.35
mysql-orc-8.0.36
mysql-orc-8.0.37
mysql-orc-8.0.38
mysql-orc-8.0.39
mysql-proxysql-2.4.4 | MySQL is a widely used, open-source relational database management system (RDBMS) | xuriwuyun | -| nebula | nebula-v3.5.0 | NebulaGraph is a popular open-source graph database that can handle large volumes of data with milliseconds of latency, scale up quickly, and have the ability to perform fast graph analytics. | Shanshan Ying Xuntao Cheng | -| neon | neon-broker-1.0.0
neon-compute-1.0.0
neon-pageserver-1.0.0
neon-safekeeper-1.0.0 | Neon is a serverless open-source alternative to AWS Aurora Postgres. It separates storage and compute and substitutes the PostgreSQL storage layer by redistributing data across a cluster of nodes. | skyrise | -| oceanbase-ce | oceanbase-ce-4.3.0 | OceanBase has served over 400 customers across the globe and has been supporting all mission critical systems in Alipay. | Powerfool shanshanying | +| mysql | mysql-5.7.44
mysql-8.0.30
mysql-8.0.31
mysql-8.0.32
mysql-8.0.33
mysql-8.0.34
mysql-8.0.35
mysql-8.0.36
mysql-8.0.37
mysql-8.0.38
mysql-8.0.39
mysql-8.4.0
mysql-8.4.1
mysql-8.4.2
mysql-mgr-8.0.30
mysql-mgr-8.0.31
mysql-mgr-8.0.32
mysql-mgr-8.0.33
mysql-mgr-8.0.34
mysql-mgr-8.0.35
mysql-mgr-8.0.36
mysql-mgr-8.0.37
mysql-mgr-8.0.38
mysql-mgr-8.0.39
mysql-mgr-8.4.0
mysql-mgr-8.4.1
mysql-mgr-8.4.2
mysql-orc-5.7.44
mysql-orc-8.0.30
mysql-orc-8.0.31
mysql-orc-8.0.32
mysql-orc-8.0.33
mysql-orc-8.0.34
mysql-orc-8.0.35
mysql-orc-8.0.36
mysql-orc-8.0.37
mysql-orc-8.0.38
mysql-orc-8.0.39
mysql-proxysql-2.4.4 | MySQL is a widely used, open-source relational database management system (RDBMS) | xuriwuyun | +| nebula | nebula-v3.5.0 | NebulaGraph is a popular open-source graph database that can handle large volumes of data with milliseconds of latency, scale up quickly, and have the ability to perform fast graph analytics. | shanshanying Xuntao Cheng | +| neon | neon-broker-1.0.0
neon-compute-1.0.0
neon-pageserver-1.0.0
neon-safekeeper-1.0.0 | Neon is a serverless open-source alternative to AWS Aurora Postgres. It separates storage and compute and substitutes the PostgreSQL storage layer by redistributing data across a cluster of nodes. | skyrise-l | +| oceanbase-ce | oceanbase-ce-4.3.0 | OceanBase has served over 400 customers across the globe and has been supporting all mission critical systems in Alipay. | Powerfooi shanshanying | | opensearch | opensearch-2.7.0
opensearch-dashboard-2.7.0 | Open source distributed and RESTful search engine. | iziang | | orchestrator | orchestrator-3.2.6 | Orchestrator is a MySQL high availability and replication management tool, runs as a service and provides command line access, HTTP API and Web interface. | kubeJocker | | orioledb | orioledb-14.7.2 | OrioleDB is a new storage engine for PostgreSQL, bringing a modern approach to database capacity, capabilities and performance to the world's most-loved database platform. | 1aal | diff --git a/addons-cluster/mysql/templates/_helpers.tpl b/addons-cluster/mysql/templates/_helpers.tpl index cacf1d4c9..50356be82 100644 --- a/addons-cluster/mysql/templates/_helpers.tpl +++ b/addons-cluster/mysql/templates/_helpers.tpl @@ -1,21 +1,19 @@ {{/* Define replica count. -standalone mode: 1 -replication mode: 2 -raftGroup mode: 3 or more - +semisync: 2 or more +mgr: 3 or more orchestrator mode: 2 or more */}} {{- define "mysql-cluster.replicaCount" -}} {{- if .Values.orchestrator.enable }} replicas: {{ max .Values.replicas 2 }} {{- else }} - {{- if eq .Values.mode "standalone" }} -replicas: 1 - {{- else if eq .Values.mode "replication" }} -replicas: {{ max .Values.replicas 2 }} - {{- else }} + {{- if hasPrefix "semisync" .Values.topology }} +replicas: 2 + {{- else if hasPrefix "mgr" .Values.topology }} replicas: {{ max .Values.replicas 3 }} + {{- else }} +replicas: {{ max .Values.replicas 2 }} {{- end }} {{- end }} {{- end }} \ No newline at end of file diff --git a/addons-cluster/mysql/values.schema.json b/addons-cluster/mysql/values.schema.json index 19d01e9a0..8604aba1a 100644 --- a/addons-cluster/mysql/values.schema.json +++ b/addons-cluster/mysql/values.schema.json @@ -18,16 +18,6 @@ "5.7.44" ] }, - "mode": { - "title": "Mode", - "description": "Cluster topology mode.", - "type": "string", - "default": "standalone", - "enum": [ - "standalone", - "replication" - ] - }, "replicas": { "title": "Replicas", "description": "The number of replicas.", @@ -77,6 +67,7 @@ "enum": [ "semisync", "semisync-proxysql", + "mgr", "orc", "orc-proxysql" ] diff --git a/addons-cluster/mysql/values.yaml b/addons-cluster/mysql/values.yaml index 155a88df5..90159add7 100644 --- a/addons-cluster/mysql/values.yaml +++ b/addons-cluster/mysql/values.yaml @@ -6,13 +6,9 @@ ## version: 8.0.39 -## @param mode MySQL cluster topology mode, standalone, replication -## -mode: standalone - ## @param replicas specify cluster replicas ## -replicas: 1 +replicas: 2 ## @param cpu ## @@ -32,7 +28,7 @@ requests: ## @param storage size, the unit is Gi ## storage: 20 -topology: semisync +topology: mgr proxysql: replicas: 1 cpu: 1 @@ -42,6 +38,7 @@ proxysql: extra: rbacEnabled: true terminationPolicy: Delete + disableExporter: true orchestrator: # monitor_password: proxysql diff --git a/addons/mysql/config/mysql-group-replication.tpl b/addons/mysql/config/mysql-group-replication.tpl new file mode 100644 index 000000000..81da84c11 --- /dev/null +++ b/addons/mysql/config/mysql-group-replication.tpl @@ -0,0 +1,8 @@ +[mysqld] +binlog_format=ROW +binlog_checksum=NONE +plugin_load_add='group_replication.so' +plugin_load_add='mysql_clone.so' +loose_group_replication_recovery_get_public_key=ON +loose_group_replication_start_on_boot=off +loose_group_replication_bootstrap_group=off \ No newline at end of file diff --git a/addons/mysql/config/mysql5.7-config.tpl b/addons/mysql/config/mysql5.7-config.tpl index 551582aee..1277543e4 100644 --- a/addons/mysql/config/mysql5.7-config.tpl +++ b/addons/mysql/config/mysql5.7-config.tpl @@ -166,10 +166,6 @@ character_set_server = utf8mb4 # rpl_semi_sync_master_timeout = 1000 # rpl-semi-sync-slave-enabled = 1 -[mysql] -default-character-set=utf8mb4 - [client] port={{ $mysql_port }} socket=/var/run/mysqld/mysqld.sock -default-character-set=utf8mb4 diff --git a/addons/mysql/config/mysql8.0-config.tpl b/addons/mysql/config/mysql8.0-config.tpl index f81843e15..f72d779fb 100644 --- a/addons/mysql/config/mysql8.0-config.tpl +++ b/addons/mysql/config/mysql8.0-config.tpl @@ -198,10 +198,6 @@ default_tmp_storage_engine=innodb collation_server = utf8mb4_unicode_520_ci character_set_server = utf8mb4 -[mysql] -default-character-set=utf8mb4 - [client] port={{ $mysql_port }} socket=/var/run/mysqld/mysqld.sock -default-character-set=utf8mb4 diff --git a/addons/mysql/templates/_helpers.tpl b/addons/mysql/templates/_helpers.tpl index 96ee32492..4550babc7 100644 --- a/addons/mysql/templates/_helpers.tpl +++ b/addons/mysql/templates/_helpers.tpl @@ -108,6 +108,25 @@ systemAccounts: numDigits: 5 numSymbols: 0 letterCase: MixedCases + - name: kbadmin + statement: select 1; + passwordGenerationPolicy: &defaultPasswordGenerationPolicy + length: 16 + numDigits: 8 + numSymbols: 0 + letterCase: MixedCases + - name: kbdataprotection + statement: CREATE USER ${KB_ACCOUNT_NAME} IDENTIFIED BY '${KB_ACCOUNT_PASSWORD}';GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON ${ALL_DB} TO ${KB_ACCOUNT_NAME}; GRANT LOCK TABLES,RELOAD,PROCESS,REPLICATION CLIENT, SUPER,SELECT,EVENT,TRIGGER,SHOW VIEW ON ${ALL_DB} TO ${KB_ACCOUNT_NAME}; + passwordGenerationPolicy: *defaultPasswordGenerationPolicy + - name: kbprobe + statement: CREATE USER ${KB_ACCOUNT_NAME} IDENTIFIED BY '${KB_ACCOUNT_PASSWORD}'; GRANT REPLICATION CLIENT, PROCESS ON ${ALL_DB} TO ${KB_ACCOUNT_NAME}; GRANT SELECT ON performance_schema.* TO ${KB_ACCOUNT_NAME}; + passwordGenerationPolicy: *defaultPasswordGenerationPolicy + - name: kbmonitoring + statement: CREATE USER ${KB_ACCOUNT_NAME} IDENTIFIED BY '${KB_ACCOUNT_PASSWORD}'; GRANT REPLICATION CLIENT, PROCESS ON ${ALL_DB} TO ${KB_ACCOUNT_NAME}; GRANT SELECT ON performance_schema.* TO ${KB_ACCOUNT_NAME}; + passwordGenerationPolicy: *defaultPasswordGenerationPolicy + - name: kbreplicator + statement: select 1; + passwordGenerationPolicy: *defaultPasswordGenerationPolicy - name: proxysql statement: CREATE USER IF NOT EXISTS '${KB_ACCOUNT_NAME}' IDENTIFIED BY '${KB_ACCOUNT_PASSWORD}'; GRANT SELECT ON performance_schema.* TO '${KB_ACCOUNT_NAME}'; GRANT SELECT ON sys.* TO '${KB_ACCOUNT_NAME}'; vars: @@ -115,6 +134,10 @@ vars: valueFrom: clusterVarRef: clusterName: Required + - name: CLUSTER_UUID + valueFrom: + clusterVarRef: + clusterUID: Required - name: CLUSTER_NAMESPACE valueFrom: clusterVarRef: @@ -139,21 +162,40 @@ vars: credentialVarRef: name: root password: Required + - name: MYSQL_ADMIN_USER + valueFrom: + credentialVarRef: + name: kbadmin + username: Required + - name: MYSQL_ADMIN_PASSWORD + valueFrom: + credentialVarRef: + name: kbadmin + password: Required + - name: MYSQL_REPLICATION_USER + valueFrom: + credentialVarRef: + name: kbreplicator + username: Required + - name: MYSQL_REPLICATION_PASSWORD + valueFrom: + credentialVarRef: + name: kbreplicator + password: Required lifecycleActions: accountProvision: exec: container: mysql - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.33 command: - - /bin/sh + - bash - -c - | set -ex + ALL_DB='*.*' eval statement=\"${KB_ACCOUNT_STATEMENT}\" mysql -u${MYSQL_ROOT_USER} -p${MYSQL_ROOT_PASSWORD} -P3306 -h127.0.0.1 -e "${statement}" targetPodSelector: Role matchingKey: primary - roleProbe: periodSeconds: {{ .Values.roleProbe.periodSeconds }} timeoutSeconds: {{ .Values.roleProbe.timeoutSeconds }} diff --git a/addons/mysql/templates/_names.tpl b/addons/mysql/templates/_names.tpl index d8b94ca08..2fdcbeb8a 100644 --- a/addons/mysql/templates/_names.tpl +++ b/addons/mysql/templates/_names.tpl @@ -12,6 +12,10 @@ Define mysql orc component definition name prefix {{ include "mysql.cmpdNamePrefix" . }}-orc {{- end -}} +{{- define "mysql.cmpdMGRNamePrefix" -}} +{{ include "mysql.cmpdNamePrefix" . }}-mgr +{{- end -}} + {{/* Define mysql component definition regex regular */}} @@ -54,6 +58,10 @@ Define mysql component definition name {{- printf "%s-8.0-%s" (include "mysql.cmpdOrcNamePrefix" .) .Chart.Version -}} {{- end -}} +{{- define "mysql.componentDefNameMGR80" -}} +{{- printf "%s-8.0-%s" (include "mysql.cmpdMGRNamePrefix" .) .Chart.Version -}} +{{- end -}} + {{/* Define mysql component definition name */}} @@ -61,6 +69,10 @@ Define mysql component definition name {{- printf "%s-8.4-%s" (include "mysql.cmpdNamePrefix" .) .Chart.Version -}} {{- end -}} +{{- define "mysql.componentDefNameMGR84" -}} +{{- printf "%s-8.4-%s" (include "mysql.cmpdMGRNamePrefix" .) .Chart.Version -}} +{{- end -}} + {{/* Define mysql component definition name */}} diff --git a/addons/mysql/templates/clusterdefinition.yaml b/addons/mysql/templates/clusterdefinition.yaml index 7a50cfe96..bcd2a33ca 100644 --- a/addons/mysql/templates/clusterdefinition.yaml +++ b/addons/mysql/templates/clusterdefinition.yaml @@ -13,6 +13,10 @@ spec: - name: mysql compDef: {{ include "mysql.componentDefRegex" . }} default: true + - name: mgr + components: + - name: mysql + compDef: {{ include "mysql.cmpdMGRNamePrefix" . }} - name: orc components: - name: mysql diff --git a/addons/mysql/templates/cmpd-mysql80-mgr.yaml b/addons/mysql/templates/cmpd-mysql80-mgr.yaml new file mode 100644 index 000000000..69d45a3d8 --- /dev/null +++ b/addons/mysql/templates/cmpd-mysql80-mgr.yaml @@ -0,0 +1,120 @@ +apiVersion: apps.kubeblocks.io/v1 +kind: ComponentDefinition +metadata: + name: {{ include "mysql.componentDefNameMGR80" . }} + labels: + {{- include "mysql.labels" . | nindent 4 }} + annotations: + {{- include "mysql.annotations" . | nindent 4 }} +spec: + {{- include "mysql.spec.common" . | nindent 2 }} + serviceVersion: 8.0.33 + configs: + - name: mysql-replication-config + templateRef: mysql-8.0-mgr-config-template + constraintRef: mysql-8.0-config-constraints + volumeName: mysql-config + namespace: {{ .Release.Namespace }} + reRenderResourceTypes: + - vscale + runtime: + initContainers: + - image: {{ .Values.image.registry | default "docker.io" }}/apecloud/mysql_audit_log:8.0.33 + name: init-data + command: + - bash + - -c + - | + mkdir -p {{ .Values.dataMountPath }}/{log,binlog,auditlog} + cp /usr/lib/mysql/plugin/ {{ .Values.dataMountPath }}/plugin -r + imagePullPolicy: {{ default .Values.image.pullPolicy "IfNotPresent" }} + volumeMounts: + - mountPath: {{ .Values.dataMountPath }} + name: data + - command: + - cp + - -r + - /jemalloc/lib/ + - /tools/lib + image: {{ .Values.image.registry | default "docker.io" }}/apecloud/jemalloc:5.3.0 + imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} + name: init-jemalloc + volumeMounts: + - mountPath: /tools + name: tools + {{- include "mysql.spec.runtime.common" . | nindent 6 }} + containers: + - name: mysql + image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.33 + imagePullPolicy: {{ default .Values.image.pullPolicy "IfNotPresent" }} + command: + - syncer + - --port + - "3601" + - -- + - bash + - -c + - | + cp {{ .Values.dataMountPath }}/plugin/audit_log.so /usr/lib64/mysql/plugin/ + chown -R mysql:root {{ .Values.dataMountPath }} + SERVICE_ID=$((${POD_NAME##*-} + 1)) + docker-entrypoint.sh mysqld --server-id $SERVICE_ID \ + --report-host ${POD_NAME}.${CLUSTER_COMPONENT_NAME}-headless \ + --plugin-load-add=rpl_semi_sync_source=semisync_source.so \ + --plugin-load-add=rpl_semi_sync_replica=semisync_replica.so \ + --plugin-load-add=audit_log=audit_log.so \ + --log-bin=/var/lib/mysql/binlog/${POD_NAME}-bin \ + --skip-slave-start=ON + volumeMounts: + - mountPath: {{ .Values.dataMountPath }} + name: data + - mountPath: /etc/mysql/conf.d + name: mysql-config + - name: scripts + mountPath: /scripts + - mountPath: /tools + name: tools + ports: + - containerPort: 3306 + name: mysql + - containerPort: 3601 + name: ha + - containerPort: 33061 + name: mgr + env: + - name: PATH + value: /tools/xtrabackup/bin:/tools/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + - name: LD_PRELOAD + value: /tools/lib/libjemalloc.so.2 + - name: KB_ENGINE_TYPE + value: mysql + - name: KB_WORKLOAD_TYPE + value: mgr + - name: MYSQL_INITDB_SKIP_TZINFO + value: "1" + - name: MYSQL_ROOT_HOST + value: {{ .Values.auth.rootHost | default "%" | quote }} + - name: SERVICE_PORT + value: "3306" + - name: POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: POD_NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + - name: POD_UID + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.uid + - name: POD_IP + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: status.podIP + - name: mysql-exporter + {{- include "mysql.spec.runtime.exporter" . | nindent 8 }} diff --git a/addons/mysql/templates/cmpd-mysql84-mgr.yaml b/addons/mysql/templates/cmpd-mysql84-mgr.yaml new file mode 100644 index 000000000..152bf6814 --- /dev/null +++ b/addons/mysql/templates/cmpd-mysql84-mgr.yaml @@ -0,0 +1,108 @@ +apiVersion: apps.kubeblocks.io/v1 +kind: ComponentDefinition +metadata: + name: {{ include "mysql.componentDefNameMGR84" . }} + labels: + {{- include "mysql.labels" . | nindent 4 }} + annotations: + {{- include "mysql.annotations" . | nindent 4 }} +spec: + {{- include "mysql.spec.common" . | nindent 2 }} + serviceVersion: 8.4.2 + configs: + - name: mysql-replication-config + templateRef: mysql-8.0-mgr-config-template + constraintRef: mysql-8.0-config-constraints + volumeName: mysql-config + namespace: {{ .Release.Namespace }} + reRenderResourceTypes: + - vscale + runtime: + initContainers: + - command: + - cp + - -r + - /jemalloc/lib/ + - /tools/lib + image: {{ .Values.image.registry | default "docker.io" }}/apecloud/jemalloc:5.3.0 + imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} + name: init-jemalloc + volumeMounts: + - mountPath: /tools + name: tools + {{- include "mysql.spec.runtime.common" . | nindent 6 }} + containers: + - name: mysql + image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.4.2 + imagePullPolicy: {{ default .Values.image.pullPolicy "IfNotPresent" }} + command: + - syncer + - --port + - "3601" + - -- + - bash + - -c + - | + mkdir -p {{ .Values.dataMountPath }}/{log,binlog,auditlog} + chown -R mysql:root {{ .Values.dataMountPath }} + export LD_PRELOAD=/tools/lib/libjemalloc.so.2 + SERVICE_ID=$((${POD_NAME##*-} + 1)) + docker-entrypoint.sh mysqld --server-id $SERVICE_ID \ + --report-host ${POD_NAME}.${CLUSTER_COMPONENT_NAME}-headless \ + --plugin-load-add=rpl_semi_sync_source=semisync_source.so \ + --plugin-load-add=rpl_semi_sync_replica=semisync_replica.so \ + --log-bin=/var/lib/mysql/binlog/${POD_NAME}-bin \ + --skip-slave-start=ON + volumeMounts: + - mountPath: {{ .Values.dataMountPath }} + name: data + - mountPath: /etc/mysql/conf.d + name: mysql-config + - name: scripts + mountPath: /scripts + - mountPath: /tools + name: tools + ports: + - containerPort: 3306 + name: mysql + - containerPort: 3601 + name: ha + - containerPort: 33061 + name: mgr + env: + - name: PATH + value: /tools/xtrabackup/bin:/tools/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + - name: LD_PRELOAD + value: /tools/lib/libjemalloc.so.2 + - name: KB_ENGINE_TYPE + value: mysql + - name: KB_WORKLOAD_TYPE + value: mgr + - name: MYSQL_INITDB_SKIP_TZINFO + value: "1" + - name: MYSQL_ROOT_HOST + value: {{ .Values.auth.rootHost | default "%" | quote }} + - name: SERVICE_PORT + value: "3306" + - name: POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: POD_NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + - name: POD_UID + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.uid + - name: POD_IP + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: status.podIP + - name: mysql-exporter + {{- include "mysql.spec.runtime.exporter" . | nindent 8 }} diff --git a/addons/mysql/templates/config-templates.yaml b/addons/mysql/templates/config-templates.yaml index 2135ccf52..d0047809f 100644 --- a/addons/mysql/templates/config-templates.yaml +++ b/addons/mysql/templates/config-templates.yaml @@ -18,3 +18,15 @@ metadata: data: my.cnf: |- {{- .Files.Get "config/mysql8.0-config.tpl" | nindent 4 }} + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: mysql-8.0-mgr-config-template + labels: + {{- include "mysql.labels" . | nindent 4 }} +data: + my.cnf: |- + {{- .Files.Get "config/mysql8.0-config.tpl" | nindent 4 }} + {{- .Files.Get "config/mysql-group-replication.tpl" | nindent 4 }} diff --git a/addons/mysql/templates/cpmv-mgr.yaml b/addons/mysql/templates/cpmv-mgr.yaml new file mode 100644 index 000000000..cd1c12da0 --- /dev/null +++ b/addons/mysql/templates/cpmv-mgr.yaml @@ -0,0 +1,134 @@ +apiVersion: apps.kubeblocks.io/v1 +kind: ComponentVersion +metadata: + name: mysql-mgr + labels: + {{- include "mysql.labels" . | nindent 4 }} + annotations: + {{- include "mysql.apiVersion" . | nindent 4 }} +spec: + compatibilityRules: + - compDefs: + - {{ include "mysql.componentDefNameMGR80" . }} + releases: + - 8.0.30 + - 8.0.31 + - 8.0.32 + - 8.0.33 + - 8.0.34 + - 8.0.35 + - 8.0.36 + - 8.0.37 + - 8.0.38 + - 8.0.39 + - compDefs: + - {{ include "mysql.componentDefName84" . }} + releases: + - 8.4.0 + - 8.4.1 + - 8.4.2 + releases: + - name: 8.0.30 + changes: + serviceVersion: 8.0.30 + images: + mysql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.30 + accountProvision: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.30 + init-data: {{ .Values.image.registry | default "docker.io" }}/apecloud/mysql_audit_log:8.0.33 + {{- include "mysql.spec.runtime.images" . | nindent 8 }} + - name: 8.0.31 + changes: + serviceVersion: 8.0.31 + images: + mysql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.31 + accountProvision: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.31 + init-data: {{ .Values.image.registry | default "docker.io" }}/apecloud/mysql_audit_log:8.0.33 + {{- include "mysql.spec.runtime.images" . | nindent 8 }} + - name: 8.0.32 + changes: + serviceVersion: 8.0.32 + images: + mysql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.32 + accountProvision: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.32 + init-data: {{ .Values.image.registry | default "docker.io" }}/apecloud/mysql_audit_log:8.0.33 + {{- include "mysql.spec.runtime.images" . | nindent 8 }} + - name: 8.0.33 + changes: + serviceVersion: 8.0.33 + images: + mysql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.33 + accountProvision: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.33 + init-data: {{ .Values.image.registry | default "docker.io" }}/apecloud/mysql_audit_log:8.0.33 + {{- include "mysql.spec.runtime.images" . | nindent 8 }} + - name: 8.0.34 + changes: + serviceVersion: 8.0.34 + images: + mysql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.34 + accountProvision: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.34 + init-data: {{ .Values.image.registry | default "docker.io" }}/apecloud/mysql_audit_log:8.0.33 + {{- include "mysql.spec.runtime.images" . | nindent 8 }} + - name: 8.0.35 + changes: + serviceVersion: 8.0.35 + images: + mysql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.35 + accountProvision: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.35 + init-data: {{ .Values.image.registry | default "docker.io" }}/apecloud/mysql_audit_log:8.0.33 + {{- include "mysql.spec.runtime.images" . | nindent 8 }} + - name: 8.0.36 + changes: + serviceVersion: 8.0.36 + images: + mysql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.36 + accountProvision: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.36 + init-data: {{ .Values.image.registry | default "docker.io" }}/apecloud/mysql_audit_log:8.0.33 + {{- include "mysql.spec.runtime.images" . | nindent 8 }} + - name: 8.0.37 + changes: + serviceVersion: 8.0.37 + images: + mysql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.37 + accountProvision: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.37 + init-data: {{ .Values.image.registry | default "docker.io" }}/apecloud/mysql_audit_log:8.0.33 + {{- include "mysql.spec.runtime.images" . | nindent 8 }} + - name: 8.0.38 + changes: + serviceVersion: 8.0.38 + images: + mysql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.38 + accountProvision: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.38 + init-data: {{ .Values.image.registry | default "docker.io" }}/apecloud/mysql_audit_log:8.0.33 + {{- include "mysql.spec.runtime.images" . | nindent 8 }} + - name: 8.0.39 + changes: + serviceVersion: 8.0.39 + images: + mysql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.39 + accountProvision: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.0.39 + init-data: {{ .Values.image.registry | default "docker.io" }}/apecloud/mysql_audit_log:8.0.33 + {{- include "mysql.spec.runtime.images" . | nindent 8 }} + - name: 8.4.0 + changes: + serviceVersion: 8.4.0 + images: + mysql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.4.0 + accountProvision: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.4.0 + init-xtrabackup: {{ .Values.image.registry | default "docker.io" }}/apecloud/xtrabackup:8.4 + {{- include "mysql.spec.runtime.images" . | nindent 8 }} + - name: 8.4.1 + changes: + serviceVersion: 8.4.1 + images: + mysql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.4.1 + accountProvision: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.4.1 + init-xtrabackup: {{ .Values.image.registry | default "docker.io" }}/apecloud/xtrabackup:8.4 + {{- include "mysql.spec.runtime.images" . | nindent 8 }} + - name: 8.4.2 + changes: + serviceVersion: 8.4.2 + images: + mysql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.4.2 + accountProvision: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:8.4.2 + init-xtrabackup: {{ .Values.image.registry | default "docker.io" }}/apecloud/xtrabackup:8.4 + {{- include "mysql.spec.runtime.images" . | nindent 8 }} \ No newline at end of file diff --git a/addons/mysql/values.yaml b/addons/mysql/values.yaml index 2858c2dba..04d2dc6b4 100644 --- a/addons/mysql/values.yaml +++ b/addons/mysql/values.yaml @@ -16,7 +16,7 @@ image: repository: apecloud/percona-xtrabackup syncer: repository: apecloud/syncer - tag: 0.4.1 + tag: 0.5.0 # refer: addons/mysql/orc-tools/Dockerfile orcTools: repository: apecloud/orc-tools diff --git a/examples/mysql/cluster-mgr.yaml b/examples/mysql/cluster-mgr.yaml new file mode 100644 index 000000000..3387f5f55 --- /dev/null +++ b/examples/mysql/cluster-mgr.yaml @@ -0,0 +1,60 @@ +apiVersion: apps.kubeblocks.io/v1 +kind: Cluster +metadata: + name: mysql-mgr-cluster + namespace: default +spec: + # Specifies the behavior when a Cluster is deleted. + # Valid options are: [DoNotTerminate, Delete, WipeOut] (`Halt` is deprecated since KB 0.9) + # - `DoNotTerminate`: Prevents deletion of the Cluster. This policy ensures that all resources remain intact. + # - `Delete`: Extends the `Halt` policy by also removing PVCs, leading to a thorough cleanup while removing all persistent data. + # - `WipeOut`: An aggressive policy that deletes all Cluster resources, including volume snapshots and backups in external storage. This results in complete data removal and should be used cautiously, primarily in non-production environments to avoid irreversible data loss. + terminationPolicy: Delete + # Specifies a list of ClusterComponentSpec objects used to define the + # individual Components that make up a Cluster. + # This field allows for detailed configuration of each Component within the Cluster + componentSpecs: + - name: mysql + # Specifies the ComponentDefinition custom resource (CR) that defines the + # Component's characteristics and behavior. + # Supports three different ways to specify the ComponentDefinition: + # - the regular expression - recommended + # - the full name - recommended + # - the name prefix + componentDef: "mysql-mgr-8.0" # match all CMPD named with 'mysql-mgr-8.0-' + # ServiceVersion specifies the version of the Service expected to be + # provisioned by this Component. + # When componentDef is "mysql-8.0", + # Valid options are: [8.0.30,8.0.31,8.0.32,8.0.33,8.0.34,8.0.35,8.0.36,8.0.37,8.0.38,8.0.39] + serviceVersion: 8.0.35 + # Determines whether metrics exporter information is annotated on the + # Component's headless Service. + # Valid options are [true, false] + disableExporter: false + # Specifies the desired number of replicas in the Component + replicas: 3 + # Specifies the resources required by the Component. + resources: + limits: + cpu: '0.5' + memory: 0.5Gi + requests: + cpu: '0.5' + memory: 0.5Gi + # Specifies a list of PersistentVolumeClaim templates that define the storage + # requirements for the Component. + volumeClaimTemplates: + # Refers to the name of a volumeMount defined in + # `componentDefinition.spec.runtime.containers[*].volumeMounts + - name: data + spec: + # The name of the StorageClass required by the claim. + # If not specified, the StorageClass annotated with + # `storageclass.kubernetes.io/is-default-class=true` will be used by default + storageClassName: "" + accessModes: + - ReadWriteOnce + resources: + requests: + # Set the storage size as needed + storage: 20Gi