Skip to content

Commit c654a2a

Browse files
authored
chart: Support the use of Helm to install MySQL cluster (#519)
feat(chart): Support the use of Helm to install MySQL cluster add a subchart `mysqlcluster` uses: helm install demo charts/mysql-operator --set mysqlcluster.install=true fix: #516
1 parent 5369cbc commit c654a2a

File tree

11 files changed

+367
-10
lines changed

11 files changed

+367
-10
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: mysqlcluster
3+
description: A Helm chart for installing radondb mysql cluster.
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 2.2.1
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "v2.2.1"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Welcome to RadonDB MySQL Kubernetes!
2+
3+
Connect to the database:
4+
5+
kubectl exec -it svc/{{ .Values.name }}-leader -c mysql -- mysql -u{{ .Values.superUser.name }} -p{{ .Values.superUser.password }}
6+
7+
Change password:
8+
9+
kubectl patch secret {{ .Values.name }}-user-password --patch="{\"data\": { \"{{ .Values.superUser.name }}\": \"$(echo -n <yourpass> |base64 -w0)\" }}" -oyaml
10+
11+
Github: https://github.com/radondb/radondb-mysql-kubernetes
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{{- define "cluster.name" -}}
2+
{{- default .Release.Name .Values.name }}
3+
{{- end }}
4+
5+
{{- define "images.sidecar" -}}
6+
{{ ternary (printf "radondb/mysql80-sidecar:%s" .Values.version ) (printf "radondb/mysql57-sidecar:%s" .Values.version ) (eq .Values.mysqlVersion "8.0") }}
7+
{{- end }}
8+
9+
{{- define "user.secret.name" -}}
10+
{{ "sample-user-password" }}
11+
{{- end }}
12+
13+
{{- define "user.cr.name" -}}
14+
{{ printf "%s-%s-%s" ( include "cluster.name" . ) .Release.Namespace (.Values.superUser.name | replace "_" "-") }}
15+
{{- end }}
16+
17+
{{- define "schedule.disable" }}
18+
{{- and (not .Values.schedule.podAntiaffinity) (not .Values.schedule.nodeSelector) }}
19+
{{- end }}
20+
21+
{{- define "tls.server.secret" -}}
22+
{{ printf "%s-%s-%s" ( include "cluster.name" . ) .Release.Namespace "tls-server" }}
23+
{{- end }}
24+
25+
{{- define "tls.client.secret" -}}
26+
{{ printf "%s-%s-%s" ( include "cluster.name" . ) .Release.Namespace "tls-client" }}
27+
{{- end }}
28+
29+
{{- define "cluster.tls.secret.name" -}}
30+
{{- if (and .Values.tls.enable (empty .Values.tls.secretName)) -}}
31+
{{ include "tls.server.secret" . }}
32+
{{- else -}}
33+
{{ .Values.tls.secretName }}
34+
{{- end }}
35+
{{- end }}
36+
37+
{{/*
38+
Create chart name and version as used by the chart label.
39+
*/}}
40+
{{- define "mysql-cluster.chart" -}}
41+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
42+
{{- end }}
43+
44+
{{/*
45+
Common labels
46+
*/}}
47+
{{- define "mysql-cluster.labels" }}
48+
app.kubernetes.io/name: {{ include "cluster.name" . }}
49+
helm.sh/chart: {{ include "mysql-cluster.chart" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- if .Chart.AppVersion }}
52+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
53+
{{- end }}
54+
app.kubernetes.io/managed-by: {{ .Release.Service }}
55+
{{- end }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## CA
2+
{{- define "tls.ca" -}}
3+
{{- /* Generate ca with CN "radondb-ca" and 5 years validity duration if not exists in the current scope.*/ -}}
4+
{{- $caKeypair := genCA "radondb-ca" 1825 -}}
5+
{{- $_ := set . "selfSignedCAKeypair" $caKeypair -}}
6+
{{- $caKeypair.Cert -}}
7+
{{- end -}}
8+
## Server
9+
{{- define "server.certPEM" -}}
10+
{{- $CA := required "self-signed CA keypair is requried" .selfSignedCAKeypair -}}
11+
{{- /* genSignedCert <CN> <IP> <DNS> <Validity duration> <CA> */ -}}
12+
{{- $ServerTLSKeypair := genSignedCert "radondb-mysql-server" nil nil 1825 $CA -}}
13+
{{- $_ := set . "serverTLSKeypair" $ServerTLSKeypair -}}
14+
{{- $ServerTLSKeypair.Cert -}}
15+
{{- end -}}
16+
{{- define "server.keyPEM" -}}
17+
{{- .serverTLSKeypair.Key -}}
18+
{{- end -}}
19+
## Client
20+
{{- define "client.certPEM" -}}
21+
{{- $CA := required "self-signed CA keypair is requried" .selfSignedCAKeypair -}}
22+
{{- /* genSignedCert <CN> <IP> <DNS> <Validity duration> <CA> */ -}}
23+
{{- $ClientTLSKeypair := genSignedCert "radondb-mysql-client" nil nil 1825 $CA -}}
24+
{{- $_ := set . "clientTLSKeypair" $ClientTLSKeypair -}}
25+
{{- $ClientTLSKeypair.Cert -}}
26+
{{- end -}}
27+
{{- define "client.keyPEM" -}}
28+
{{- .clientTLSKeypair.Key -}}
29+
{{- end -}}
30+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{{- if .Values.install }}
2+
{{- $scheduleDisable := include "schedule.disable" . }}
3+
apiVersion: mysql.radondb.com/v1alpha1
4+
kind: MysqlCluster
5+
metadata:
6+
name: {{ template "cluster.name" . }}
7+
annotations:
8+
"helm.sh/resource-policy": keep
9+
spec:
10+
replicas: {{ .Values.replicas }}
11+
mysqlVersion: {{ ternary "8.0" "5.7" (eq .Values.mysqlVersion "8.0") | quote }}
12+
tlsSecretName: {{ include "cluster.tls.secret.name" . }}
13+
14+
mysqlOpts:
15+
{{- with .Values.mycnf }}
16+
mysqlConf:
17+
{{ toYaml . | indent 6 }}
18+
{{- end }}
19+
20+
resources:
21+
limits:
22+
cpu: {{ .Values.mysqlResources.limits.cpu }}
23+
memory: {{ .Values.mysqlResources.limits.memory }}
24+
requests:
25+
cpu: {{ .Values.mysqlResources.requests.cpu }}
26+
memory: {{ .Values.mysqlResources.requests.memory }}
27+
28+
metricsOpts:
29+
enabled: {{ .Values.sidecar.metrics }}
30+
31+
podPolicy:
32+
sidecarImage: {{ template "images.sidecar" . }}
33+
34+
slowLogTail: {{ .Values.sidecar.slowLogTail }}
35+
auditLogTail: {{ .Values.sidecar.auditLogTail }}
36+
37+
labels: {}
38+
annotations: {}
39+
{{- if $scheduleDisable }}
40+
affinity: {}
41+
{{- else }}
42+
affinity:
43+
{{- if .Values.schedule.podAntiaffinity }}
44+
podAntiAffinity:
45+
requiredDuringSchedulingIgnoredDuringExecution:
46+
- labelSelector:
47+
matchExpressions:
48+
- key: mysql.radondb.com/cluster
49+
operator: In
50+
values:
51+
- {{ .Values.mysqlCluster.name }}
52+
topologyKey: "kubernetes.io/hostname"
53+
{{- if .Values.schedule.nodeSelector }}
54+
nodeSelector:
55+
{{- range $k, $v := .Values.schedule.nodeSelector }}
56+
{{ $k }}: {{ $v }}
57+
{{- end }}
58+
{{- end }}
59+
{{- end }}
60+
{{- end }}
61+
62+
priorityClassName: ""
63+
tolerations: {{ .Values.schedule.tolerations }}
64+
schedulerName: ""
65+
66+
persistence:
67+
enabled: true
68+
accessModes:
69+
- ReadWriteOnce
70+
{{- if .Values.persistence.storageClass }}
71+
storageClass: {{ .Values.persistence.storageClass }}
72+
{{- end }}
73+
size: {{ .Values.persistence.size }}
74+
{{- end }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{- if .Values.install }}
2+
{{- if .Values.superUser.create }}
3+
apiVersion: v1
4+
kind: Secret
5+
metadata:
6+
name: {{ template "user.secret.name" . }}
7+
data:
8+
{{ .Values.superUser.name }}: {{ .Values.superUser.password | b64enc }}
9+
---
10+
apiVersion: mysql.radondb.com/v1alpha1
11+
kind: MysqlUser
12+
metadata:
13+
name: {{ template "user.cr.name" . }}
14+
spec:
15+
user: {{ .Values.superUser.name }}
16+
withGrantOption: true
17+
tlsOptions:
18+
type: {{ .Values.superUser.tlsType }}
19+
hosts:
20+
- "%"
21+
permissions:
22+
- database: "*"
23+
tables:
24+
- "*"
25+
privileges:
26+
- ALL
27+
userOwner:
28+
clusterName: {{ template "cluster.name" . }}
29+
nameSpace: {{ .Values.namespace }}
30+
secretSelector:
31+
secretName: {{ template "user.secret.name" . }}
32+
secretKey: {{ .Values.superUser.name }}
33+
{{- end }}
34+
{{- end }}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{{- if (and .Values.tls.enable (empty .Values.tls.secretName)) -}}
2+
3+
{{- $caCertPEM := include "tls.ca" . -}}
4+
{{- $serverCertPEM := include "server.certPEM" . -}}
5+
{{- $serverKeyPEM := include "server.keyPEM" . -}}
6+
{{- $clientCertPEM := include "client.certPEM" . -}}
7+
{{- $clientKeyPEM := include "client.keyPEM" . -}}
8+
9+
kind: Secret
10+
apiVersion: v1
11+
metadata:
12+
name: {{ template "tls.server.secret" . }}
13+
namespace: {{ .Release.Namespace | quote }}
14+
labels:
15+
{{- include "mysql-cluster.labels" . | nindent 4 }}
16+
app.kubernetes.io/component: mysql-tls-secret
17+
type: Opaque
18+
data:
19+
ca.crt: {{ b64enc $caCertPEM }}
20+
tls.crt: {{ b64enc $serverCertPEM }}
21+
tls.key: {{ b64enc $serverKeyPEM }}
22+
23+
---
24+
25+
kind: Secret
26+
apiVersion: v1
27+
metadata:
28+
name: {{ template "tls.client.secret" . }}
29+
namespace: {{ .Release.Namespace | quote }}
30+
labels:
31+
{{- include "mysql-cluster.labels" . | nindent 4 }}
32+
app.kubernetes.io/component: mysql-tls-secret
33+
type: Opaque
34+
data:
35+
ca.crt: {{ b64enc $caCertPEM }}
36+
tls.crt: {{ b64enc $clientCertPEM }}
37+
tls.key: {{ b64enc $clientKeyPEM }}
38+
39+
{{- end }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
install: true
2+
3+
replicas: 3
4+
5+
name: "sample"
6+
namespace: "default"
7+
8+
mysqlVersion: "8.0"
9+
version: v2.2.1
10+
11+
tls:
12+
enable: false
13+
secretName: ""
14+
15+
sidecar:
16+
metrics: false
17+
slowLogTail: false
18+
auditLogTail: false
19+
20+
schedule:
21+
podAntiaffinity: true
22+
nodeSelector: {}
23+
tolerations: []
24+
25+
persistence:
26+
storageClass: ""
27+
size: 20Gi
28+
29+
mysqlResources:
30+
limits:
31+
cpu: 256m
32+
memory: 500Mi
33+
requests:
34+
cpu: 256m
35+
memory: 500Mi
36+
37+
mycnf: {}
38+
39+
superUser:
40+
create: true
41+
name: "super_usr"
42+
password: "RadonDB@123"
43+
tlsType: NONE
Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1-
You can create a new mysqlcluster by issuing:
2-
3-
cat <<EOF | kubectl apply -f-
4-
apiVersion: mysql.radondb.com/v1alpha1
5-
kind: MysqlCluster
6-
metadata:
7-
name: sample
8-
spec:
9-
replicas: 3
10-
EOF
1+
Welcome to RadonDB MySQL Kubernetes!
2+
3+
{{- if .Values.mysqlcluster.install }}
4+
5+
Create MySQLCluster:
6+
{{- else }}
7+
8+
> Create MySQLCluster:
9+
{{- end }}
10+
11+
kubectl apply -f https://github.com/radondb/radondb-mysql-kubernetes/releases/latest/download/mysql_v1alpha1_mysqlcluster.yaml
12+
13+
Create Users:
14+
15+
kubectl apply -f https://github.com/radondb/radondb-mysql-kubernetes/releases/latest/download/mysql_v1alpha1_mysqluser.yaml
16+
17+
{{- if .Values.mysqlcluster.install }}
18+
19+
> Connect to the database:
20+
{{- else }}
21+
22+
Connect to the database:
23+
{{- end }}
24+
25+
kubectl exec -it svc/sample-leader -c mysql -- mysql -usuper_usr -pRadonDB@123
26+
27+
Change password:
28+
29+
kubectl patch secret sample-user-password --patch="{\"data\": { \"super_usr\": \"$(echo -n <yourpass> |base64 -w0)\" }}" -oyaml
30+
31+
Github: https://github.com/radondb/radondb-mysql-kubernetes

charts/mysql-operator/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
replicaCount: 1
66
installCRDS: true
77

8+
mysqlcluster:
9+
install: false
10+
version: v2.2.1
811
## Specify an imagePullPolicy (Required)
912
## It's recommended to change this to 'Always' if the image tag is 'latest'
1013
## ref: http://kubernetes.io/docs/user-guide/images/#updating-images

0 commit comments

Comments
 (0)