Skip to content

Commit 6c7dec7

Browse files
committed
chore(mysql): Re-implementing the cluster implementation
1 parent 3892256 commit 6c7dec7

12 files changed

Lines changed: 65 additions & 98 deletions

File tree

addons/mysql-cluster/8.0/chart/mysql-cluster/templates/cluster/deployments.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@ SPDX-License-Identifier: APACHE-2.0
66
apiVersion: apps/v1
77
kind: Deployment
88
metadata:
9-
name: {{ include "mysql.cluster.fullname" . }}-tools
9+
name: {{ include "mysql.cluster.fullname" . }}-manager
1010
namespace: {{ include "common.names.namespace" . | quote }}
1111
spec:
1212
replicas: 1
1313
selector:
1414
matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
1515
app.kubernetes.io/component: mysql-cluster-tools
16-
1716
template:
1817
metadata:
1918
labels: {{- include "common.labels.standard" . | nindent 8 }}
2019
app.kubernetes.io/component: mysql-cluster-tools
21-
2220
spec:
21+
subdomain: {{ include "mysql.primary.fullname" . }}
22+
dnsConfig:
23+
searches:
24+
- {{ include "mysql.primary.fullname" . }}.{{ include "common.names.namespace" . }}.svc.cluster.local
2325
containers:
2426
- name: cluster-tools
2527
image: {{ include "cluster.image" . }}
@@ -30,9 +32,11 @@ spec:
3032
- |
3133
sleep infinity
3234
env:
35+
- name: MYSQL_HOST
36+
value: {{ include "mysql.primary.fullname" . }}
3337
- name: MYSQL_MASTER_PORT_NUMBER
3438
value: {{ .Values.primary.service.ports.mysql | quote }}
35-
- name: MYSQL_MASTER_ROOT_USER
39+
- name: MYSQL_ROOT_USER
3640
value: "root"
3741
- name: MYSQL_ROOT_PASSWORD
3842
valueFrom:

addons/mysql-cluster/8.0/chart/mysql-cluster/templates/cluster/job.yaml

Lines changed: 31 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SPDX-License-Identifier: APACHE-2.0
66
apiVersion: {{ include "common.capabilities.cronjob.apiVersion" . }}
77
kind: Job
88
metadata:
9-
name: {{ include "mysql.cluster.fullname" . }}
9+
name: {{ include "mysql.cluster.fullname" . }}-init
1010
namespace: {{ include "common.names.namespace" . | quote }}
1111
labels: {{- include "common.labels.standard" . | nindent 4 }}
1212
app.kubernetes.io/component: primary
@@ -21,6 +21,10 @@ spec:
2121
template:
2222
spec:
2323
restartPolicy: Never
24+
subdomain: {{ include "mysql.primary.fullname" . }}
25+
dnsConfig:
26+
searches:
27+
- {{ include "mysql.primary.fullname" . }}.{{ include "common.names.namespace" . }}.svc.cluster.local
2428
initContainers:
2529
- name: init-wait
2630
image: registry.uucin.com/drycc/python-dev:latest
@@ -29,70 +33,16 @@ spec:
2933
- netcat
3034
- -v
3135
- -u
32-
- mysql://$(MYSQL_MASTER_HOST)-0.$(MYSQL_MASTER_HOST):$(MYSQL_MASTER_PORT_NUMBER),mysql://$(MYSQL_MASTER_HOST)-1.$(MYSQL_MASTER_HOST):$(MYSQL_MASTER_PORT_NUMBER),mysql://$(MYSQL_MASTER_HOST)-2.$(MYSQL_MASTER_HOST):$(MYSQL_MASTER_PORT_NUMBER)
36+
- mysql://$(MYSQL_HOST)-2:$(MYSQL_PORT_NUMBER)
3337

