Dominic Lunanuova | 50aafc5 | 2018-03-30 02:29:23 +0000 | [diff] [blame] | 1 | # PostgreSQL can be accessed via port 5432 on the following DNS name from within your cluster: |
| 2 | # {{ template "postgresql.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local |
| 3 | # |
| 4 | # To get your user password run: |
| 5 | # |
| 6 | # PGPASSWORD=$(kubectl get secret --namespace {{ .Values.global.nsPrefix }} {{ template "postgresql.fullname" . }} -o jsonpath="{.data.postgres-password}" | base64 --decode; echo) |
| 7 | # |
| 8 | # To connect to your database run the following command (using the env variable from above): |
| 9 | # |
| 10 | # kubectl run --namespace {{ .Values.global.nsPrefix }} {{ template "postgresql.fullname" . }}-client --restart=Never --rm --tty -i --image postgres \ |
| 11 | # --env "PGPASSWORD=$PGPASSWORD" \{{- if and (.Values.networkPolicy.enabled) (not .Values.networkPolicy.allowExternal) }} |
| 12 | # --labels="{{ template "postgresql.fullname" . }}-client=true" \{{- end }} |
| 13 | # --command -- psql -U {{ default "postgres" .Values.postgresUser }} \ |
| 14 | # -h {{ template "postgresql.fullname" . }} {{ default "postgres" .Values.postgresDatabase }} |
| 15 | # |
| 16 | # {{ if and (.Values.networkPolicy.enabled) (not .Values.networkPolicy.allowExternal) }} |
| 17 | # Note: Since NetworkPolicy is enabled, only pods with label |
| 18 | # {{ template "postgresql.fullname" . }}-client=true" |
| 19 | # will be able to connect to this PostgreSQL cluster. |
| 20 | # {{- end }} |
| 21 | # |
| 22 | # To connect to your database directly from outside the K8s cluster: |
| 23 | # {{- if contains "NodePort" .Values.service.type }} |
| 24 | # PGHOST=$(kubectl get nodes --namespace {{ .Values.global.nsPrefix }} -o jsonpath='{.items[0].status.addresses[0].address}') |
| 25 | # PGPORT=$(kubectl get svc --namespace {{ .Values.global.nsPrefix }} {{ template "postgresql.fullname" . }} -o jsonpath='{.spec.ports[0].nodePort}') |
| 26 | # |
| 27 | # {{- else if contains "ClusterIP" .Values.service.type }} |
| 28 | # PGHOST=127.0.0.1 |
| 29 | # PGPORT={{ default "5432" .Values.service.port }} |
| 30 | # |
| 31 | # # Execute the following commands to route the connection: |
| 32 | # export POD_NAME=$(kubectl get pods --namespace {{ .Values.global.nsPrefix }} -l "app={{ template "postgresql.fullname" . }}" -o jsonpath="{.items[0].metadata.name}") |
| 33 | # kubectl port-forward --namespace {{ .Values.global.nsPrefix }} $POD_NAME {{ default "5432" .Values.service.port }}:{{ default "5432" .Values.service.port }} |
| 34 | # |
| 35 | # {{- end }} |