From a52607218c7aa1cd4f5d0ee27b89019d245ef1c2 Mon Sep 17 00:00:00 2001 From: pmint93 Date: Tue, 7 Nov 2023 22:04:25 +0700 Subject: [PATCH 1/4] Init pgbouncer chart from example template --- charts/pgbouncer/.helmignore | 23 ++++++ charts/pgbouncer/Chart.yaml | 24 ++++++ charts/pgbouncer/templates/NOTES.txt | 22 +++++ charts/pgbouncer/templates/_helpers.tpl | 62 ++++++++++++++ charts/pgbouncer/templates/deployment.yaml | 61 ++++++++++++++ charts/pgbouncer/templates/ingress.yaml | 61 ++++++++++++++ charts/pgbouncer/templates/service.yaml | 15 ++++ .../templates/tests/test-connection.yaml | 15 ++++ charts/pgbouncer/values.yaml | 82 +++++++++++++++++++ 9 files changed, 365 insertions(+) create mode 100644 charts/pgbouncer/.helmignore create mode 100644 charts/pgbouncer/Chart.yaml create mode 100644 charts/pgbouncer/templates/NOTES.txt create mode 100644 charts/pgbouncer/templates/_helpers.tpl create mode 100644 charts/pgbouncer/templates/deployment.yaml create mode 100644 charts/pgbouncer/templates/ingress.yaml create mode 100644 charts/pgbouncer/templates/service.yaml create mode 100644 charts/pgbouncer/templates/tests/test-connection.yaml create mode 100644 charts/pgbouncer/values.yaml diff --git a/charts/pgbouncer/.helmignore b/charts/pgbouncer/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/pgbouncer/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/pgbouncer/Chart.yaml b/charts/pgbouncer/Chart.yaml new file mode 100644 index 0000000..68b9820 --- /dev/null +++ b/charts/pgbouncer/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: pgbouncer +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/charts/pgbouncer/templates/NOTES.txt b/charts/pgbouncer/templates/NOTES.txt new file mode 100644 index 0000000..5a3a417 --- /dev/null +++ b/charts/pgbouncer/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "pgbouncer.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "pgbouncer.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "pgbouncer.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "pgbouncer.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/pgbouncer/templates/_helpers.tpl b/charts/pgbouncer/templates/_helpers.tpl new file mode 100644 index 0000000..5148fe5 --- /dev/null +++ b/charts/pgbouncer/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "pgbouncer.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +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). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "pgbouncer.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "pgbouncer.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "pgbouncer.labels" -}} +helm.sh/chart: {{ include "pgbouncer.chart" . }} +{{ include "pgbouncer.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "pgbouncer.selectorLabels" -}} +app.kubernetes.io/name: {{ include "pgbouncer.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "pgbouncer.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "pgbouncer.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/pgbouncer/templates/deployment.yaml b/charts/pgbouncer/templates/deployment.yaml new file mode 100644 index 0000000..ee73335 --- /dev/null +++ b/charts/pgbouncer/templates/deployment.yaml @@ -0,0 +1,61 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "pgbouncer.fullname" . }} + labels: + {{- include "pgbouncer.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "pgbouncer.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "pgbouncer.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "pgbouncer.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/pgbouncer/templates/ingress.yaml b/charts/pgbouncer/templates/ingress.yaml new file mode 100644 index 0000000..0edf229 --- /dev/null +++ b/charts/pgbouncer/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "pgbouncer.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "pgbouncer.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/pgbouncer/templates/service.yaml b/charts/pgbouncer/templates/service.yaml new file mode 100644 index 0000000..1a9909a --- /dev/null +++ b/charts/pgbouncer/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "pgbouncer.fullname" . }} + labels: + {{- include "pgbouncer.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "pgbouncer.selectorLabels" . | nindent 4 }} diff --git a/charts/pgbouncer/templates/tests/test-connection.yaml b/charts/pgbouncer/templates/tests/test-connection.yaml new file mode 100644 index 0000000..8eddb8a --- /dev/null +++ b/charts/pgbouncer/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "pgbouncer.fullname" . }}-test-connection" + labels: + {{- include "pgbouncer.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "pgbouncer.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/pgbouncer/values.yaml b/charts/pgbouncer/values.yaml new file mode 100644 index 0000000..0b0d7a4 --- /dev/null +++ b/charts/pgbouncer/values.yaml @@ -0,0 +1,82 @@ +# Default values for pgbouncer. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} From 84e314e852f09a6f8daaf4f1161065ecd7da21c5 Mon Sep 17 00:00:00 2001 From: pmint93 Date: Fri, 10 Nov 2023 15:08:51 +0700 Subject: [PATCH 2/4] PGBouncer chart v0.1.0 --- charts/pgbouncer/Chart.yaml | 28 +- charts/pgbouncer/templates/NOTES.txt | 46 +- charts/pgbouncer/templates/_helpers.tpl | 11 - .../templates/_pgbouncer-other.ini.tpl | 5 + charts/pgbouncer/templates/_pgbouncer.ini.tpl | 400 ++++++++++++++++++ charts/pgbouncer/templates/_userlist.txt.tpl | 5 + charts/pgbouncer/templates/configmap.yaml | 13 + charts/pgbouncer/templates/deployment.yaml | 41 +- charts/pgbouncer/templates/ingress.yaml | 61 --- charts/pgbouncer/templates/service.yaml | 4 +- .../templates/tests/test-connection.yaml | 15 - charts/pgbouncer/values.yaml | 88 ++-- 12 files changed, 535 insertions(+), 182 deletions(-) create mode 100644 charts/pgbouncer/templates/_pgbouncer-other.ini.tpl create mode 100644 charts/pgbouncer/templates/_pgbouncer.ini.tpl create mode 100644 charts/pgbouncer/templates/_userlist.txt.tpl create mode 100644 charts/pgbouncer/templates/configmap.yaml delete mode 100644 charts/pgbouncer/templates/ingress.yaml delete mode 100644 charts/pgbouncer/templates/tests/test-connection.yaml diff --git a/charts/pgbouncer/Chart.yaml b/charts/pgbouncer/Chart.yaml index 68b9820..4745a64 100644 --- a/charts/pgbouncer/Chart.yaml +++ b/charts/pgbouncer/Chart.yaml @@ -1,24 +1,10 @@ apiVersion: v2 name: pgbouncer -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. +version: "0.1.0" +description: A Helm chart for Pgbouncer type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -# Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.0 - -# This is the version number of the application being deployed. This version number should be -# incremented each time you make changes to the application. Versions are not expected to -# follow Semantic Versioning. They should reflect the version the application is using. -# It is recommended to use it with quotes. -appVersion: "1.16.0" +home: https://github.com/pmint93/helm-charts +maintainers: +- name: pmint93 + url: https://github.com/pmint93 +appVersion: "v1.21.0" diff --git a/charts/pgbouncer/templates/NOTES.txt b/charts/pgbouncer/templates/NOTES.txt index 5a3a417..d84d272 100644 --- a/charts/pgbouncer/templates/NOTES.txt +++ b/charts/pgbouncer/templates/NOTES.txt @@ -1,22 +1,32 @@ -1. Get the application URL by running these commands: -{{- if .Values.ingress.enabled }} -{{- range $host := .Values.ingress.hosts }} - {{- range .paths }} - http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} - {{- end }} -{{- end }} -{{- else if contains "NodePort" .Values.service.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "pgbouncer.fullname" . }}) - export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") - echo http://$NODE_IP:$NODE_PORT +PGBouncer has been installed! + +{{- if contains "NodePort" .Values.service.type }} + +PGBouncer is exposed as a `NodePort` type service. +Get the address by running these commands: + + export NODE_PORT=$(kubectl --namespace {{ .Release.Namespace }} get services -o jsonpath="{.spec.ports[0].nodePort}" {{ include "pgbouncer.fullname" . }}) + export NODE_IP=$(kubectl --namespace {{ .Release.Namespace }} get nodes -o jsonpath="{.items[0].status.addresses[1].address}") + + echo "Connect to PGBouncer by using IP address: $NODE_IP and port number: $NODE_PORT" + {{- else if contains "LoadBalancer" .Values.service.type }} - NOTE: It may take a few minutes for the LoadBalancer IP to be available. - You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "pgbouncer.fullname" . }}' + +PGBouncer is exposed as a `LoadBalancer` type service. +It may take a few minutes for the LoadBalancer IP to be available. +You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "pgbouncer.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "pgbouncer.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") - echo http://$SERVICE_IP:{{ .Values.service.port }} + echo "Connect to PGBouncer by using IP address: $SERVICE_IP and port number: {{ .Values.service.port }}" + {{- else if contains "ClusterIP" .Values.service.type }} - export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "pgbouncer.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") - export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") - echo "Visit http://127.0.0.1:8080 to use your application" - kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT + +PGBouncer is exposed as a `ClusterIP` type service. +Get the address by running these commands: + + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "pgbouncer.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Connect to PGBouncer by using IP address: 127.0.0.1 and port number: 5432" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 5432:$CONTAINER_PORT + {{- end }} diff --git a/charts/pgbouncer/templates/_helpers.tpl b/charts/pgbouncer/templates/_helpers.tpl index 5148fe5..ed5bdb7 100644 --- a/charts/pgbouncer/templates/_helpers.tpl +++ b/charts/pgbouncer/templates/_helpers.tpl @@ -49,14 +49,3 @@ Selector labels app.kubernetes.io/name: {{ include "pgbouncer.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} - -{{/* -Create the name of the service account to use -*/}} -{{- define "pgbouncer.serviceAccountName" -}} -{{- if .Values.serviceAccount.create }} -{{- default (include "pgbouncer.fullname" .) .Values.serviceAccount.name }} -{{- else }} -{{- default "default" .Values.serviceAccount.name }} -{{- end }} -{{- end }} diff --git a/charts/pgbouncer/templates/_pgbouncer-other.ini.tpl b/charts/pgbouncer/templates/_pgbouncer-other.ini.tpl new file mode 100644 index 0000000..f0d4e38 --- /dev/null +++ b/charts/pgbouncer/templates/_pgbouncer-other.ini.tpl @@ -0,0 +1,5 @@ +{{- define "pgbouncer-other.ini" -}} +{{- range $k, $v := .Values.extraSettings -}} +{{ $k }} = {{ $v }} +{{- end -}} +{{- end -}} diff --git a/charts/pgbouncer/templates/_pgbouncer.ini.tpl b/charts/pgbouncer/templates/_pgbouncer.ini.tpl new file mode 100644 index 0000000..57a0d0e --- /dev/null +++ b/charts/pgbouncer/templates/_pgbouncer.ini.tpl @@ -0,0 +1,400 @@ +{{- define "pgbouncer.ini" -}} +;;; +;;; PgBouncer configuration file +;;; + +;; database name = connect string +;; +;; connect string params: +;; dbname= host= port= user= password= auth_user= +;; client_encoding= datestyle= timezone= +;; pool_size= reserve_pool= max_db_connections= +;; pool_mode= connect_query= application_name= +[databases] +{{- range $k, $v := .Values.databases }} +{{ $k }} = {{ $v }} +{{- end }} + +;; foodb over Unix socket +;foodb = + +;; redirect bardb to bazdb on localhost +;bardb = host=localhost dbname=bazdb + +;; access to dest database will go with single user +;forcedb = host=localhost port=300 user=baz password=foo client_encoding=UNICODE datestyle=ISO connect_query='SELECT 1' + +;; use custom pool sizes +;nondefaultdb = pool_size=50 reserve_pool=10 + +;; use auth_user with auth_query if user not present in auth_file +;; auth_user must exist in auth_file +; foodb = auth_user=bar + +;; run auth_query on a specific database. +; bardb = auth_dbname=foo + +;; fallback connect string +;* = host=testserver + +;; User-specific configuration +[users] +{{- range $user := .Values.users }} +{{- with $user.options }} +{{ $user.name | quote }} ={{ if $user.pool_mode }} pool_mode={{ $user.pool_mode }}{{end}} {{ if $user.max_user_connections }} max_user_connections={{ $user.max_user_connections }}{{end}} +{{- end }} +{{- end }} + +;user1 = pool_mode=transaction max_user_connections=10 + +;; Configuration section +[pgbouncer] + +;;; +;;; Administrative settings +;;; + +; logfile = /var/log/pgbouncer/pgbouncer.log +; pidfile = /var/run/pgbouncer/pgbouncer.pid + +;;; +;;; Where to wait for clients +;;; + +;; IP address or * which means all IPs +listen_addr = 0.0.0.0 +listen_port = 5432 + +;; Unix socket is also used for -R. +;; On Debian it should be /var/run/postgresql +;unix_socket_dir = /tmp +;unix_socket_mode = 0777 +;unix_socket_group = + +;; The peer id used to identify this pgbouncer process in a group of pgbouncer +;; processes that are peered together. When set to 0 pgbouncer peering is disabled +;peer_id = 0 + +;;; +;;; TLS settings for accepting clients +;;; + +;; disable, allow, require, verify-ca, verify-full +;client_tls_sslmode = disable + +;; Path to file that contains trusted CA certs +;client_tls_ca_file = + +;; Private key and cert to present to clients. +;; Required for accepting TLS connections from clients. +;client_tls_key_file = +;client_tls_cert_file = + +;; default, secure, fast, normal, +;client_tls_ciphers = default + +;; all, secure, tlsv1.0, tlsv1.1, tlsv1.2, tlsv1.3 +;client_tls_protocols = secure + +;; none, auto, legacy +;client_tls_dheparams = auto + +;; none, auto, +;client_tls_ecdhcurve = auto + +;;; +;;; TLS settings for connecting to backend databases +;;; + +;; disable, allow, require, verify-ca, verify-full +;server_tls_sslmode = disable + +;; Path to that contains trusted CA certs +;server_tls_ca_file = + +;; Private key and cert to present to backend. +;; Needed only if backend server require client cert. +;server_tls_key_file = +;server_tls_cert_file = + +;; all, secure, tlsv1.0, tlsv1.1, tlsv1.2, tlsv1.3 +;server_tls_protocols = secure + +;; default, secure, fast, normal, +;server_tls_ciphers = default + +;;; +;;; Authentication settings +;;; + +;; any, trust, plain, md5, cert, hba, pam +auth_type = {{ .Values.settings.auth_type }} +auth_file = /etc/pgbouncer/userlist.txt + +;; Path to HBA-style auth config +;auth_hba_file = + +{{- with .Values.settings.auth_user }} +auth_user = {{ . }} +{{- end }} + +;; Query to use to fetch password from database. Result +;; must have 2 columns - username and password hash. +{{- with .Values.settings.auth_query }} +auth_query = {{ . }} +{{- end }} + +;; Authentication database that can be set globally to run "auth_query". +;auth_dbname = + +;;; +;;; Users allowed into database 'pgbouncer' +;;; + +;; comma-separated list of users who are allowed to change settings +;admin_users = user2, someadmin, otheradmin + +;; comma-separated list of users who are just allowed to use SHOW command +;stats_users = stats, root + +;;; +;;; Pooler personality questions +;;; + +;; When server connection is released back to pool: +;; session - after client disconnects (default) +;; transaction - after transaction finishes +;; statement - after statement finishes +pool_mode = {{ .Values.settings.pool_mode | default "session" }} + +;; Number of prepared statements to cache on a server connection (zero value +;; disables support of prepared statements). +;max_prepared_statements = 0 + +;; Query for cleaning connection immediately after releasing from +;; client. No need to put ROLLBACK here, pgbouncer does not reuse +;; connections where transaction is left open. +;server_reset_query = DISCARD ALL + +;; Whether server_reset_query should run in all pooling modes. If it +;; is off, server_reset_query is used only for session-pooling. +;server_reset_query_always = 0 + +;; Comma-separated list of parameters to track per client. The +;; Postgres parameters listed here will be cached per client by +;; pgbouncer and restored in server everytime the client runs a query. +;track_extra_parameters = IntervalStyle + +;; Comma-separated list of parameters to ignore when given in startup +;; packet. Newer JDBC versions require the extra_float_digits here. +;ignore_startup_parameters = extra_float_digits + +;; When taking idle server into use, this query is run first. +;server_check_query = select 1 + +;; If server was used more recently that this many seconds ago, +;; skip the check query. Value 0 may or may not run in immediately. +;server_check_delay = 30 + +;; Close servers in session pooling mode after a RECONNECT, RELOAD, +;; etc. when they are idle instead of at the end of the session. +;server_fast_close = 0 + +;; Use as application_name on server. +;application_name_add_host = 0 + +;; Period for updating aggregated stats. +;stats_period = 60 + +;;; +;;; Connection limits +;;; + +;; Total number of clients that can connect +max_client_conn = {{ .Values.connectionLimits.max_client_conn }} + +;; Default pool size. 20 is good number when transaction pooling +;; is in use, in session pooling it needs to be the number of +;; max clients you want to handle at any moment +default_pool_size = {{ .Values.connectionLimits.default_pool_size }} + +;; Minimum number of server connections to keep in pool. +min_pool_size = {{ .Values.connectionLimits.min_pool_size }} + +; how many additional connection to allow in case of trouble +reserve_pool_size = {{ .Values.connectionLimits.reserve_pool_size }} + +;; If a clients needs to wait more than this many seconds, use reserve +;; pool. +reserve_pool_timeout = {{ .Values.connectionLimits.reserve_pool_timeout }} + +;; Maximum number of server connections for a database +;max_db_connections = 0 + +;; Maximum number of server connections for a user +;max_user_connections = 0 + +;; If off, then server connections are reused in LIFO manner +;server_round_robin = 0 + +;;; +;;; Logging +;;; + +;; Syslog settings +;syslog = 0 +;syslog_facility = daemon +;syslog_ident = pgbouncer + +;; log if client connects or server connection is made +log_connections = {{ .Values.logging.log_connections }} + +;; log if and why connection was closed +log_disconnections = {{ .Values.logging.log_disconnections }} + +;; log error messages pooler sends to clients +log_pooler_errors = {{ .Values.logging.log_pooler_errors }} + +;; write aggregated stats into log +log_stats = {{ .Values.logging.log_stats }} + +;; Logging verbosity. Same as -v switch on command line. +verbose = {{ .Values.logging.verbose }} + +;;; +;;; Timeouts +;;; + +;; Close server connection if its been connected longer. +;server_lifetime = 3600 + +;; Close server connection if its not been used in this time. Allows +;; to clean unnecessary connections from pool after peak. +;server_idle_timeout = 600 + +;; Cancel connection attempt if server does not answer takes longer. +;server_connect_timeout = 15 + +;; If server login failed (server_connect_timeout or auth failure) +;; then wait this many second before trying again. +;server_login_retry = 15 + +;; Dangerous. Server connection is closed if query does not return in +;; this time. Should be used to survive network problems, _not_ as +;; statement_timeout. (default: 0) +;query_timeout = 0 + +;; Dangerous. Client connection is closed if the query is not +;; assigned to a server in this time. Should be used to limit the +;; number of queued queries in case of a database or network +;; failure. (default: 120) +;query_wait_timeout = 120 + +;; Dangerous. Client connection is closed if the cancellation request +;; is not assigned to a server in this time. Should be used to limit +;; the time a client application blocks on a queued cancel request in +;; case of a database or network failure. (default: 10) +;cancel_wait_timeout = 10 + +;; Dangerous. Client connection is closed if no activity in this +;; time. Should be used to survive network problems. (default: 0) +;client_idle_timeout = 0 + +;; Disconnect clients who have not managed to log in after connecting +;; in this many seconds. +;client_login_timeout = 60 + +;; Clean automatically created database entries (via "*") if they stay +;; unused in this many seconds. +;autodb_idle_timeout = 3600 + +;; Close connections which are in "IDLE in transaction" state longer +;; than this many seconds. +;idle_transaction_timeout = 0 + +;; How long SUSPEND/-R waits for buffer flush before closing +;; connection. +;suspend_timeout = 10 + +;;; +;;; Low-level tuning options +;;; + +;; buffer for streaming packets +;pkt_buf = 4096 + +;; man 2 listen +;listen_backlog = 128 + +;; Max number pkt_buf to process in one event loop. +;sbuf_loopcnt = 5 + +;; Maximum PostgreSQL protocol packet size. +;max_packet_size = 2147483647 + +;; Set SO_REUSEPORT socket option +;so_reuseport = 0 + +;; networking options, for info: man 7 tcp + +;; Linux: Notify program about new connection only if there is also +;; data received. (Seconds to wait.) On Linux the default is 45, on +;; other OS'es 0. +;tcp_defer_accept = 0 + +;; In-kernel buffer size (Linux default: 4096) +;tcp_socket_buffer = 0 + +;; whether tcp keepalive should be turned on (0/1) +;tcp_keepalive = 1 + +;; The following options are Linux-specific. They also require +;; tcp_keepalive=1. + +;; Count of keepalive packets +;tcp_keepcnt = 0 + +;; How long the connection can be idle before sending keepalive +;; packets +;tcp_keepidle = 0 + +;; The time between individual keepalive probes +;tcp_keepintvl = 0 + +;; How long may transmitted data remain unacknowledged before TCP +;; connection is closed (in milliseconds) +;tcp_user_timeout = 0 + +;; DNS lookup caching time +;dns_max_ttl = 15 + +;; DNS zone SOA lookup period +;dns_zone_check_period = 0 + +;; DNS negative result caching time +;dns_nxdomain_ttl = 15 + +;; Custom resolv.conf file, to set custom DNS servers or other options +;; (default: empty = use OS settings) +;resolv_conf = /etc/pgbouncer/resolv.conf + +;;; +;;; Random stuff +;;; + +;; Hackish security feature. Helps against SQL injection: when PQexec +;; is disabled, multi-statement cannot be made. +;disable_pqexec = 0 + +;; Config file to use for next RELOAD/SIGHUP +;; By default contains config file from command line. +;conffile + +;; Windows service name to register as. job_name is alias for +;; service_name, used by some Skytools scripts. +;service_name = pgbouncer +;job_name = pgbouncer + +;; Read additional config from other file +%include /etc/pgbouncer/pgbouncer-other.ini +{{- end -}} diff --git a/charts/pgbouncer/templates/_userlist.txt.tpl b/charts/pgbouncer/templates/_userlist.txt.tpl new file mode 100644 index 0000000..4fae1f3 --- /dev/null +++ b/charts/pgbouncer/templates/_userlist.txt.tpl @@ -0,0 +1,5 @@ +{{- define "userlist.txt" -}} +{{- range $user := .Values.users -}} +{{ $user.name | quote }} {{ $user.password | quote }} +{{- end -}} +{{- end -}} diff --git a/charts/pgbouncer/templates/configmap.yaml b/charts/pgbouncer/templates/configmap.yaml new file mode 100644 index 0000000..454a8eb --- /dev/null +++ b/charts/pgbouncer/templates/configmap.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "pgbouncer.fullname" . }}-config + labels: + {{- include "pgbouncer.labels" . | nindent 4 }} +data: + userlist.txt: |- +{{ include "userlist.txt" . | indent 4 }} + pgbouncer.ini: |- +{{ include "pgbouncer.ini" . | indent 4 }} + pgbouncer-other.ini: |- +{{ include "pgbouncer-other.ini" . | indent 4 }} diff --git a/charts/pgbouncer/templates/deployment.yaml b/charts/pgbouncer/templates/deployment.yaml index ee73335..2d9b7fb 100644 --- a/charts/pgbouncer/templates/deployment.yaml +++ b/charts/pgbouncer/templates/deployment.yaml @@ -5,12 +5,12 @@ metadata: labels: {{- include "pgbouncer.labels" . | nindent 4 }} spec: - {{- if not .Values.autoscaling.enabled }} replicas: {{ .Values.replicaCount }} - {{- end }} selector: matchLabels: {{- include "pgbouncer.selectorLabels" . | nindent 6 }} + strategy: + {{- toYaml .Values.updateStrategy | nindent 4 }} template: metadata: {{- with .Values.podAnnotations }} @@ -24,7 +24,6 @@ spec: imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} - serviceAccountName: {{ include "pgbouncer.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: @@ -33,20 +32,38 @@ spec: {{- toYaml .Values.securityContext | nindent 12 }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} + {{- with .Values.image.command }} + command: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.image.args }} + args: + {{- toYaml . | nindent 12 }} + {{- end }} ports: - - name: http - containerPort: {{ .Values.service.port }} + - name: pgbouncer + containerPort: 5432 protocol: TCP - livenessProbe: - httpGet: - path: / - port: http readinessProbe: - httpGet: - path: / - port: http + tcpSocket: + port: pgbouncer + initialDelaySeconds: 5 + periodSeconds: 10 + livenessProbe: + tcpSocket: + port: pgbouncer + initialDelaySeconds: 15 + periodSeconds: 15 resources: {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: config + readOnly: true + mountPath: /etc/pgbouncer/ + volumes: + - name: config + configMap: + name: {{ include "pgbouncer.fullname" . }}-config {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/charts/pgbouncer/templates/ingress.yaml b/charts/pgbouncer/templates/ingress.yaml deleted file mode 100644 index 0edf229..0000000 --- a/charts/pgbouncer/templates/ingress.yaml +++ /dev/null @@ -1,61 +0,0 @@ -{{- if .Values.ingress.enabled -}} -{{- $fullName := include "pgbouncer.fullname" . -}} -{{- $svcPort := .Values.service.port -}} -{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} - {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} - {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} - {{- end }} -{{- end }} -{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} -apiVersion: networking.k8s.io/v1 -{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} -apiVersion: networking.k8s.io/v1beta1 -{{- else -}} -apiVersion: extensions/v1beta1 -{{- end }} -kind: Ingress -metadata: - name: {{ $fullName }} - labels: - {{- include "pgbouncer.labels" . | nindent 4 }} - {{- with .Values.ingress.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -spec: - {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} - ingressClassName: {{ .Values.ingress.className }} - {{- end }} - {{- if .Values.ingress.tls }} - tls: - {{- range .Values.ingress.tls }} - - hosts: - {{- range .hosts }} - - {{ . | quote }} - {{- end }} - secretName: {{ .secretName }} - {{- end }} - {{- end }} - rules: - {{- range .Values.ingress.hosts }} - - host: {{ .host | quote }} - http: - paths: - {{- range .paths }} - - path: {{ .path }} - {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} - pathType: {{ .pathType }} - {{- end }} - backend: - {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} - service: - name: {{ $fullName }} - port: - number: {{ $svcPort }} - {{- else }} - serviceName: {{ $fullName }} - servicePort: {{ $svcPort }} - {{- end }} - {{- end }} - {{- end }} -{{- end }} diff --git a/charts/pgbouncer/templates/service.yaml b/charts/pgbouncer/templates/service.yaml index 1a9909a..ff65754 100644 --- a/charts/pgbouncer/templates/service.yaml +++ b/charts/pgbouncer/templates/service.yaml @@ -8,8 +8,8 @@ spec: type: {{ .Values.service.type }} ports: - port: {{ .Values.service.port }} - targetPort: http + targetPort: pgbouncer protocol: TCP - name: http + name: pgbouncer selector: {{- include "pgbouncer.selectorLabels" . | nindent 4 }} diff --git a/charts/pgbouncer/templates/tests/test-connection.yaml b/charts/pgbouncer/templates/tests/test-connection.yaml deleted file mode 100644 index 8eddb8a..0000000 --- a/charts/pgbouncer/templates/tests/test-connection.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: "{{ include "pgbouncer.fullname" . }}-test-connection" - labels: - {{- include "pgbouncer.labels" . | nindent 4 }} - annotations: - "helm.sh/hook": test -spec: - containers: - - name: wget - image: busybox - command: ['wget'] - args: ['{{ include "pgbouncer.fullname" . }}:{{ .Values.service.port }}'] - restartPolicy: Never diff --git a/charts/pgbouncer/values.yaml b/charts/pgbouncer/values.yaml index 0b0d7a4..ebc3df4 100644 --- a/charts/pgbouncer/values.yaml +++ b/charts/pgbouncer/values.yaml @@ -1,28 +1,54 @@ -# Default values for pgbouncer. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - replicaCount: 1 +databases: {} + # example: "host=127.0.0.1 port=5432 user=pgbouncer" + +users: [] + # - name: bob + # password: 3obSecretPwd + # options: {} + # # pool_mode: transaction + # # max_user_connections: 100 + +connectionLimits: + max_client_conn: 200 + default_pool_size: 20 + min_pool_size: 15 + reserve_pool_size: 25 + reserve_pool_timeout: 5 + +logging: + log_connections: 1 + log_disconnections: 1 + log_pooler_errors: 1 + log_stats: 0 + stats_period: 60 + verbose: 0 + +settings: + auth_type: md5 + auth_user: null + # In order to use auth_query, auth_user must be set + auth_query: "SELECT usename, passwd FROM pg_shadow WHERE usename=$1" + pool_mode: session + +extraSettings: + ignore_startup_parameters: extra_float_digits + image: - repository: nginx + repository: hyperized/pgbouncer pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. tag: "" + # Overrides the image command and args + command: [] + args: + - /etc/pgbouncer/pgbouncer.ini imagePullSecrets: [] nameOverride: "" fullnameOverride: "" -serviceAccount: - # Specifies whether a service account should be created - create: true - # Annotations to add to the service account - annotations: {} - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: "" - podAnnotations: {} podSecurityContext: {} @@ -36,31 +62,16 @@ securityContext: {} # runAsNonRoot: true # runAsUser: 1000 +updateStrategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 0 + service: type: ClusterIP - port: 80 - -ingress: - enabled: false - className: "" - annotations: {} - # kubernetes.io/ingress.class: nginx - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: - - path: / - pathType: ImplementationSpecific - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local + port: 5432 resources: {} - # We usually recommend not to specify default resources and to leave this as a conscious - # choice for the user. This also increases chances charts run on environments with little - # resources, such as Minikube. If you do want to specify resources, uncomment the following - # lines, adjust them as necessary, and remove the curly braces after 'resources:'. # limits: # cpu: 100m # memory: 128Mi @@ -68,13 +79,6 @@ resources: {} # cpu: 100m # memory: 128Mi -autoscaling: - enabled: false - minReplicas: 1 - maxReplicas: 100 - targetCPUUtilizationPercentage: 80 - # targetMemoryUtilizationPercentage: 80 - nodeSelector: {} tolerations: [] From 17e0907be22a57b6c085516b1d0ccc003bfbb38e Mon Sep 17 00:00:00 2001 From: pmint93 Date: Fri, 10 Nov 2023 15:09:39 +0700 Subject: [PATCH 3/4] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ccc944c..22f8688 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,8 +6,6 @@ Contributions are welcome via GitHub pull requests. This document outlines the p Isssues or Pull requests to a chart should be created with prefix `[charts/]` eg: `[charts/metabase]` -_For now, there's only one chart, then this is just a best practice_ - **Bumping chart version** Every PR should include chart version bump, because we can not have different version of the charts with the same version name. From a51dba711c2ef26cc8510906470410784f4f0758 Mon Sep 17 00:00:00 2001 From: pmint93 Date: Fri, 10 Nov 2023 15:19:07 +0700 Subject: [PATCH 4/4] Update PgBouncer instruction --- charts/pgbouncer/templates/NOTES.txt | 14 +++++++------- charts/pgbouncer/values.yaml | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/charts/pgbouncer/templates/NOTES.txt b/charts/pgbouncer/templates/NOTES.txt index d84d272..268c1f1 100644 --- a/charts/pgbouncer/templates/NOTES.txt +++ b/charts/pgbouncer/templates/NOTES.txt @@ -1,32 +1,32 @@ -PGBouncer has been installed! +PgBouncer has been installed! {{- if contains "NodePort" .Values.service.type }} -PGBouncer is exposed as a `NodePort` type service. +PgBouncer is exposed as a `NodePort` type service. Get the address by running these commands: export NODE_PORT=$(kubectl --namespace {{ .Release.Namespace }} get services -o jsonpath="{.spec.ports[0].nodePort}" {{ include "pgbouncer.fullname" . }}) export NODE_IP=$(kubectl --namespace {{ .Release.Namespace }} get nodes -o jsonpath="{.items[0].status.addresses[1].address}") - echo "Connect to PGBouncer by using IP address: $NODE_IP and port number: $NODE_PORT" + echo "Connect to PgBouncer by using IP address: $NODE_IP and port number: $NODE_PORT" {{- else if contains "LoadBalancer" .Values.service.type }} -PGBouncer is exposed as a `LoadBalancer` type service. +PgBouncer is exposed as a `LoadBalancer` type service. It may take a few minutes for the LoadBalancer IP to be available. You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "pgbouncer.fullname" . }}' export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "pgbouncer.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") - echo "Connect to PGBouncer by using IP address: $SERVICE_IP and port number: {{ .Values.service.port }}" + echo "Connect to PgBouncer by using IP address: $SERVICE_IP and port number: {{ .Values.service.port }}" {{- else if contains "ClusterIP" .Values.service.type }} -PGBouncer is exposed as a `ClusterIP` type service. +PgBouncer is exposed as a `ClusterIP` type service. Get the address by running these commands: export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "pgbouncer.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") - echo "Connect to PGBouncer by using IP address: 127.0.0.1 and port number: 5432" + echo "Connect to PgBouncer by using IP address: 127.0.0.1 and port number: 5432" kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 5432:$CONTAINER_PORT {{- end }} diff --git a/charts/pgbouncer/values.yaml b/charts/pgbouncer/values.yaml index ebc3df4..6458f2b 100644 --- a/charts/pgbouncer/values.yaml +++ b/charts/pgbouncer/values.yaml @@ -2,11 +2,12 @@ replicaCount: 1 databases: {} # example: "host=127.0.0.1 port=5432 user=pgbouncer" + # "*": "host=127.0.0.1 port=5432" users: [] # - name: bob # password: 3obSecretPwd - # options: {} + # options: {} # Override global settings # # pool_mode: transaction # # max_user_connections: 100