3438
env:
35-
- name: MYSQL_MASTER_HOST
39+
- name: MYSQL_HOST
3640
value: {{ include "mysql.primary.fullname" . }}
37-
- name: MYSQL_MASTER_PORT_NUMBER
41+
- name: MYSQL_PORT_NUMBER
3842
value: {{ .Values.primary.service.ports.mysql | quote }}
39-
40-
- name: mgr
41-
image: {{ include "mysql.image" . }}
42-
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
43-
{{- if .Values.primary.containerSecurityContext.enabled }}
44-
securityContext: {{- omit .Values.primary.containerSecurityContext "enabled" | toYaml | nindent 12 }}
45-
{{- end }}
46-
command:
47-
- /bin/bash
48-
- -ec
49-
- |
50-
export HOST_0=${MYSQL_MASTER_HOST}-0.${MYSQL_MASTER_HOST}
51-
export HOST_1=${MYSQL_MASTER_HOST}-1.${MYSQL_MASTER_HOST}
52-
export HOST_2=${MYSQL_MASTER_HOST}-2.${MYSQL_MASTER_HOST}
53-
54-
echo "
55-
set global group_replication_bootstrap_group=on;
56-
start group_replication;
57-
select * from performance_schema.replication_group_members;
58-
set global group_replication_bootstrap_group=off;
59-
" > /tmp/master.sql
60-
mysql -h${HOST_0} -P${MYSQL_MASTER_PORT_NUMBER} -uroot -p${MYSQL_ROOT_PASSWORD} < /tmp/master.sql
61-
62-
echo "
63-
reset master;
64-
change master to master_user='$(MYSQL_REPLICATION_USER)',master_password='$(MYSQL_REPLICATION_PASSWORD)' for channel 'group_replication_recovery';
65-
start group_replication;
66-
select * from performance_schema.replication_group_members;
67-
" > /tmp/slave.sql
68-
mysql -h${HOST_1} -P${MYSQL_MASTER_PORT_NUMBER} -uroot -p${MYSQL_ROOT_PASSWORD} < /tmp/slave.sql
69-
mysql -h${HOST_2} -P${MYSQL_MASTER_PORT_NUMBER} -uroot -p${MYSQL_ROOT_PASSWORD} < /tmp/slave.sql
70-
mysql -h${HOST_0} -P${MYSQL_MASTER_PORT_NUMBER} -uroot -p${MYSQL_ROOT_PASSWORD} -e "GRANT ALL PRIVILEGES ON *.* TO administrator@'%' WITH GRANT OPTION;flush privileges;"
71-
72-
env:
73-
- name: DRYCC_DEBUG
74-
value: {{ ternary "true" "false" (or .Values.image.debug .Values.diagnosticMode.enabled) | quote }}
75-
- name: MYSQL_MASTER_HOST
76-
value: {{ include "mysql.primary.fullname" . }}
77-
- name: MYSQL_MASTER_PORT_NUMBER
78-
value: {{ .Values.primary.service.ports.mysql | quote }}
79-
- name: MYSQL_MASTER_ROOT_USER
80-
value: "root"
81-
- name: MYSQL_ROOT_PASSWORD
82-
valueFrom:
83-
secretKeyRef:
84-
name: {{ template "mysql.secretName" . }}
85-
key: mysql-root-password
86-
- name: MYSQL_REPLICATION_USER
87-
value: {{ .Values.auth.replicationUser | quote }}
88-
- name: MYSQL_REPLICATION_PASSWORD
89-
valueFrom:
90-
secretKeyRef:
91-
name: {{ template "mysql.secretName" . }}
92-
key: mysql-replication-password
9343

9444
containers:
95-
- name: cluster
45+
- name: init-cluster
9646
image: {{ include "cluster.image" . }}
9747
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
9848
{{- if .Values.primary.containerSecurityContext.enabled }}
@@ -102,20 +52,32 @@ spec:
10252
- /bin/bash
10353
- -ec
10454
- |
105-
export HOST_0=${MYSQL_MASTER_HOST}-0.${MYSQL_MASTER_HOST}
106-
export HOST_1=${MYSQL_MASTER_HOST}-1.${MYSQL_MASTER_HOST}
107-
export HOST_2=${MYSQL_MASTER_HOST}-2.${MYSQL_MASTER_HOST}
10855
109-
echo 'Y' | mysqlsh --uri=${MYSQL_MASTER_ROOT_USER}@${HOST_0}:${MYSQL_MASTER_PORT_NUMBER} -p${MYSQL_ROOT_PASSWORD} -e'var c=dba.createCluster("MXMGR");'
110-
mysql -h${HOST_0} -P${MYSQL_MASTER_PORT_NUMBER} -uroot -p${MYSQL_ROOT_PASSWORD} -e "select @group_replication_group_name:= attributes -> '$.group_replication_group_name' from mysql_innodb_cluster_metadata.clusters; SET @sql = CONCAT('SET GLOBAL group_replication_group_name = "', @group_replication_group_name, '"');";
111-
mysql -h${HOST_1} -P${MYSQL_MASTER_PORT_NUMBER} -uroot -p${MYSQL_ROOT_PASSWORD} -e "select @group_replication_group_name:= attributes -> '$.group_replication_group_name' from mysql_innodb_cluster_metadata.clusters; SET @sql = CONCAT('SET GLOBAL group_replication_group_name = "', @group_replication_group_name, '"');";
112-
mysql -h${HOST_2} -P${MYSQL_MASTER_PORT_NUMBER} -uroot -p${MYSQL_ROOT_PASSWORD} -e "select @group_replication_group_name:= attributes -> '$.group_replication_group_name' from mysql_innodb_cluster_metadata.clusters; SET @sql = CONCAT('SET GLOBAL group_replication_group_name = "', @group_replication_group_name, '"');";
56+
export HOST_0=${MYSQL_HOST}-0
57+
export HOST_1=${MYSQL_HOST}-1
58+
export HOST_2=${MYSQL_HOST}-2
59+
60+
# create mysql cluster --file
61+
echo "
62+
shell.options['dba.restartWaitTimeout']=300;
63+
dba.createCluster('MXMGR',{disableClone:false});
64+
dba.getCluster().addInstance('root@${HOST_1}',{recoveryMethod:'clone'});
65+
dba.getCluster().addInstance('root@${HOST_2}',{recoveryMethod:'clone'});
66+
dba.getCluster().status();
67+
" > /tmp/create_cluster.js
68+
mysqlsh --uri=${MYSQL_ROOT_USER}@${HOST_0}:${MYSQL_PORT_NUMBER} -p${MYSQL_ROOT_PASSWORD} -f /tmp/create_cluster.js
69+
70+
# init sql --sql
71+
echo "
72+
GRANT ALL PRIVILEGES ON *.* TO administrator@'%' WITH GRANT OPTION;flush privileges;
73+
" > /tmp/init.sql
74+
mysqlsh --uri=${MYSQL_ROOT_USER}@${HOST_0}:${MYSQL_PORT_NUMBER} -p${MYSQL_ROOT_PASSWORD} --sql -f /tmp/init.sql
11375
env:
114-
- name: MYSQL_MASTER_HOST
76+
- name: MYSQL_HOST
11577
value: {{ include "mysql.primary.fullname" . }}
116-
- name: MYSQL_MASTER_PORT_NUMBER
78+
- name: MYSQL_PORT_NUMBER
11779
value: {{ .Values.primary.service.ports.mysql | quote }}
118-
- name: MYSQL_MASTER_ROOT_USER
80+
- name: MYSQL_ROOT_USER
11981
value: "root"
12082
- name: MYSQL_ROOT_PASSWORD
12183
valueFrom:

