2 # Copyright © 2017 Amdocs, Bell Canada
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 apiVersion: apps/v1beta1
20 name: {{ include "common.fullname" . }}
21 namespace: {{ include "common.namespace" . }}
23 app: {{ include "common.name" . }}
24 chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
25 release: {{ .Release.Name }}
26 heritage: {{ .Release.Service }}
28 serviceName: {{ .Values.service.name }}
29 replicas: {{ .Values.replicaCount }}
33 app: {{ include "common.name" . }}
34 release: {{ .Release.Name }}
37 #{{ if not .Values.disableNfsProvisioner }}
38 - name: {{ include "common.name" . }}-readiness
43 - {{ .Values.nfsprovisionerPrefix }}-nfs-provisioner
49 fieldPath: metadata.namespace
50 image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}"
51 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
54 image: "{{ .Values.dockerHubRepository }}/{{ .Values.image }}"
55 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
61 # Generate mysql server-id from pod ordinal index.
62 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
63 ordinal=${BASH_REMATCH[1]}
64 siteId={{ .Values.geoSiteId }}
65 echo BASH_REMATCH=${BASH_REMATCH}
66 echo [mysqld] > /mnt/conf.d/server-id.cnf
67 # Add an offset to avoid reserved server-id=0 value.
68 echo server-id=$(($siteId*100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
69 # Copy appropriate conf.d files from config-map to emptyDir.
70 if [[ $ordinal -eq 0 ]]; then
71 cp /mnt/config-map/master.cnf /mnt/conf.d/
73 cp /mnt/config-map/slave.cnf /mnt/conf.d/
77 mountPath: /mnt/conf.d
79 mountPath: /mnt/config-map
82 image: "{{ .Values.global.xtrabackupRepository | default .Values.xtrabackupRepository }}/{{ .Values.xtrabackupImage }}"
83 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
85 - name: MYSQL_ROOT_PASSWORD
88 name: {{ template "common.fullname" . }}
95 # Skip the clone if data already exists.
96 [[ -d /var/lib/mysql/mysql ]] && exit 0
97 # Skip the clone on master (ordinal index 0).
98 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
99 ordinal=${BASH_REMATCH[1]}
101 [[ $ordinal -eq 0 ]] && exit 0
102 # Clone data from previous peer.
103 ncat --recv-only {{ include "common.fullname" . }}-$(($ordinal-1)).{{ .Values.service.name }}.{{ include "common.namespace" . }} 3307 | xbstream -x -C {{ .Values.persistence.mysqlPath }}
104 # Prepare the backup.
105 xtrabackup --user=root --password=$MYSQL_ROOT_PASSWORD --prepare --target-dir=/var/lib/mysql
106 ls -l {{ .Values.persistence.mysqlPath }}
108 - name: {{ include "common.fullname" . }}-mysql
109 mountPath: {{ .Values.persistence.mysqlPath }}
111 mountPath: /etc/mysql/conf.d
114 - name: {{ include "common.name" . }}
115 image: "{{ .Values.dockerHubRepository }}/{{ .Values.image }}"
116 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
118 - containerPort: {{ .Values.service.internalPort }}
119 # disable liveness probe when breakpoints set in debugger
120 # so K8s doesn't restart unresponsive container
121 {{- if eq .Values.liveness.enabled true }}
124 command: ["mysqladmin", "ping"]
125 initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
126 periodSeconds: {{ .Values.liveness.periodSeconds }}
127 timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
131 port: {{ .Values.service.internalPort }}
132 initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
133 periodSeconds: {{ .Values.readiness.periodSeconds }}
135 - name: MYSQL_ROOT_PASSWORD
138 name: {{ template "common.fullname" . }}
139 key: db-root-password
140 - name: MYSQL_ROOT_HOST
142 - name: MYSQL_ALLOW_EMPTY_PASSWORD
143 value: {{ .Values.config.dbAllowEmptyPassword | default "0" | quote }}
145 - mountPath: {{ .Values.persistence.mysqlPath }}
146 name: {{ include "common.fullname" . }}-mysql
147 - mountPath: /etc/mysql/conf.d
150 {{ toYaml .Values.resources | indent 12 }}
151 {{- if .Values.nodeSelector }}
153 {{ toYaml .Values.nodeSelector | indent 10 }}
155 {{- if .Values.affinity }}
157 {{ toYaml .Values.affinity | indent 10 }}
161 image: "{{ .Values.global.xtrabackupRepository | default .Values.xtrabackupRepository }}/{{ .Values.xtrabackupImage }}"
162 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
164 - name: MYSQL_ROOT_PASSWORD
167 name: {{ template "common.fullname" . }}
168 key: db-root-password
170 - containerPort: {{ .Values.xtrabackup.internalPort }}
177 cd {{ .Values.persistence.mysqlPath }}
179 # Determine binlog position of cloned data, if any.
180 if [[ -f xtrabackup_slave_info ]]; then
181 echo "Inside xtrabackup_slave_info"
182 # XtraBackup already generated a partial "CHANGE MASTER TO" query
183 # because we're cloning from an existing slave.
184 mv xtrabackup_slave_info change_master_to.sql.in
185 # Ignore xtrabackup_binlog_info in this case (it's useless).
186 rm -f xtrabackup_binlog_info
187 elif [[ -f xtrabackup_binlog_info ]]; then
188 echo "Inside xtrabackup_binlog_info"
189 # We're cloning directly from master. Parse binlog position.
190 [[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
191 rm xtrabackup_binlog_info
192 echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\
193 MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in
196 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
197 ordinal=${BASH_REMATCH[1]}
200 mysqlhost={{ include "common.fullname" . }}-$(($ordinal)).{{ .Values.service.name }}.{{ include "common.namespace" . }}
203 # Check if we need to complete a clone by starting replication.
204 if [[ -f change_master_to.sql.in ]]; then
205 echo "Waiting for mysqld to be ready (accepting connections)"
206 until mysql --user=root --password=$MYSQL_ROOT_PASSWORD -h $mysqlhost -e "SELECT 1"; do sleep 1; done
208 echo "Initializing replication from clone position"
209 # In case of container restart, attempt this at-most-once.
210 mv change_master_to.sql.in change_master_to.sql.orig
211 mysql --user=root --password=$MYSQL_ROOT_PASSWORD -h $mysqlhost <<EOF
212 $(<change_master_to.sql.orig),
213 MASTER_HOST="{{ include "common.fullname" . }}-0.{{ .Values.service.name }}.{{ include "common.namespace" . }}",
215 MASTER_PASSWORD="$MYSQL_ROOT_PASSWORD",
216 MASTER_CONNECT_RETRY=10;
221 # Start a server to send backups when requested by peers.
222 exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \
223 "xtrabackup --user=root --password=$MYSQL_ROOT_PASSWORD --backup --slave-info --stream=xbstream --host=$mysqlhost"
225 - name: {{ include "common.fullname" . }}-mysql
226 mountPath: {{ .Values.persistence.mysqlPath }}
228 mountPath: /etc/mysql/conf.d
234 name: {{ include "common.fullname" . }}-db-configmap
238 - name: {{ include "common.fullname" . }}-mysql
239 {{ if not .Values.persistence.enabled }}
240 - name: {{ include "common.fullname" . }}-mysql
243 volumeClaimTemplates:
245 name: {{ include "common.fullname" . }}-mysql
247 name: {{ include "common.fullname" . }}
249 accessModes: [ {{ .Values.persistence.accessMode }} ]
250 storageClassName: {{ include "common.fullname" . }}-mysql
253 storage: {{ .Values.persistence.size }}