Skip to content

Commit 631a385

Browse files
authored
chore(mysql):Re-implementing the cluster implementation (#31)
1 parent 155d616 commit 631a385

19 files changed

Lines changed: 89 additions & 127 deletions

File tree

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@ 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 }}
15-
app.kubernetes.io/component: mysql-cluster-tools
16-
15+
app.kubernetes.io/component: mysql-cluster-manager
1716
template:
1817
metadata:
1918
labels: {{- include "common.labels.standard" . | nindent 8 }}
20-
app.kubernetes.io/component: mysql-cluster-tools
21-
19+
app.kubernetes.io/component: mysql-cluster-manager
2220
spec:
21+
subdomain: {{ include "mysql.primary.fullname" . }}
22+
dnsConfig:
23+
searches:
24+
- {{ include "mysql.primary.fullname" . }}.{{ include "common.names.namespace" . }}.svc.cluster.local
25+
2326
containers:
24-
- name: cluster-tools
27+
- name: cluster-manager
2528
image: {{ include "cluster.image" . }}
2629
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
2730
command:
@@ -30,12 +33,14 @@ spec:
3033
- |
3134
sleep infinity
3235
env:
33-
- name: MYSQL_MASTER_PORT_NUMBER
36+
- name: MYSQL_HOST
37+
value: {{ include "mysql.primary.fullname" . }}
38+
- name: MYSQL_PORT_NUMBER
3439
value: {{ .Values.primary.service.ports.mysql | quote }}
35-
- name: MYSQL_MASTER_ROOT_USER
40+
- name: MYSQL_ROOT_USER
3641
value: "root"
3742
- name: MYSQL_ROOT_PASSWORD
3843
valueFrom:
3944
secretKeyRef:
4045
name: {{ template "mysql.secretName" . }}
41-
key: mysql-root-password
46+
key: mysql-root-password

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

Lines changed: 31 additions & 64 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,15 +52,32 @@ spec:
10252
- /bin/bash
10353
- -ec
10454
- |
105-
export HOST_0=${MYSQL_MASTER_HOST}-0.${MYSQL_MASTER_HOST}
106-
echo 'Y' | mysqlsh --uri=${MYSQL_MASTER_ROOT_USER}@${HOST_0}:${MYSQL_MASTER_PORT_NUMBER} -p${MYSQL_ROOT_PASSWORD} -e'var c=dba.createCluster("MXMGR");'
10755
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
10875
env:
109-
- name: MYSQL_MASTER_HOST
76+
- name: MYSQL_HOST
11077
value: {{ include "mysql.primary.fullname" . }}
111-
- name: MYSQL_MASTER_PORT_NUMBER
78+
- name: MYSQL_PORT_NUMBER
11279
value: {{ .Values.primary.service.ports.mysql | quote }}
113-
- name: MYSQL_MASTER_ROOT_USER
80+
- name: MYSQL_ROOT_USER
11481
value: "root"
11582
- name: MYSQL_ROOT_PASSWORD
11683
valueFrom:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ spec:
2626
- port: {{ .Values.router.service.portrw }}
2727
- port: {{ .Values.router.service.portro }}
2828
- port: 24901
29+
- port: 33061
2930
{{- if and .Values.metrics.enabled }}
3031
- port: {{ .Values.metrics.service.port }}
3132
{{ end }}

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: 7 additions & 15 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 }}
@@ -186,11 +190,7 @@ spec:
186190
- /bin/bash
187191
- -ec
188192
- |
189-
password_aux="${MYSQL_ROOT_PASSWORD:-}"
190-
if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
191-
password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
192-
fi
193-
mysqladmin status -uroot -h127.0.0.1 -P6446 -p"${password_aux}"
193+
mysqladmin ping -uroot -h127.0.0.1 -P6446 -p"${MYSQL_ROOT_PASSWORD}"
194194
{{- end }}
195195
{{- if .Values.router.customReadinessProbe }}
196196
readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.router.customReadinessProbe "context" $) | nindent 12 }}
@@ -201,11 +201,7 @@ spec:
201201
- /bin/bash
202202
- -ec
203203
- |
204-
password_aux="${MYSQL_ROOT_PASSWORD:-}"
205-
if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
206-
password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
207-
fi
208-
mysqladmin status -uroot -h127.0.0.1 -P6446 -p"${password_aux}"
204+
mysqladmin ping -uroot -h127.0.0.1 -P6446 -p"${MYSQL_ROOT_PASSWORD}"
209205
{{- end }}
210206
{{- if .Values.router.customStartupProbe }}
211207
startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.router.customStartupProbe "context" $) | nindent 12 }}
@@ -216,11 +212,7 @@ spec:
216212
- /bin/bash
217213
- -ec
218214
- |
219-
password_aux="${MYSQL_ROOT_PASSWORD:-}"
220-
if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
221-
password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
222-
fi
223-
mysqladmin status -uroot -h127.0.0.1 -P6446 -p"${password_aux}"
215+
mysqladmin ping -uroot -h127.0.0.1 -P6446 -p"${MYSQL_ROOT_PASSWORD}"
224216
{{- end }}
225217
{{- end }}
226218
{{- if .Values.router.resources }}

0 commit comments

Comments
 (0)