From 60fca4a0350dca3534dc1c07e59a67ea10fb9535 Mon Sep 17 00:00:00 2001 From: Beltran Rueda Date: Fri, 6 Apr 2018 12:21:44 +0000 Subject: [PATCH] Added support for configMap & persistVolume for slaves --- incubator/mariadb-cluster/templates/NOTES.txt | 4 +++ .../templates/master-configmap.yaml | 14 +++++++++ .../templates/master-deploy.yaml | 2 +- .../templates/slave-configmap.yaml | 16 ++++++++++ .../templates/slave-deploy.yaml | 13 ++++++++ .../mariadb-cluster/templates/slave-pvc.yaml | 28 +++++++++++++++++ incubator/mariadb-cluster/values.yaml | 30 ++++++++++++++----- 7 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 incubator/mariadb-cluster/templates/master-configmap.yaml create mode 100644 incubator/mariadb-cluster/templates/slave-configmap.yaml create mode 100644 incubator/mariadb-cluster/templates/slave-pvc.yaml diff --git a/incubator/mariadb-cluster/templates/NOTES.txt b/incubator/mariadb-cluster/templates/NOTES.txt index 6c3391c44..ed6ee9260 100644 --- a/incubator/mariadb-cluster/templates/NOTES.txt +++ b/incubator/mariadb-cluster/templates/NOTES.txt @@ -8,7 +8,9 @@ Tip: Services: echo Master: {{ template "master.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.service.port }} +{{- if .Values.replication.enabled }} echo Slave: {{ template "slave.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.service.port }} +{{- end }} Administrator credentials: @@ -25,6 +27,8 @@ To connect to your database mysql -h {{ template "master.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local -uroot -p {{ .Values.db.name }} +{{- if .Values.replication.enabled }} 3. To connect to slave service (read-only): mysql -h {{ template "slave.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local -uroot -p {{ .Values.db.name }} +{{- end }} diff --git a/incubator/mariadb-cluster/templates/master-configmap.yaml b/incubator/mariadb-cluster/templates/master-configmap.yaml new file mode 100644 index 000000000..3795b3d4b --- /dev/null +++ b/incubator/mariadb-cluster/templates/master-configmap.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "master.fullname" . }} + labels: + app: {{ template "master.fullname" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" +data: + my.cnf: |- +{{- if .Values.master.config }} +{{ .Values.master.config | indent 4 }} +{{- end -}} diff --git a/incubator/mariadb-cluster/templates/master-deploy.yaml b/incubator/mariadb-cluster/templates/master-deploy.yaml index ed007943f..fc82fdf1a 100644 --- a/incubator/mariadb-cluster/templates/master-deploy.yaml +++ b/incubator/mariadb-cluster/templates/master-deploy.yaml @@ -132,7 +132,7 @@ spec: volumes: - name: config configMap: - name: {{ template "fullname" . }} + name: {{ template "master.fullname" . }} - name: data {{- if .Values.master.persistence.enabled }} persistentVolumeClaim: diff --git a/incubator/mariadb-cluster/templates/slave-configmap.yaml b/incubator/mariadb-cluster/templates/slave-configmap.yaml new file mode 100644 index 000000000..508da7e38 --- /dev/null +++ b/incubator/mariadb-cluster/templates/slave-configmap.yaml @@ -0,0 +1,16 @@ +{{- if .Values.replication.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "slave.fullname" . }} + labels: + app: {{ template "slave.fullname" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" +data: + my.cnf: |- +{{- if .Values.slave.config }} +{{ .Values.slave.config | indent 4 }} +{{- end -}} +{{- end -}} diff --git a/incubator/mariadb-cluster/templates/slave-deploy.yaml b/incubator/mariadb-cluster/templates/slave-deploy.yaml index 482672714..d27b62ac4 100644 --- a/incubator/mariadb-cluster/templates/slave-deploy.yaml +++ b/incubator/mariadb-cluster/templates/slave-deploy.yaml @@ -105,6 +105,11 @@ spec: volumeMounts: - name: data mountPath: /bitnami +{{- if .Values.slave.config }} + - name: config + mountPath: /opt/bitnami/mariadb/conf/my.cnf + subPath: my.cnf +{{- end }} {{- if .Values.metrics.enabled }} - name: metrics image: "{{ .Values.metrics.image }}:{{ .Values.metrics.imageTag }}" @@ -135,8 +140,16 @@ spec: {{ toYaml .Values.metrics.resources | indent 10 }} {{- end }} volumes: + - name: config + configMap: + name: {{ template "slave.fullname" . }} - name: data + {{- if .Values.slave.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ template "slave.fullname" . }}-data + {{- else }} emptyDir: {} + {{- end }} --- apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler diff --git a/incubator/mariadb-cluster/templates/slave-pvc.yaml b/incubator/mariadb-cluster/templates/slave-pvc.yaml new file mode 100644 index 000000000..8e20f3edd --- /dev/null +++ b/incubator/mariadb-cluster/templates/slave-pvc.yaml @@ -0,0 +1,28 @@ +{{- if and (.Values.slave.persistence.enabled) (.Values.replication.enabled) }} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ template "slave.fullname" . }}-data + labels: + app: "{{ template "name" . }}" + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" +{{- if .Values.slave.persistence.annotations }} + annotations: +{{ toYaml .Values.slave.persistence.annotations | indent 2 }} +{{- end }} +spec: + accessModes: +{{ toYaml .Values.slave.persistence.accessModes | indent 2 }} + resources: + requests: + storage: "{{ .Values.slave.persistence.size }}" +{{- if .Values.slave.persistence.storageClass }} +{{- if (eq "-" .Values.slave.persistence.storageClass) }} + storageClassName: "" +{{- else }} + storageClassName: "{{ .Values.slave.persistence.storageClass }}" +{{- end }} +{{- end }} +{{- end }} diff --git a/incubator/mariadb-cluster/values.yaml b/incubator/mariadb-cluster/values.yaml index 0ced75664..fdcebc67e 100644 --- a/incubator/mariadb-cluster/values.yaml +++ b/incubator/mariadb-cluster/values.yaml @@ -44,7 +44,7 @@ db: replication: ## Enable replication - enabled: false + enabled: true ## MariaDB replication user ## ref: https://github.com/bitnami/bitnami-docker-mariadb#setting-up-a-replication-cluster ## @@ -82,12 +82,12 @@ master: ## Persistent Volume size ## size: 8Gi - ## Configure MySQL with a custom my.cnf file - ## ref: https://mysql.com/kb/en/mysql/configuring-mysql-with-mycnf/#example-of-configuration-file - ## - ## config: |- - ## [mysqld] - ## skip-name-resolve + ## Configure MySQL with a custom my.cnf file + ## ref: https://mysql.com/kb/en/mysql/configuring-mysql-with-mycnf/#example-of-configuration-file + ## + # config: |- + # [mysqld] + # skip-name-resolve ## ## Configure master resource requests and limits @@ -103,6 +103,22 @@ slave: max: 3 target: cpuPercentage: 75 + persistence: + ## If true, use a Persistent Volume Claim, If false, use emptyDir + ## + enabled: false + # storageClass: "-" + annotations: + accessModes: + - ReadWriteOnce + ## Persistent Volume size + ## + size: 8Gi + ## Configure MySQL with a custom my.cnf file + # config: |- + # [mysqld] + # skip-name-resolve + ## ## Configure slave resource requests and limits ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ ##