[stable/postgresql] namespace template helpers with chart name (#1777)

This commit is contained in:
kevinschumacher
2017-08-20 12:05:20 +05:30
committed by Dhilip
parent a96337bc2c
commit 1cd194bef9
8 changed files with 31 additions and 31 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
name: postgresql
version: 0.8.0
version: 0.8.1
description: Object-relational database management system (ORDBMS) with an emphasis on extensibility and on standards-compliance.
keywords:
- postgresql
+8 -8
View File
@@ -1,35 +1,35 @@
PostgreSQL can be accessed via port 5432 on the following DNS name from within your cluster:
{{ template "fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local
{{ template "postgresql.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local
To get your user password run:
PGPASSWORD=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath="{.data.postgres-password}" | base64 --decode; echo)
PGPASSWORD=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "postgresql.fullname" . }} -o jsonpath="{.data.postgres-password}" | base64 --decode; echo)
To connect to your database run the following command (using the env variable from above):
kubectl run {{ template "fullname" . }}-client --rm --tty -i --image postgres \
kubectl run {{ template "postgresql.fullname" . }}-client --rm --tty -i --image postgres \
--env "PGPASSWORD=$PGPASSWORD" \{{- if and (.Values.networkPolicy.enabled) (not .Values.networkPolicy.allowExternal) }}
--labels="{{ template "fullname" . }}-client=true" \{{- end }}
--labels="{{ template "postgresql.fullname" . }}-client=true" \{{- end }}
--command -- psql -U {{ default "postgres" .Values.postgresUser }} \
-h {{ template "fullname" . }} {{ default "postgres" .Values.postgresDatabase }}
-h {{ template "postgresql.fullname" . }} {{ default "postgres" .Values.postgresDatabase }}
{{ if and (.Values.networkPolicy.enabled) (not .Values.networkPolicy.allowExternal) }}
Note: Since NetworkPolicy is enabled, only pods with label
{{ template "fullname" . }}-client=true"
{{ template "postgresql.fullname" . }}-client=true"
will be able to connect to this PostgreSQL cluster.
{{- end }}
To connect to your database directly from outside the K8s cluster:
{{- if contains "NodePort" .Values.service.type }}
PGHOST=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath='{.items[0].status.addresses[0].address}')
PGPORT=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.spec.ports[0].nodePort}')
PGPORT=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "postgresql.fullname" . }} -o jsonpath='{.spec.ports[0].nodePort}')
{{- else if contains "ClusterIP" .Values.service.type }}
PGHOST=127.0.0.1
PGPORT={{ default "5432" .Values.service.port }}
# Execute the following commands to route the connection:
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "fullname" . }}" -o jsonpath="{.items[0].metadata.name}")
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "postgresql.fullname" . }}" -o jsonpath="{.items[0].metadata.name}")
kubectl port-forward $POD_NAME {{ default "5432" .Values.service.port }}:{{ default "5432" .Values.service.port }}
{{- end }}
+3 -3
View File
@@ -2,7 +2,7 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- define "postgresql.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
@@ -10,7 +10,7 @@ Expand the name of the chart.
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- define "postgresql.fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
@@ -18,7 +18,7 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
{{/*
Return the appropriate apiVersion for networkpolicy.
*/}}
{{- define "networkPolicy.apiVersion" -}}
{{- define "postgresql.networkPolicy.apiVersion" -}}
{{- if and (ge .Capabilities.KubeVersion.Minor "4") (le .Capabilities.KubeVersion.Minor "6") -}}
"extensions/v1beta1"
{{- else if ge .Capabilities.KubeVersion.Minor "7" -}}
+7 -7
View File
@@ -1,9 +1,9 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fullname" . }}
name: {{ template "postgresql.fullname" . }}
labels:
app: {{ template "fullname" . }}
app: {{ template "postgresql.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
@@ -11,10 +11,10 @@ spec:
template:
metadata:
labels:
app: {{ template "fullname" . }}
app: {{ template "postgresql.fullname" . }}
spec:
containers:
- name: {{ template "fullname" . }}
- name: {{ template "postgresql.fullname" . }}
image: "{{ .Values.image }}:{{ .Values.imageTag }}"
imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }}
env:
@@ -32,7 +32,7 @@ spec:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "fullname" . }}
name: {{ template "postgresql.fullname" . }}
key: postgres-password
- name: POD_IP
valueFrom: { fieldRef: { fieldPath: status.podIP } }
@@ -87,14 +87,14 @@ spec:
- name: data
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ .Values.persistence.existingClaim | default (include "fullname" .) }}
claimName: {{ .Values.persistence.existingClaim | default (include "postgresql.fullname" .) }}
{{- else }}
emptyDir: {}
{{- end }}
{{- if and .Values.metrics.enabled .Values.metrics.customMetrics }}
- name: custom-metrics
secret:
secretName: {{ template "fullname" . }}
secretName: {{ template "postgresql.fullname" . }}
items:
- key: custom-metrics.yaml
path: custom-metrics.yaml
@@ -1,17 +1,17 @@
{{- if .Values.networkPolicy.enabled }}
kind: NetworkPolicy
apiVersion: {{ template "networkPolicy.apiVersion" . }}
apiVersion: {{ template "postgresql.networkPolicy.apiVersion" . }}
metadata:
name: "{{ template "fullname" . }}"
name: "{{ template "postgresql.fullname" . }}"
labels:
app: {{ template "fullname" . }}
app: {{ template "postgresql.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
podSelector:
matchLabels:
app: "{{ template "fullname" . }}"
app: "{{ template "postgresql.fullname" . }}"
ingress:
# Allow inbound connections
- ports:
@@ -20,7 +20,7 @@ spec:
from:
- podSelector:
matchLabels:
{{ template "fullname" . }}-client: "true"
{{ template "postgresql.fullname" . }}-client: "true"
{{- end }}
# Allow prometheus scrapes
- ports:
+2 -2
View File
@@ -2,9 +2,9 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ template "fullname" . }}
name: {{ template "postgresql.fullname" . }}
labels:
app: {{ template "fullname" . }}
app: {{ template "postgresql.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
+2 -2
View File
@@ -1,9 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ template "fullname" . }}
name: {{ template "postgresql.fullname" . }}
labels:
app: {{ template "fullname" . }}
app: {{ template "postgresql.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
+3 -3
View File
@@ -1,9 +1,9 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "fullname" . }}
name: {{ template "postgresql.fullname" . }}
labels:
app: {{ template "fullname" . }}
app: {{ template "postgresql.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
@@ -23,4 +23,4 @@ spec:
{{ toYaml .Values.service.externalIPs | indent 4 }}
{{- end }}
selector:
app: {{ template "fullname" . }}
app: {{ template "postgresql.fullname" . }}