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 echo BASH_REMATCH=${BASH_REMATCH}
49 echo [mysqld] > /mnt/conf.d/server-id.cnf
50 # Add an offset to avoid reserved server-id=0 value.
51 echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
52 # Copy appropriate conf.d files from config-map to emptyDir.
53 if [[ $ordinal -eq 0 ]]; then
54 cp /mnt/config-map/master.cnf /mnt/conf.d/
56 cp /mnt/config-map/slave.cnf /mnt/conf.d/
60 mountPath: /mnt/conf.d
62 mountPath: /mnt/config-map
65 image: "{{ .Values.global.xtrabackupRepository | default .Values.xtrabackupRepository }}/{{ .Values.xtrabackupImage }}"
66 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
68 - name: MYSQL_ROOT_PASSWORD
71 name: {{ template "common.fullname" . }}
78 # Skip the clone if data already exists.
79 [[ -d /var/lib/mysql/mysql ]] && exit 0
80 # Skip the clone on master (ordinal index 0).
81 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
82 ordinal=${BASH_REMATCH[1]}
84 [[ $ordinal -eq 0 ]] && exit 0
85 # Clone data from previous peer.
86 ncat --recv-only {{ template "common.name" . }}-$(($ordinal-1)).{{ .Values.service.name }}.{{ include "common.namespace" . }} 3307 | xbstream -x -C /var/lib/mysql
88 xtrabackup --user=root --password=$MYSQL_ROOT_PASSWORD --prepare --target-dir=/var/lib/mysql
91 - name: {{ include "common.fullname" . }}-data
92 mountPath: /var/lib/mysql
95 mountPath: /etc/mysql/conf.d
99 - name: {{ include "common.name" . }}
100 image: "{{ .Values.repository | default .Values.repository }}/{{ .Values.image }}"
101 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
103 - containerPort: {{ .Values.service.internalPort }}
104 # disable liveness probe when breakpoints set in debugger
105 # so K8s doesn't restart unresponsive container
106 {{- if eq .Values.liveness.enabled true }}
109 command: ["mysqladmin", "ping"]
110 initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
111 periodSeconds: {{ .Values.liveness.periodSeconds }}
112 timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
116 port: {{ .Values.service.internalPort }}
117 initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
118 periodSeconds: {{ .Values.readiness.periodSeconds }}
120 - name: MYSQL_ROOT_PASSWORD
123 name: {{ template "common.fullname" . }}
124 key: db-root-password
125 - name: MYSQL_ROOT_HOST
127 - name: MYSQL_ALLOW_EMPTY_PASSWORD
128 value: {{ .Values.config.dbAllowEmptyPassword | default "0" | quote }}
130 - mountPath: /var/lib/mysql
131 name: {{ include "common.fullname" . }}-data
133 - mountPath: /etc/mysql/conf.d
136 {{ toYaml .Values.resources | indent 12 }}
137 {{- if .Values.nodeSelector }}
139 {{ toYaml .Values.nodeSelector | indent 10 }}
141 {{- if .Values.affinity }}
143 {{ toYaml .Values.affinity | indent 10 }}
147 image: "{{ .Values.global.xtrabackupRepository | default .Values.xtrabackupRepository }}/{{ .Values.xtrabackupImage }}"
148 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
150 - name: MYSQL_ROOT_PASSWORD
153 name: {{ template "common.fullname" . }}
154 key: db-root-password
156 - containerPort: {{ .Values.xtrabackup.internalPort }}
165 # Determine binlog position of cloned data, if any.
166 if [[ -f xtrabackup_slave_info ]]; then
167 echo "Inside xtrabackup_slave_info"
168 # XtraBackup already generated a partial "CHANGE MASTER TO" query
169 # because we're cloning from an existing slave.
170 mv xtrabackup_slave_info change_master_to.sql.in
171 # Ignore xtrabackup_binlog_info in this case (it's useless).
172 rm -f xtrabackup_binlog_info
173 elif [[ -f xtrabackup_binlog_info ]]; then
174 echo "Inside xtrabackup_binlog_info"
175 # We're cloning directly from master. Parse binlog position.
176 [[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
177 rm xtrabackup_binlog_info
178 echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\
179 MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in
182 # Check if we need to complete a clone by starting replication.
183 if [[ -f change_master_to.sql.in ]]; then
184 echo "Waiting for mysqld to be ready (accepting connections)"
185 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
186 ordinal=${BASH_REMATCH[1]}
188 until mysql --user=root --password=$MYSQL_ROOT_PASSWORD -h localhost -e "SELECT 1"; do sleep 1; done
190 echo "Initializing replication from clone position"
191 # In case of container restart, attempt this at-most-once.
192 mv change_master_to.sql.in change_master_to.sql.orig
193 mysql --user=root --password=$MYSQL_ROOT_PASSWORD -h localhost <<EOF
194 $(<change_master_to.sql.orig),
195 MASTER_HOST="{{ template "common.name" . }}-0.{{ .Values.service.name }}.{{ include "common.namespace" . }}",
197 MASTER_PASSWORD="$MYSQL_ROOT_PASSWORD",
198 MASTER_CONNECT_RETRY=10;
203 # Start a server to send backups when requested by peers.
204 exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \
205 "xtrabackup --user=root --password=$MYSQL_ROOT_PASSWORD --backup --slave-info --stream=xbstream --host=localhost"
207 - name: {{ include "common.fullname" . }}-data
208 mountPath: /var/lib/mysql
211 mountPath: /etc/mysql/conf.d
217 name: {{ include "common.fullname" . }}-db-configmap
221 - name: {{ include "common.fullname" . }}-data
222 #{{ if not .Values.disableNfsProvisioner }}
223 volumeClaimTemplates:
225 name: {{ include "common.fullname" . }}-data
227 volume.beta.kubernetes.io/storage-class: "{{ include "common.fullname" . }}-data"
229 accessModes: ["ReadWriteMany"]
233 #{{ else if .Values.persistence.enabled }}
234 persistentVolumeClaim:
235 claimName: {{ include "common.fullname" . }}-data