addons/mysql-cluster/8.0/chart/mysql-cluster/templates/primary/statefulset.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ spec:
4646
{{- if .Values.primary.hostAliases }}
4747
hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.primary.hostAliases "context" $) | nindent 8 }}
4848
{{- end }}
49+
subdomain: {{ include "mysql.primary.fullname" . }}
50+
dnsConfig:
51+
searches:
52+
- {{ include "mysql.primary.fullname" . }}.{{ include "common.names.namespace" . }}.svc.cluster.local
4953
{{- if .Values.primary.affinity }}
5054
affinity: {{- include "common.tplvalues.render" (dict "value" .Values.primary.affinity "context" $) | nindent 8 }}
5155
{{- else }}
@@ -214,7 +218,7 @@ spec:
214218
if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
215219
password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
216220
fi
217-
mysqladmin status -uroot -h127.0.0.1 -p"${password_aux}"
221+
mysqladmin ping -uroot -h127.0.0.1 -p"${password_aux}"
218222
{{- end }}
219223
{{- if .Values.primary.customReadinessProbe }}
220224
readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.primary.customReadinessProbe "context" $) | nindent 12 }}
@@ -229,7 +233,7 @@ spec:
229233
if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
230234
password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
231235
fi
232-
mysqladmin status -uroot -h127.0.0.1 -p"${password_aux}"
236+
mysqladmin ping -uroot -h127.0.0.1 -p"${password_aux}"
233237
{{- end }}
234238
{{- if .Values.primary.customStartupProbe }}
235239
startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.primary.customStartupProbe "context" $) | nindent 12 }}
@@ -244,7 +248,7 @@ spec:
244248
if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
245249
password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
246250
fi
247-
mysqladmin status -uroot -h127.0.0.1 -p"${password_aux}"
251+
mysqladmin ping -uroot -h127.0.0.1 -p"${password_aux}"
248252
{{- end }}
249253
{{- end }}
250254
{{- if .Values.primary.resources }}

addons/mysql-cluster/8.0/chart/mysql-cluster/templates/router/statefulset.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ spec:
4343
{{- if .Values.router.hostAliases }}
4444
hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.router.hostAliases "context" $) | nindent 8 }}
4545
{{- end }}
46+
subdomain: {{ include "mysql.primary.fullname" . }}
47+
dnsConfig:
48+
searches:
49+
- {{ include "mysql.primary.fullname" . }}.{{ include "common.names.namespace" . }}.svc.cluster.local
4650
{{- if .Values.router.affinity }}
4751
affinity: {{- include "common.tplvalues.render" (dict "value" .Values.router.affinity "context" $) | nindent 8 }}
4852
{{- else }}

