PostgreSQL can be accessed via port 5432 on the following DNS name from within your cluster:
{{ template "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)

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 \
   --env "PGPASSWORD=$PGPASSWORD" \
   --command -- psql -U {{ default "postgres" .Values.postgresUser }} \
   -h {{ template "fullname" . }} {{ default "postgres" .Values.postgresDatabase }}

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}')

   {{- 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}")
     kubectl port-forward $POD_NAME {{ default "5432" .Values.service.port }}:{{ default "5432" .Values.service.port }}

   {{- end }}