1 # Copyright © 2017-2018 Amdocs, Bell Canada
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 apiVersion: apps/v1beta1
18 name: {{ include "common.fullname" . }}
19 namespace: {{ include "common.namespace" . }}
21 app: {{ include "common.name" . }}
22 chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
23 release: {{ .Release.Name }}
24 heritage: {{ .Release.Service }}
26 serviceName: {{ .Values.service.name }}
27 replicas: {{ .Values.replicaCount }}
31 app: {{ include "common.name" . }}
32 release: {{ .Release.Name }}
35 #{{ if not .Values.disableNfsProvisioner }}
36 - name: {{ include "common.name" . }}-readiness
41 - {{ .Values.nfsprovisionerPrefix }}-nfs-provisioner
47 fieldPath: metadata.namespace
48 image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}"
49 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
52 image: "{{ .Values.repository | default .Values.repository }}/{{ .Values.image }}"
53 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
59 # Generate mysql server-id from pod ordinal index.
60 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
61 ordinal=${BASH_REMATCH[1]}
62 siteId={{ .Values.geoSiteId }}
63 echo BASH_REMATCH=${BASH_REMATCH}
64 echo [mysqld] > /mnt/conf.d/server-id.cnf
65 # Add an offset to avoid reserved server-id=0 value.
66 echo server-id=$(($siteId*100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
67 # Copy appropriate conf.d files from config-map to emptyDir.
68 if [[ $ordinal -eq 0 ]]; then
69 cp /mnt/config-map/master.cnf /mnt/conf.d/
71 cp /mnt/config-map/slave.cnf /mnt/conf.d/
75 mountPath: /mnt/conf.d
77 mountPath: /mnt/config-map
80 image: "{{ .Values.global.xtrabackupRepository | default .Values.xtrabackupRepository }}/{{ .Values.xtrabackupImage }}"
81 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
83 - name: MYSQL_ROOT_PASSWORD
86 name: {{ template "common.fullname" . }}
93 # Skip the clone if data already exists.
94 [[ -d /var/lib/mysql/mysql ]] && exit 0
95 # Skip the clone on master (ordinal index 0).
96 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
97 ordinal=${BASH_REMATCH[1]}
99 [[ $ordinal -eq 0 ]] && exit 0
100 # Clone data from previous peer.
101 ncat --recv-only {{ include "common.fullname" . }}-$(($ordinal-1)).{{ .Values.service.name }}.{{ include "common.namespace" . }} 3307 | xbstream -x -C /var/lib/mysql
102 # Prepare the backup.
103 xtrabackup --user=root --password=$MYSQL_ROOT_PASSWORD --prepare --target-dir=/var/lib/mysql
106 - name: {{ include "common.fullname" . }}-data
107 mountPath: /var/lib/mysql
110 mountPath: /etc/mysql/conf.d
114 - name: {{ include "common.name" . }}
115 image: "{{ .Values.repository | default .Values.repository }}/{{ .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: /var/lib/mysql
146 name: {{ include "common.fullname" . }}-data
148 - mountPath: /etc/mysql/conf.d
151 {{ toYaml .Values.resources | indent 12 }}
152 {{- if .Values.nodeSelector }}
154 {{ toYaml .Values.nodeSelector | indent 10 }}
156 {{- if .Values.affinity }}
158 {{ toYaml .Values.affinity | indent 10 }}
162 image: "{{ .Values.global.xtrabackupRepository | default .Values.xtrabackupRepository }}/{{ .Values.xtrabackupImage }}"
163 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
165 - name: MYSQL_ROOT_PASSWORD
168 name: {{ template "common.fullname" . }}
169 key: db-root-password
171 - containerPort: {{ .Values.xtrabackup.internalPort }}
180 # Determine binlog position of cloned data, if any.
181 if [[ -f xtrabackup_slave_info ]]; then
182 echo "Inside xtrabackup_slave_info"
183 # XtraBackup already generated a partial "CHANGE MASTER TO" query
184 # because we're cloning from an existing slave.
185 mv xtrabackup_slave_info change_master_to.sql.in
186 # Ignore xtrabackup_binlog_info in this case (it's useless).
187 rm -f xtrabackup_binlog_info
188 elif [[ -f xtrabackup_binlog_info ]]; then
189 echo "Inside xtrabackup_binlog_info"
190 # We're cloning directly from master. Parse binlog position.
191 [[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
192 rm xtrabackup_binlog_info
193 echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\
194 MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in
197 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
198 ordinal=${BASH_REMATCH[1]}
201 mysqlhost={{ include "common.fullname" . }}-$(($ordinal)).{{ .Values.service.name }}.{{ include "common.namespace" . }}
204 # Check if we need to complete a clone by starting replication.
205 if [[ -f change_master_to.sql.in ]]; then
206 echo "Waiting for mysqld to be ready (accepting connections)"
207 until mysql --user=root --password=$MYSQL_ROOT_PASSWORD -h $mysqlhost -e "SELECT 1"; do sleep 1; done
209 echo "Initializing replication from clone position"
210 # In case of container restart, attempt this at-most-once.
211 mv change_master_to.sql.in change_master_to.sql.orig
212 mysql --user=root --password=$MYSQL_ROOT_PASSWORD -h $mysqlhost <<EOF
213 $(<change_master_to.sql.orig),
214 MASTER_HOST="{{ include "common.fullname" . }}-0.{{ .Values.service.name }}.{{ include "common.namespace" . }}",
216 MASTER_PASSWORD="$MYSQL_ROOT_PASSWORD",
217 MASTER_CONNECT_RETRY=10;
222 # Start a server to send backups when requested by peers.
223 exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \
224 "xtrabackup --user=root --password=$MYSQL_ROOT_PASSWORD --backup --slave-info --stream=xbstream --host=$mysqlhost"
226 - name: {{ include "common.fullname" . }}-data
227 mountPath: /var/lib/mysql
230 mountPath: /etc/mysql/conf.d
236 name: {{ include "common.fullname" . }}-db-configmap
240 - name: {{ include "common.fullname" . }}-data
241 #{{ if not .Values.disableNfsProvisioner }}
242 volumeClaimTemplates:
244 name: {{ include "common.fullname" . }}-data
246 volume.beta.kubernetes.io/storage-class: "{{ include "common.fullname" . }}-data"
248 accessModes: ["ReadWriteMany"]
252 #{{ else if .Values.persistence.enabled }}
253 persistentVolumeClaim:
254 claimName: {{ include "common.fullname" . }}-data