addons/mysql-cluster/8.0/chart/mysql-cluster/values.yaml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ initdbScripts:
176176
# Add an offset to avoid reserved server-id=0 value.
177177
echo server-id=$((100 + $ordinal)) >> $base_conf_file
178178
# Copy appropriate conf.d files from config-map to emptyDir.
179-
echo loose-group_replication_local_address=$mgr_host.$svc_mgr_host:24901 >> $base_conf_file
180-
echo report_host=$mgr_host.$svc_mgr_host >> $base_conf_file
181-
echo loose-group_replication_group_seeds="$svc_mgr_host-0.$svc_mgr_host:24901,$svc_mgr_host-1.$svc_mgr_host:24901,$svc_mgr_host-2.$svc_mgr_host:24901" >> $base_conf_file
179+
echo loose-group_replication_local_address=$mgr_host:24901 >> $base_conf_file
180+
echo report_host=$mgr_host >> $base_conf_file
181+
echo loose-group_replication_group_seeds="$svc_mgr_host-0:24901,$svc_mgr_host-1:24901,$svc_mgr_host-2:24901" >> $base_conf_file
182182
183183
echo plugin_load_add='group_replication.so' >> $base_conf_file
184184
@@ -204,7 +204,7 @@ primary:
204204
##
205205
args: []
206206
## @param primary.lifecycleHooks for the MySQL Primary container(s) to automate configuration before or after startup
207-
##
207+
##configuration
208208
lifecycleHooks: {}
209209
## @param primary.hostAliases Deployment pod host aliases
210210
## https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/
@@ -259,18 +259,11 @@ primary:
259259
260260
# Multi-threaded Replication
261261
replica_preserve_commit_order=ON
262-
replica_parallel_workers=4
262+
replica_parallel_workers=8
263+
replica_parallel_type=LOGICAL_CLOCK
263264
264265
# Group Replication Settings
265-
#plugin_load_add="group_replication.so"
266-
loose-group_replication_recovery_get_public_key=ON
267-
loose-group_replication_recovery_use_ssl=on
268-
loose-group_replication_group_name="{{uuidv4}}"
269-
loose-group_replication_ip_allowlist="0.0.0.0/0"
270-
271-
loose-group_replication_bootstrap_group=OFF
272-
loose-group_replication_start_on_boot=OFF
273-
266+
274267
[client]
275268
port=3306
276269
socket=/opt/drycc/mysql/tmp/mysql.sock
@@ -689,7 +682,7 @@ router:
689682
## @param secondary.podManagementPolicy podManagementPolicy to manage scaling operation of MySQL secondary pods
690683
## ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#pod-management-policies
691684
##
692-
podManagementPolicy: ""
685+
podManagementPolicy: "Parallel"
693686
## MySQL secondary Pod security context
694687
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod
695688
## @param secondary.podSecurityContext.enabled Enable security context for MySQL secondary pods

addons/mysql-cluster/8.0/plans/standard-10/bind.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ credential:
33
- name: EXTRANET_HOST
44
valueFrom:
55
serviceRef:
6-
name: {{ include "common.names.fullname" . }}
6+
name: {{ include "common.names.fullname" . }}-router
77
jsonpath: '{ .status.loadBalancer.ingress[*].ip }'
88
{{- end }}
99
- name: HOST

addons/mysql-cluster/8.0/plans/standard-100/bind.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ credential:
33
- name: EXTRANET_HOST
44
valueFrom:
55
serviceRef:
6-
name: {{ include "common.names.fullname" . }}
6+
name: {{ include "common.names.fullname" . }}-router
77
jsonpath: '{ .status.loadBalancer.ingress[*].ip }'
88
{{- end }}
99
- name: HOST

addons/mysql-cluster/8.0/plans/standard-20/bind.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ credential:
33
- name: EXTRANET_HOST
44
valueFrom:
55
serviceRef:
6-
name: {{ include "common.names.fullname" . }}
6+
name: {{ include "common.names.fullname" . }}-router
77
jsonpath: '{ .status.loadBalancer.ingress[*].ip }'
88
{{- end }}
99
- name: HOST

addons/mysql-cluster/8.0/plans/standard-200/bind.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ credential:
33
- name: EXTRANET_HOST
44
valueFrom:
55
serviceRef:
6-
name: {{ include "common.names.fullname" . }}
6+
name: {{ include "common.names.fullname" . }}-router
77
jsonpath: '{ .status.loadBalancer.ingress[*].ip }'
88
{{- end }}
99
- name: HOST

addons/mysql-cluster/8.0/plans/standard-400/bind.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ credential:
33
- name: EXTRANET_HOST
44
valueFrom:
55
serviceRef:
6-
name: {{ include "common.names.fullname" . }}
6+
name: {{ include "common.names.fullname" . }}-router
77
jsonpath: '{ .status.loadBalancer.ingress[*].ip }'
88
{{- end }}
99
- name: HOST

0 commit comments

Comments
 (0)