From 15535e4a9eb691d985bb9ff032e4296a38ddc24f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20J=2E=20Salmer=C3=B3n-Garc=C3=ADa?= Date: Fri, 21 Dec 2018 01:14:02 +0100 Subject: [PATCH] [stable/postgresql] Add read-only connection to the replica slaves (#10186) Signed-off-by: Javier J. Salmeron Garcia --- stable/postgresql/Chart.yaml | 2 +- stable/postgresql/templates/NOTES.txt | 6 +++-- stable/postgresql/templates/svc-read.yaml | 31 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 stable/postgresql/templates/svc-read.yaml diff --git a/stable/postgresql/Chart.yaml b/stable/postgresql/Chart.yaml index ad2094a627..0ad9aa0e8b 100644 --- a/stable/postgresql/Chart.yaml +++ b/stable/postgresql/Chart.yaml @@ -1,5 +1,5 @@ name: postgresql -version: 3.5.0 +version: 3.6.0 appVersion: 10.6.0 description: Chart for PostgreSQL, an object-relational database management system (ORDBMS) with an emphasis on extensibility and on standards-compliance. keywords: diff --git a/stable/postgresql/templates/NOTES.txt b/stable/postgresql/templates/NOTES.txt index 329f5eaf1e..41c2210491 100644 --- a/stable/postgresql/templates/NOTES.txt +++ b/stable/postgresql/templates/NOTES.txt @@ -19,8 +19,10 @@ PostgreSQL can be accessed via port 5432 on the following DNS name from within your cluster: - {{ template "postgresql.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local - + {{ template "postgresql.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local - Read/Write connection +{{- if .Values.replication.enabled }} + {{ template "postgresql.fullname" . }}-read.{{ .Release.Namespace }}.svc.cluster.local - Read only connection +{{- end }} To get the password for "{{ .Values.postgresqlUsername }}" run: export POSTGRESQL_PASSWORD=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{ else }}{{ template "postgresql.fullname" . }}{{ end }} -o jsonpath="{.data.postgresql-password}" | base64 --decode) diff --git a/stable/postgresql/templates/svc-read.yaml b/stable/postgresql/templates/svc-read.yaml new file mode 100644 index 0000000000..6b2de778ab --- /dev/null +++ b/stable/postgresql/templates/svc-read.yaml @@ -0,0 +1,31 @@ +{{- if .Values.replication.enabled }} +apiVersion: v1 +kind: Service +metadata: + name: {{ template "postgresql.fullname" . }}-read + labels: + app: {{ template "postgresql.name" . }} + chart: {{ template "postgresql.chart" . }} + release: {{ .Release.Name | quote }} + heritage: {{ .Release.Service | quote }} +{{- with .Values.service.annotations }} + annotations: +{{ toYaml . | indent 4 }} +{{- end }} +spec: + type: {{ .Values.service.type }} + {{- if and .Values.service.loadBalancerIP (eq .Values.service.type "LoadBalancer") }} + loadBalancerIP: {{ .Values.service.loadBalancerIP }} + {{- end }} + ports: + - name: postgresql + port: {{ .Values.service.port }} + targetPort: postgresql + {{- if .Values.service.nodePort }} + nodePort: {{ .Values.service.nodePort }} + {{- end }} + selector: + app: {{ template "postgresql.name" . }} + release: {{ .Release.Name | quote }} + role: slave +{{- end }}