mirror of
https://github.com/bitnami/charts.git
synced 2026-03-08 00:37:41 +08:00
Add support for database replication
This commit is contained in:
15
bitnami/mysql/templates/master-configmap.yaml
Normal file
15
bitnami/mysql/templates/master-configmap.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
{{- if .Values.master.config }}
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: {{ template "master.fullname" . }}
|
||||
labels:
|
||||
app: {{ template "name" . }}
|
||||
component: "master"
|
||||
chart: {{ template "mysql.chart" . }}
|
||||
release: {{ .Release.Name | quote }}
|
||||
heritage: {{ .Release.Service | quote }}
|
||||
data:
|
||||
my.cnf: |-
|
||||
{{ .Values.master.config | indent 4 }}
|
||||
{{- end -}}
|
||||
178
bitnami/mysql/templates/master-statefulset.yaml
Normal file
178
bitnami/mysql/templates/master-statefulset.yaml
Normal file
@@ -0,0 +1,178 @@
|
||||
apiVersion: apps/v1beta1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: {{ template "master.fullname" . }}
|
||||
labels:
|
||||
app: "{{ template "name" . }}"
|
||||
chart: {{ template "mysql.chart" . }}
|
||||
component: "master"
|
||||
release: {{ .Release.Name | quote }}
|
||||
heritage: {{ .Release.Service | quote }}
|
||||
spec:
|
||||
serviceName: "{{ template "master.fullname" . }}"
|
||||
replicas: 1
|
||||
updateStrategy:
|
||||
type: RollingUpdate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: "{{ template "name" . }}"
|
||||
component: "master"
|
||||
release: "{{ .Release.Name }}"
|
||||
spec:
|
||||
{{- if eq .Values.master.antiAffinity "hard" }}
|
||||
affinity:
|
||||
podAntiAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
- topologyKey: "kubernetes.io/hostname"
|
||||
labelSelector:
|
||||
matchLabels:
|
||||
app: "{{ template "name" . }}"
|
||||
release: "{{ .Release.Name }}"
|
||||
{{- else if eq .Values.master.antiAffinity "soft" }}
|
||||
affinity:
|
||||
podAntiAffinity:
|
||||
preferredDuringSchedulingIgnoredDuringExecution:
|
||||
- weight: 1
|
||||
podAffinityTerm:
|
||||
topologyKey: kubernetes.io/hostname
|
||||
labelSelector:
|
||||
matchLabels:
|
||||
app: "{{ template "name" . }}"
|
||||
release: "{{ .Release.Name }}"
|
||||
{{- end }}
|
||||
{{- if .Values.image.pullSecrets }}
|
||||
imagePullSecrets:
|
||||
{{- range .Values.image.pullSecrets }}
|
||||
- name: {{ . }}
|
||||
{{- end}}
|
||||
{{- end }}
|
||||
containers:
|
||||
- name: "mysql"
|
||||
image: {{ template "mysql.image" . }}
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
|
||||
env:
|
||||
- name: MYSQL_ROOT_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ template "fullname" . }}
|
||||
key: mysql-root-password
|
||||
{{- if .Values.db.user }}
|
||||
- name: MYSQL_USER
|
||||
value: "{{ .Values.db.user }}"
|
||||
- name: MYSQL_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ template "fullname" . }}
|
||||
key: mysql-password
|
||||
{{- end }}
|
||||
- name: MYSQL_DATABASE
|
||||
value: "{{ .Values.db.name }}"
|
||||
{{- if .Values.replication.enabled }}
|
||||
- name: MYSQL_REPLICATION_MODE
|
||||
value: "master"
|
||||
- name: MYSQL_REPLICATION_USER
|
||||
value: "{{ .Values.replication.user }}"
|
||||
- name: MYSQL_REPLICATION_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ template "fullname" . }}
|
||||
key: mysql-replication-password
|
||||
{{- end }}
|
||||
ports:
|
||||
- name: mysql
|
||||
containerPort: 3306
|
||||
{{- if .Values.master.livenessProbe.enabled }}
|
||||
livenessProbe:
|
||||
exec:
|
||||
command: ["sh", "-c", "exec mysqladmin status -uroot -p$MYSQL_ROOT_PASSWORD"]
|
||||
initialDelaySeconds: {{ .Values.master.livenessProbe.initialDelaySeconds }}
|
||||
periodSeconds: {{ .Values.master.livenessProbe.periodSeconds }}
|
||||
timeoutSeconds: {{ .Values.master.livenessProbe.timeoutSeconds }}
|
||||
successThreshold: {{ .Values.master.livenessProbe.successThreshold }}
|
||||
failureThreshold: {{ .Values.master.livenessProbe.failureThreshold }}
|
||||
{{- end }}
|
||||
{{- if .Values.master.readinessProbe.enabled }}
|
||||
readinessProbe:
|
||||
exec:
|
||||
command: ["sh", "-c", "exec mysqladmin status -uroot -p$MYSQL_ROOT_PASSWORD"]
|
||||
initialDelaySeconds: {{ .Values.master.readinessProbe.initialDelaySeconds }}
|
||||
periodSeconds: {{ .Values.master.readinessProbe.periodSeconds }}
|
||||
timeoutSeconds: {{ .Values.master.readinessProbe.timeoutSeconds }}
|
||||
successThreshold: {{ .Values.master.readinessProbe.successThreshold }}
|
||||
failureThreshold: {{ .Values.master.readinessProbe.failureThreshold }}
|
||||
{{- end }}
|
||||
resources:
|
||||
{{ toYaml .Values.master.resources | indent 10 }}
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /bitnami/mysql
|
||||
{{- if .Values.master.config }}
|
||||
- name: config
|
||||
mountPath: /opt/bitnami/mysql/conf/my.cnf
|
||||
subPath: my.cnf
|
||||
{{- end }}
|
||||
{{- if .Values.metrics.enabled }}
|
||||
- name: metrics
|
||||
image: {{ template "metrics.image" . }}
|
||||
imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
|
||||
env:
|
||||
- name: MYSQL_ROOT_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ template "fullname" . }}
|
||||
key: mysql-root-password
|
||||
command: [ 'sh', '-c', 'DATA_SOURCE_NAME="root:$MYSQL_ROOT_PASSWORD@(localhost:3306)/" /bin/mysqld_exporter' ]
|
||||
ports:
|
||||
- name: metrics
|
||||
containerPort: 9104
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /metrics
|
||||
port: metrics
|
||||
initialDelaySeconds: 15
|
||||
timeoutSeconds: 5
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /metrics
|
||||
port: metrics
|
||||
initialDelaySeconds: 5
|
||||
timeoutSeconds: 1
|
||||
resources:
|
||||
{{ toYaml .Values.metrics.resources | indent 10 }}
|
||||
{{- end }}
|
||||
volumes:
|
||||
{{- if .Values.master.config }}
|
||||
- name: config
|
||||
configMap:
|
||||
name: {{ template "master.fullname" . }}
|
||||
{{- end }}
|
||||
{{- if .Values.master.persistence.enabled }}
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: data
|
||||
labels:
|
||||
app: "{{ template "name" . }}"
|
||||
chart: {{ template "mysql.chart" . }}
|
||||
component: "master"
|
||||
release: {{ .Release.Name | quote }}
|
||||
heritage: {{ .Release.Service | quote }}
|
||||
spec:
|
||||
accessModes:
|
||||
{{- range .Values.master.persistence.accessModes }}
|
||||
- {{ . | quote }}
|
||||
{{- end }}
|
||||
resources:
|
||||
requests:
|
||||
storage: {{ .Values.master.persistence.size | quote }}
|
||||
{{- if .Values.master.persistence.storageClass }}
|
||||
{{- if (eq "-" .Values.master.persistence.storageClass) }}
|
||||
storageClassName: ""
|
||||
{{- else }}
|
||||
storageClassName: {{ .Values.master.persistence.storageClass | quote }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
- name: "data"
|
||||
emptyDir: {}
|
||||
{{- end }}
|
||||
29
bitnami/mysql/templates/master-svc.yaml
Normal file
29
bitnami/mysql/templates/master-svc.yaml
Normal file
@@ -0,0 +1,29 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: {{ template "master.fullname" . }}
|
||||
labels:
|
||||
app: "{{ template "name" . }}"
|
||||
component: "master"
|
||||
chart: {{ template "mysql.chart" . }}
|
||||
release: {{ .Release.Name | quote }}
|
||||
heritage: {{ .Release.Service | quote }}
|
||||
{{- if .Values.metrics.enabled }}
|
||||
annotations:
|
||||
{{ toYaml .Values.metrics.annotations | indent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
type: {{ .Values.service.type }}
|
||||
ports:
|
||||
- name: mysql
|
||||
port: {{ .Values.service.port }}
|
||||
targetPort: mysql
|
||||
{{- if .Values.metrics.enabled }}
|
||||
- name: metrics
|
||||
port: 9104
|
||||
targetPort: metrics
|
||||
{{- end }}
|
||||
selector:
|
||||
app: "{{ template "name" . }}"
|
||||
component: "master"
|
||||
release: "{{ .Release.Name }}"
|
||||
15
bitnami/mysql/templates/slave-configmap.yaml
Normal file
15
bitnami/mysql/templates/slave-configmap.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
{{- if and .Values.replication.enabled .Values.slave.config }}
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: {{ template "slave.fullname" . }}
|
||||
labels:
|
||||
app: {{ template "name" . }}
|
||||
component: "slave"
|
||||
chart: {{ template "mysql.chart" . }}
|
||||
release: {{ .Release.Name | quote }}
|
||||
heritage: {{ .Release.Service | quote }}
|
||||
data:
|
||||
my.cnf: |-
|
||||
{{ .Values.slave.config | indent 4 }}
|
||||
{{- end }}
|
||||
189
bitnami/mysql/templates/slave-statefulset.yaml
Normal file
189
bitnami/mysql/templates/slave-statefulset.yaml
Normal file
@@ -0,0 +1,189 @@
|
||||
{{- if .Values.replication.enabled }}
|
||||
apiVersion: apps/v1beta1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: {{ template "slave.fullname" . }}
|
||||
labels:
|
||||
app: "{{ template "name" . }}"
|
||||
chart: {{ template "mysql.chart" . }}
|
||||
component: "slave"
|
||||
release: {{ .Release.Name | quote }}
|
||||
heritage: {{ .Release.Service | quote }}
|
||||
spec:
|
||||
serviceName: "{{ template "slave.fullname" . }}"
|
||||
replicas: {{ .Values.slave.replicas }}
|
||||
updateStrategy:
|
||||
type: RollingUpdate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: "{{ template "name" . }}"
|
||||
component: "slave"
|
||||
release: "{{ .Release.Name }}"
|
||||
spec:
|
||||
{{- if eq .Values.slave.antiAffinity "hard" }}
|
||||
affinity:
|
||||
podAntiAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
- topologyKey: "kubernetes.io/hostname"
|
||||
labelSelector:
|
||||
matchLabels:
|
||||
app: "{{ template "name" . }}"
|
||||
release: "{{ .Release.Name }}"
|
||||
{{- else if eq .Values.slave.antiAffinity "soft" }}
|
||||
affinity:
|
||||
podAntiAffinity:
|
||||
preferredDuringSchedulingIgnoredDuringExecution:
|
||||
- weight: 1
|
||||
podAffinityTerm:
|
||||
topologyKey: kubernetes.io/hostname
|
||||
labelSelector:
|
||||
matchLabels:
|
||||
app: "{{ template "name" . }}"
|
||||
release: "{{ .Release.Name }}"
|
||||
{{- end }}
|
||||
{{- if .Values.image.pullSecrets }}
|
||||
imagePullSecrets:
|
||||
{{- range .Values.image.pullSecrets }}
|
||||
- name: {{ . }}
|
||||
{{- end}}
|
||||
{{- end }}
|
||||
containers:
|
||||
- name: "mysql"
|
||||
image: {{ template "mysql.image" . }}
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
|
||||
env:
|
||||
- name: MYSQL_ROOT_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ template "fullname" . }}
|
||||
key: mysql-root-password
|
||||
{{- if .Values.db.user }}
|
||||
- name: MYSQL_USER
|
||||
value: "{{ .Values.db.user }}"
|
||||
- name: MYSQL_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ template "fullname" . }}
|
||||
key: mysql-password
|
||||
{{- end }}
|
||||
- name: MYSQL_DATABASE
|
||||
value: "{{ .Values.db.name }}"
|
||||
- name: MYSQL_REPLICATION_MODE
|
||||
value: "slave"
|
||||
- name: MYSQL_MASTER_HOST
|
||||
value: {{ template "master.fullname" . }}
|
||||
- name: MYSQL_MASTER_PORT
|
||||
value: "3306"
|
||||
- name: MYSQL_MASTER_USER
|
||||
value: "root"
|
||||
- name: MYSQL_MASTER_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ template "fullname" . }}
|
||||
key: mysql-root-password
|
||||
- name: MYSQL_REPLICATION_USER
|
||||
value: "{{ .Values.replication.user }}"
|
||||
- name: MYSQL_REPLICATION_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ template "fullname" . }}
|
||||
key: mysql-replication-password
|
||||
ports:
|
||||
- name: mysql
|
||||
containerPort: 3306
|
||||
{{- if .Values.slave.livenessProbe.enabled }}
|
||||
livenessProbe:
|
||||
exec:
|
||||
command: ["sh", "-c", "exec mysqladmin status -uroot -p$MYSQL_ROOT_PASSWORD"]
|
||||
initialDelaySeconds: {{ .Values.slave.livenessProbe.initialDelaySeconds }}
|
||||
periodSeconds: {{ .Values.slave.livenessProbe.periodSeconds }}
|
||||
timeoutSeconds: {{ .Values.slave.livenessProbe.timeoutSeconds }}
|
||||
successThreshold: {{ .Values.slave.livenessProbe.successThreshold }}
|
||||
failureThreshold: {{ .Values.slave.livenessProbe.failureThreshold }}
|
||||
{{- end }}
|
||||
{{- if .Values.slave.readinessProbe.enabled }}
|
||||
readinessProbe:
|
||||
exec:
|
||||
command: ["sh", "-c", "exec mysqladmin status -uroot -p$MYSQL_ROOT_PASSWORD"]
|
||||
initialDelaySeconds: {{ .Values.slave.readinessProbe.initialDelaySeconds }}
|
||||
periodSeconds: {{ .Values.slave.readinessProbe.periodSeconds }}
|
||||
timeoutSeconds: {{ .Values.slave.readinessProbe.timeoutSeconds }}
|
||||
successThreshold: {{ .Values.slave.readinessProbe.successThreshold }}
|
||||
failureThreshold: {{ .Values.slave.readinessProbe.failureThreshold }}
|
||||
{{- end }}
|
||||
resources:
|
||||
{{ toYaml .Values.slave.resources | indent 10 }}
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /bitnami/mysql
|
||||
{{- if .Values.slave.config }}
|
||||
- name: config
|
||||
mountPath: /opt/bitnami/mysql/conf/my.cnf
|
||||
subPath: my.cnf
|
||||
{{- end }}
|
||||
{{- if .Values.metrics.enabled }}
|
||||
- name: metrics
|
||||
image: {{ template "metrics.image" . }}
|
||||
imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
|
||||
env:
|
||||
- name: MYSQL_ROOT_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ template "fullname" . }}
|
||||
key: mysql-root-password
|
||||
command: [ 'sh', '-c', 'DATA_SOURCE_NAME="root:$MYSQL_ROOT_PASSWORD@(localhost:3306)/" /bin/mysqld_exporter' ]
|
||||
ports:
|
||||
- name: metrics
|
||||
containerPort: 9104
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /metrics
|
||||
port: metrics
|
||||
initialDelaySeconds: 15
|
||||
timeoutSeconds: 5
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /metrics
|
||||
port: metrics
|
||||
initialDelaySeconds: 5
|
||||
timeoutSeconds: 1
|
||||
resources:
|
||||
{{ toYaml .Values.metrics.resources | indent 10 }}
|
||||
{{- end }}
|
||||
volumes:
|
||||
{{- if .Values.slave.config }}
|
||||
- name: config
|
||||
configMap:
|
||||
name: {{ template "slave.fullname" . }}
|
||||
{{- end }}
|
||||
{{- if .Values.slave.persistence.enabled }}
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: data
|
||||
labels:
|
||||
app: "{{ template "name" . }}"
|
||||
chart: {{ template "mysql.chart" . }}
|
||||
component: "slave"
|
||||
release: {{ .Release.Name | quote }}
|
||||
heritage: {{ .Release.Service | quote }}
|
||||
spec:
|
||||
accessModes:
|
||||
{{- range .Values.slave.persistence.accessModes }}
|
||||
- {{ . | quote }}
|
||||
{{- end }}
|
||||
resources:
|
||||
requests:
|
||||
storage: {{ .Values.slave.persistence.size | quote }}
|
||||
{{- if .Values.slave.persistence.storageClass }}
|
||||
{{- if (eq "-" .Values.slave.persistence.storageClass) }}
|
||||
storageClassName: ""
|
||||
{{- else }}
|
||||
storageClassName: {{ .Values.slave.persistence.storageClass | quote }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
- name: "data"
|
||||
emptyDir: {}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
31
bitnami/mysql/templates/slave-svc.yaml
Normal file
31
bitnami/mysql/templates/slave-svc.yaml
Normal file
@@ -0,0 +1,31 @@
|
||||
{{- if .Values.replication.enabled }}
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: {{ template "slave.fullname" . }}
|
||||
labels:
|
||||
app: "{{ template "name" . }}"
|
||||
chart: {{ template "mysql.chart" . }}
|
||||
component: "slave"
|
||||
release: {{ .Release.Name | quote }}
|
||||
heritage: {{ .Release.Service | quote }}
|
||||
{{- if .Values.metrics.enabled }}
|
||||
annotations:
|
||||
{{ toYaml .Values.metrics.annotations | indent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
type: {{ .Values.service.type }}
|
||||
ports:
|
||||
- name: mysql
|
||||
port: {{ .Values.service.port }}
|
||||
targetPort: mysql
|
||||
{{- if .Values.metrics.enabled }}
|
||||
- name: metrics
|
||||
port: 9104
|
||||
targetPort: metrics
|
||||
{{- end }}
|
||||
selector:
|
||||
app: "{{ template "name" . }}"
|
||||
component: "slave"
|
||||
release: "{{ .Release.Name }}"
|
||||
{{- end }}
|
||||
Reference in New Issue
Block a user