@@ -33,174 +33,3 @@ The MySQL operator provides three services to access the nodes:
3333
3434We use helm to deploy our application into Kubernetes, so we updated our charts
3535to use Mysql operator to provide a cluster per application.
36-
37- #### Helm chart
38- In the next paragraphs are show some parts of a helm chart, only the parts that
39- provide a MySQL Cluster. You can find a more comprehensive guide to writing a
40- helm chart [ here] ( https://docs.helm.sh/developing_charts/ ) .
41-
42- In this section, we'll exemplify parts from a chart that can be used to
43- integrate the MySQL Operator with an application using Helm. The chart structure
44- is as follows:
45-
46- ```
47- chart
48- ├── Chart.yaml
49- ├── templates
50- │ ├── deployment.yaml
51- │ ├── mysql-backup-secret.yaml
52- │ ├── mysql-secret.yaml
53- │ ├── mysql.yaml
54- | └── _helpers.tpl
55- └── values.yaml
56- ```
57-
58- #### The ` values.yaml ` file
59-
60- The ` values.yaml ` contains chart defaults values.
61-
62- ``` yaml
63- mysql :
64- # if the MySQL is enabled or not, this can be put under a flag
65- enabled : true
66- # how many MySQL cluster nodes
67- replicas : 1
68- # the application user to be created
69- dbUser : app
70- # the application database name to be created
71- dbDatabase : application
72- # the application password
73- dbPassword : password
74- # the root password
75- rootPassword : <random>
76- # some extra specification
77-
78- # backup scheduler for reccurent backups
79- backupSchedule :
80- # backup URL to put backups
81- backupURL :
82- # a secret that contains storage credentails
83- backupSecretName :
84- # or storage credentails, the backup secret content
85- backupCredentials :
86- # GCS_SERVICE_ACCOUNT_JSON_KEY: ?
87- # GCS_PROJECT_ID: ?
88- ```
89-
90- #### The ` mysql.yaml ` file
91-
92- This file contains the Mysql cluster resource as a go template.
93-
94- ``` yaml
95- apiVersion : mysql.presslabs.org/v1alpha1
96- kind : MysqlCluster
97- metadata :
98- name : {{ .Release.Name}}-db
99- spec :
100- replicas : {{ .Values.mysql.replicas }}
101- secretName : {{ .Release.Name }}-db-secret
102-
103- {{- if .Values.mysql.backupSecretName }}
104- backupSecretName : {{ .Values.mysql.backupSecretName }}
105- {{- else if .Values.mysql.backupCredentials }}
106- backupSecretName : {{ .Release.Name }}-backup-secret
107- {{- else if .Values.mysql.backupSchedule }}
108- {{ required "One of .mysql.backupBucketSecretName and .mysql.backupCredentails should be specified" "" }}
109- {{- end }}
110-
111- {{- if .Values.mysql.backupSchedule }}
112- backupSchedule : {{ .Values.mysql.backupSchedule }}
113- backupURL : {{ required ".mysql.backupBucketURL is missing" .Values.mysql.backupURL }}
114- {{- end }}
115- ```
116-
117-
118- #### The ` mysql-secret.yaml ` file
119-
120- This file describes how to create the secret that contains all needed fields.
121-
122- ``` yaml
123- apiVersion : v1
124- kind : Secret
125- metadata :
126- name : {{ .Release.Name }}-db-secret
127- type : Opaque
128- data :
129- ROOT_PASSWORD : {{ required ".mysql.rootPassword is missing" .Values.mysql.rootPassword | b64enc | quote }}
130- USER : {{ required ".mysql.dbUser is missing" .Values.mysql.dbUser | b64enc | quote }}
131- PASSWORD : {{ required ".mysql.dbPassword is missing" .Values.mysql.dbPassword | b64enc | quote }}
132- DATABASE : {{ required ".mysql.dbDatabase is missing" .Values.mysql.dbDatabase | b64enc | quote }}
133- DB_CONNECT_URL : {{ include "app.mysql_connect_url" . | b64enc | quote }}
134- ` ` `
135-
136-
137- #### The ` mysql-backup-secret.yaml` file
138-
139- This file describes how to create the secret that contains credentials for the
140- storage provider.
141-
142- ` ` ` yaml
143- {{- if .Values.mysql.backupCredentials }}
144- apiVersion: v1
145- kind: Secret
146- metadata:
147- name: {{ .Release.Name }}-backup-secret
148- labels:
149- app: {{ template "name" . }}
150- chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
151- release: {{ .Release.Name }}
152- heritage: {{ .Release.Service }}
153- type: Opaque
154- data:
155- {{- range $key, $value := .Values.mysql.backupCredentials }}
156- {{ $key | upper }}: {{ $value | b64enc | quote }}
157- {{ end }}
158- {{- end }}
159- ` ` `
160-
161-
162- # ### The example `deployment.yaml` file
163-
164- This file is an example of how to link the `DB_CONNECT_URL` from the DB secret
165- to the application environment.
166-
167- ` ` ` yaml
168- apiVersion: extensions/v1beta1
169- kind: Deployment
170- metadata:
171- name: {{ .Release.Name }}-web
172- spec:
173- replicas: {{ .Values.web.replicaCount }}
174- template:
175- metadata:
176- labels:
177- app: {{ template "name" . }}
178- release: {{ .Release.Name }}
179- role: web
180- spec:
181- containers:
182- - name: {{ .Release.Name }}-web
183- image: "{{ .Values.image }}"
184- imagePullPolicy: {{ .Values.imagePullPolicy }}
185- readinessProbe:
186- env:
187- - name: {{ printf "%s%s" $envPrefix "DB_CONNECT_URL" }}
188- valueFrom:
189- secretKeyRef:
190- name: {{ .Release.Name }}-db-secret
191- key: DB_CONNECT_URL
192- ` ` `
193-
194-
195- # ### The helper `_helpers.tpl` file
196-
197- By convention, we put all helper templates in this file. Here is the template
198- that builds `DB_CONNECT_URL`. The DSN is constructed using the master service,
199- that points to the master nodes, so we can read and write to this DSN.
200-
201- ` ` ` yaml
202- {{- define "app.mysql_connect_url" -}}
203- mysql://{{- .Values.mysql.dbUser -}}:{{- .Values.mysql.dbPassword -}}@
204- {{- include "app.name_mysql" . -}}-mysql-master:3306/{{- .Values.mysql.dbDatabase -}}
205- {{- end -}}
206- ` ` `
0 commit comments