1 apiVersion: apps/v1beta1
4 name: {{ include "common.fullname" . }}
5 namespace: {{ include "common.namespace" . }}
7 app: {{ include "common.name" . }}
8 chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
9 release: {{ .Release.Name }}
10 heritage: {{ .Release.Service }}
12 serviceName: {{ .Values.service.name }}
13 replicas: {{ .Values.replicaCount }}
17 app: {{ include "common.name" . }}
18 release: {{ .Release.Name }}
21 #{{ if not .Values.disableNfsProvisioner }}
22 - name: {{ include "common.name" . }}-readiness
27 - {{ .Values.nfsprovisionerPrefix }}-nfs-provisioner
33 fieldPath: metadata.namespace
34 image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}"
35 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
38 image: "{{ .Values.repository | default .Values.repository }}/{{ .Values.image }}"
39 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
45 # Generate mysql server-id from pod ordinal index.
46 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
47 ordinal=${BASH_REMATCH[1]}
48 siteId={{ .Values.geoSiteId }}
49 echo BASH_REMATCH=${BASH_REMATCH}
50 echo [mysqld] > /mnt/conf.d/server-id.cnf
51 # Add an offset to avoid reserved server-id=0 value.
52 echo server-id=$(($siteId*100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
53 # Copy appropriate conf.d files from config-map to emptyDir.
54 if [[ $ordinal -eq 0 ]]; then
55 cp /mnt/config-map/master.cnf /mnt/conf.d/
57 cp /mnt/config-map/slave.cnf /mnt/conf.d/
61 mountPath: /mnt/conf.d
63 mountPath: /mnt/config-map
66 image: "{{ .Values.global.xtrabackupRepository | default .Values.xtrabackupRepository }}/{{ .Values.xtrabackupImage }}"
67 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
69 - name: MYSQL_ROOT_PASSWORD
72 name: {{ template "common.fullname" . }}
79 # Skip the clone if data already exists.
80 [[ -d /var/lib/mysql/mysql ]] && exit 0
81 # Skip the clone on master (ordinal index 0).
82 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
83 ordinal=${BASH_REMATCH[1]}
85 [[ $ordinal -eq 0 ]] && exit 0
86 # Clone data from previous peer.
87 ncat --recv-only {{ template "common.name" . }}-$(($ordinal-1)).{{ .Values.service.name }}.{{ include "common.namespace" . }} 3307 | xbstream -x -C /var/lib/mysql
89 xtrabackup --user=root --password=$MYSQL_ROOT_PASSWORD --prepare --target-dir=/var/lib/mysql
92 - name: {{ include "common.fullname" . }}-data
93 mountPath: /var/lib/mysql
96 mountPath: /etc/mysql/conf.d
100 - name: {{ include "common.name" . }}
101 image: "{{ .Values.repository | default .Values.repository }}/{{ .Values.image }}"
102 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
104 - containerPort: {{ .Values.service.internalPort }}
105 # disable liveness probe when breakpoints set in debugger
106 # so K8s doesn't restart unresponsive container
107 {{- if eq .Values.liveness.enabled true }}
110 command: ["mysqladmin", "ping"]
111 initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
112 periodSeconds: {{ .Values.liveness.periodSeconds }}
113 timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
117 port: {{ .Values.service.internalPort }}
118 initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
119 periodSeconds: {{ .Values.readiness.periodSeconds }}
121 - name: MYSQL_ROOT_PASSWORD
124 name: {{ template "common.fullname" . }}
125 key: db-root-password
126 - name: MYSQL_ROOT_HOST
128 - name: MYSQL_ALLOW_EMPTY_PASSWORD
129 value: {{ .Values.config.dbAllowEmptyPassword | default "0" | quote }}
131 - mountPath: /var/lib/mysql
132 name: {{ include "common.fullname" . }}-data
134 - mountPath: /etc/mysql/conf.d
137 {{ toYaml .Values.resources | indent 12 }}
138 {{- if .Values.nodeSelector }}
140 {{ toYaml .Values.nodeSelector | indent 10 }}
142 {{- if .Values.affinity }}
144 {{ toYaml .Values.affinity | indent 10 }}
148 image: "{{ .Values.global.xtrabackupRepository | default .Values.xtrabackupRepository }}/{{ .Values.xtrabackupImage }}"
149 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
151 - name: MYSQL_ROOT_PASSWORD
154 name: {{ template "common.fullname" . }}
155 key: db-root-password
157 - containerPort: {{ .Values.xtrabackup.internalPort }}
166 # Determine binlog position of cloned data, if any.
167 if [[ -f xtrabackup_slave_info ]]; then
168 echo "Inside xtrabackup_slave_info"
169 # XtraBackup already generated a partial "CHANGE MASTER TO" query
170 # because we're cloning from an existing slave.
171 mv xtrabackup_slave_info change_master_to.sql.in
172 # Ignore xtrabackup_binlog_info in this case (it's useless).
173 rm -f xtrabackup_binlog_info
174 elif [[ -f xtrabackup_binlog_info ]]; then
175 echo "Inside xtrabackup_binlog_info"
176 # We're cloning directly from master. Parse binlog position.
177 [[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
178 rm xtrabackup_binlog_info
179 echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\
180 MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in
183 # Check if we need to complete a clone by starting replication.
184 if [[ -f change_master_to.sql.in ]]; then
185 echo "Waiting for mysqld to be ready (accepting connections)"
186 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
187 ordinal=${BASH_REMATCH[1]}
189 until mysql --user=root --password=$MYSQL_ROOT_PASSWORD -h localhost -e "SELECT 1"; do sleep 1; done
191 echo "Initializing replication from clone position"
192 # In case of container restart, attempt this at-most-once.
193 mv change_master_to.sql.in change_master_to.sql.orig
194 mysql --user=root --password=$MYSQL_ROOT_PASSWORD -h localhost <<EOF
195 $(<change_master_to.sql.orig),
196 MASTER_HOST="{{ template "common.name" . }}-0.{{ .Values.service.name }}.{{ include "common.namespace" . }}",
198 MASTER_PASSWORD="$MYSQL_ROOT_PASSWORD",
199 MASTER_CONNECT_RETRY=10;
204 # Start a server to send backups when requested by peers.
205 exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \
206 "xtrabackup --user=root --password=$MYSQL_ROOT_PASSWORD --backup --slave-info --stream=xbstream --host=localhost"
208 - name: {{ include "common.fullname" . }}-data
209 mountPath: /var/lib/mysql
212 mountPath: /etc/mysql/conf.d
218 name: {{ include "common.fullname" . }}-db-configmap
222 - name: {{ include "common.fullname" . }}-data
223 #{{ if not .Values.disableNfsProvisioner }}
224 volumeClaimTemplates:
226 name: {{ include "common.fullname" . }}-data
228 volume.beta.kubernetes.io/storage-class: "{{ include "common.fullname" . }}-data"
230 accessModes: ["ReadWriteMany"]
234 #{{ else if .Values.persistence.enabled }}
235 persistentVolumeClaim:
236 claimName: {{ include "common.fullname" . }}-data