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 chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
35 release: {{ .Release.Name }}
36 heritage: {{ .Release.Service }}
39 #{{ if not .Values.disableNfsProvisioner }}
40 - name: {{ include "common.name" . }}-readiness
45 - {{ .Values.nfsprovisionerPrefix }}-nfs-provisioner
51 fieldPath: metadata.namespace
52 image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}"
53 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
56 image: "{{ .Values.dockerHubRepository }}/{{ .Values.image }}"
57 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
63 # Generate mysql server-id from pod ordinal index.
64 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
65 ordinal=${BASH_REMATCH[1]}
66 siteId={{ .Values.geoSiteId }}
67 echo BASH_REMATCH=${BASH_REMATCH}
68 echo [mysqld] > /mnt/conf.d/server-id.cnf
69 # Add an offset to avoid reserved server-id=0 value.
70 echo server-id=$(($siteId*100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
71 # Copy appropriate conf.d files from config-map to emptyDir.
72 if [[ $ordinal -eq 0 ]]; then
73 cp /mnt/config-map/master.cnf /mnt/conf.d/
75 cp /mnt/config-map/slave.cnf /mnt/conf.d/
79 mountPath: /mnt/conf.d
81 mountPath: /mnt/config-map
84 image: "{{ .Values.global.xtrabackupRepository | default .Values.xtrabackupRepository }}/{{ .Values.xtrabackupImage }}"
85 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
87 - name: MYSQL_ROOT_PASSWORD
90 name: {{ template "common.fullname" . }}
97 # Skip the clone if data already exists.
98 [[ -d /var/lib/mysql/mysql ]] && exit 0
99 # Skip the clone on master (ordinal index 0).
100 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
101 ordinal=${BASH_REMATCH[1]}
103 [[ $ordinal -eq 0 ]] && exit 0
104 # Clone data from previous peer.
105 ncat --recv-only {{ include "common.fullname" . }}-$(($ordinal-1)).{{ .Values.service.name }}.{{ include "common.namespace" . }} 3307 | xbstream -x -C {{ .Values.persistence.mysqlPath }}
106 # Prepare the backup.
107 xtrabackup --user=root --password=$MYSQL_ROOT_PASSWORD --prepare --target-dir=/var/lib/mysql
108 ls -l {{ .Values.persistence.mysqlPath }}
110 - name: {{ include "common.fullname" . }}-mysql
111 mountPath: {{ .Values.persistence.mysqlPath }}
113 mountPath: /etc/mysql/conf.d
116 - name: {{ include "common.name" . }}
117 image: "{{ .Values.dockerHubRepository }}/{{ .Values.image }}"
118 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
120 - containerPort: {{ .Values.service.internalPort }}
121 # disable liveness probe when breakpoints set in debugger
122 # so K8s doesn't restart unresponsive container
123 {{- if eq .Values.liveness.enabled true }}
126 command: ["mysqladmin", "ping"]
127 initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
128 periodSeconds: {{ .Values.liveness.periodSeconds }}
129 timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
133 port: {{ .Values.service.internalPort }}
134 initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
135 periodSeconds: {{ .Values.readiness.periodSeconds }}
137 - name: MYSQL_ROOT_PASSWORD
140 name: {{ template "common.fullname" . }}
141 key: db-root-password
142 - name: MYSQL_ROOT_HOST
144 - name: MYSQL_ALLOW_EMPTY_PASSWORD
145 value: {{ .Values.config.dbAllowEmptyPassword | default "0" | quote }}
147 - mountPath: {{ .Values.persistence.mysqlPath }}
148 name: {{ include "common.fullname" . }}-mysql
149 - mountPath: /etc/mysql/conf.d
152 {{ include "common.resources" . | indent 12 }}
153 {{- if .Values.nodeSelector }}
155 {{ toYaml .Values.nodeSelector | indent 10 }}
157 {{- if .Values.affinity }}
159 {{ toYaml .Values.affinity | indent 10 }}
163 image: "{{ .Values.global.xtrabackupRepository | default .Values.xtrabackupRepository }}/{{ .Values.xtrabackupImage }}"
164 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
166 - name: MYSQL_ROOT_PASSWORD
169 name: {{ template "common.fullname" . }}
170 key: db-root-password
172 - containerPort: {{ .Values.xtrabackup.internalPort }}
179 cd {{ .Values.persistence.mysqlPath }}
181 # Determine binlog position of cloned data, if any.
182 if [[ -f xtrabackup_slave_info ]]; then
183 echo "Inside xtrabackup_slave_info"
184 # XtraBackup already generated a partial "CHANGE MASTER TO" query
185 # because we're cloning from an existing slave.
186 mv xtrabackup_slave_info change_master_to.sql.in
187 # Ignore xtrabackup_binlog_info in this case (it's useless).
188 rm -f xtrabackup_binlog_info
189 elif [[ -f xtrabackup_binlog_info ]]; then
190 echo "Inside xtrabackup_binlog_info"
191 # We're cloning directly from master. Parse binlog position.
192 [[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
193 rm xtrabackup_binlog_info
194 echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\
195 MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in
198 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
199 ordinal=${BASH_REMATCH[1]}
202 mysqlhost={{ include "common.fullname" . }}-$(($ordinal)).{{ .Values.service.name }}.{{ include "common.namespace" . }}
205 # Check if we need to complete a clone by starting replication.
206 if [[ -f change_master_to.sql.in ]]; then
207 echo "Waiting for mysqld to be ready (accepting connections)"
208 until mysql --user=root --password=$MYSQL_ROOT_PASSWORD -h $mysqlhost -e "SELECT 1"; do sleep 1; done
210 echo "Initializing replication from clone position"
211 # In case of container restart, attempt this at-most-once.
212 mv change_master_to.sql.in change_master_to.sql.orig
213 mysql --user=root --password=$MYSQL_ROOT_PASSWORD -h $mysqlhost <<EOF
214 $(<change_master_to.sql.orig),
215 MASTER_HOST="{{ include "common.fullname" . }}-0.{{ .Values.service.name }}.{{ include "common.namespace" . }}",
217 MASTER_PASSWORD="$MYSQL_ROOT_PASSWORD",
218 MASTER_CONNECT_RETRY=10;
223 # Start a server to send backups when requested by peers.
224 exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \
225 "xtrabackup --user=root --password=$MYSQL_ROOT_PASSWORD --backup --slave-info --stream=xbstream --host=$mysqlhost"
227 - name: {{ include "common.fullname" . }}-mysql
228 mountPath: {{ .Values.persistence.mysqlPath }}
230 mountPath: /etc/mysql/conf.d
236 name: {{ include "common.fullname" . }}-db-configmap
240 - name: {{ include "common.fullname" . }}-mysql
241 {{ if not .Values.persistence.enabled }}
242 - name: {{ include "common.fullname" . }}-mysql
245 volumeClaimTemplates:
247 name: {{ include "common.fullname" . }}-mysql
249 app: {{ include "common.name" . }}
250 chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
251 release: {{ .Release.Name }}
252 heritage: {{ .Release.Service }}
253 name: {{ include "common.fullname" . }}
255 accessModes: [ {{ .Values.persistence.accessMode }} ]
256 storageClassName: {{ include "common.fullname" . }}-mysql
259 storage: {{ .Values.persistence.size }}
262 name: {{ include "common.fullname" . }}