|
| 1 | +apiVersion: {{ template "deployment.apiVersion" . }} |
| 2 | +kind: Deployment |
| 3 | +metadata: |
| 4 | + name: {{ include "pgbouncer.fullname" . }} |
| 5 | + labels: |
| 6 | + app.kubernetes.io/name: {{ template "pgbouncer.name" . }} |
| 7 | + helm.sh/chart: {{ template "pgbouncer.chart" . }} |
| 8 | + app.kubernetes.io/instance: {{ .Release.Name }} |
| 9 | + app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 10 | +spec: |
| 11 | + replicas: {{ .Values.replicaCount }} |
| 12 | + revisionHistoryLimit: {{ .Values.revisionHistoryLimit }} |
| 13 | + {{ if .Values.updateStrategy -}} |
| 14 | + strategy: {{ .Values.updateStrategy | toYaml | trimSuffix "\n" | nindent 4 }} |
| 15 | + {{ end -}} |
| 16 | + {{ if .Values.minReadySeconds -}} |
| 17 | + minReadySeconds: {{ .Values.minReadySeconds }} |
| 18 | + {{ end -}} |
| 19 | + selector: |
| 20 | + matchLabels: |
| 21 | + app.kubernetes.io/name: {{ template "pgbouncer.name" . }} |
| 22 | + app.kubernetes.io/instance: {{ .Release.Name }} |
| 23 | + template: |
| 24 | + metadata: |
| 25 | + labels: |
| 26 | + app.kubernetes.io/name: {{ template "pgbouncer.name" . }} |
| 27 | + app.kubernetes.io/instance: {{ .Release.Name }} |
| 28 | + {{- if .Values.podLabels }} |
| 29 | + {{ range $key, $value := .Values.podLabels -}} |
| 30 | + {{ $key }}: {{ $value | quote }} |
| 31 | + {{- end -}} |
| 32 | + {{- end }} |
| 33 | + annotations: |
| 34 | + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} |
| 35 | + {{- if .Values.pgbouncerExporter.enabled }} |
| 36 | + prometheus.io/scrape: "true" |
| 37 | + prometheus.io/port: "{{ .Values.pgbouncerExporter.port }}" |
| 38 | + prometheus.io/path: "/metrics" |
| 39 | + {{- end }} |
| 40 | + {{ range $key, $value := .Values.podAnnotations -}} |
| 41 | + {{ $key }}: {{ $value | quote }} |
| 42 | + {{- end }} |
| 43 | + spec: |
| 44 | + serviceAccountName: {{ template "pgbouncer.serviceAccountName" . }} |
| 45 | + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} |
| 46 | + {{ if .Values.nodeSelector -}} |
| 47 | + nodeSelector: {{ toYaml .Values.nodeSelector | trimSuffix "\n" | nindent 8 }} |
| 48 | + {{ end -}} |
| 49 | + {{ if .Values.tolerations -}} |
| 50 | + tolerations: {{ toYaml .Values.tolerations | trimSuffix "\n" | nindent 6 }} |
| 51 | + {{ end -}} |
| 52 | + {{ if .Values.affinity -}} |
| 53 | + affinity: {{ toYaml .Values.affinity | trimSuffix "\n" | nindent 8 }} |
| 54 | + {{ end -}} |
| 55 | + {{ if .Values.priorityClassName -}} |
| 56 | + priorityClassName: {{ .Values.priorityClassName }} |
| 57 | + {{ end -}} |
| 58 | + {{ if .Values.runtimeClassName -}} |
| 59 | + runtimeClassName: {{ .Values.runtimeClassName }} |
| 60 | + {{ end -}} |
| 61 | + {{ if len .Values.imagePullSecrets -}} |
| 62 | + imagePullSecrets: {{ toYaml .Values.imagePullSecrets | trimSuffix "\n" | nindent 6 }} |
| 63 | + {{ end -}} |
| 64 | + {{ if .Values.extraInitContainers -}} |
| 65 | + initContainers: {{ toYaml .Values.extraInitContainers | trimSuffix "\n" | nindent 6 }} |
| 66 | + {{ end -}} |
| 67 | + containers: |
| 68 | + - name: pgbouncer |
| 69 | + image: {{ template "pgbouncer.image" . }} |
| 70 | + imagePullPolicy: {{ .Values.image.pullPolicy }} |
| 71 | + lifecycle: |
| 72 | + postStart: |
| 73 | + exec: |
| 74 | + command: |
| 75 | + - '/bin/sh' |
| 76 | + - '-c' |
| 77 | + - > |
| 78 | + until pids=$(pidof pgbouncer); do |
| 79 | + sleep 1 |
| 80 | + done; |
| 81 | + for db_name in /etc/secrets-db/*; do |
| 82 | + cd $db_name |
| 83 | + echo "$(cat dbname) = host={{ .Values.config.postgresql.host }} port={{ .Values.config.postgresql.port }} dbname=$(cat dbname) user=$(cat user) password=$(cat password)" >> /opt/bitnami/pgbouncer/conf/databases.txt |
| 84 | + done; |
| 85 | + kill -1 1 |
| 86 | + env: |
| 87 | + - name: POSTGRESQL_HOST |
| 88 | + value: "{{ .Values.config.postgresql.host }}" |
| 89 | + - name: POSTGRESQL_PORT |
| 90 | + value: "{{ .Values.config.postgresql.port }}" |
| 91 | + - name: PGBOUNCER_PORT |
| 92 | + value: "{{ .Values.config.postgresql.port }}" |
| 93 | + - name: POSTGRESQL_PASSWORD |
| 94 | + value: "0" |
| 95 | + {{- if .Values.extraEnvs }} |
| 96 | + {{ toYaml .Values.extraEnvs | trimSuffix "\n" | nindent 10 }} |
| 97 | + {{- end }} |
| 98 | + ports: |
| 99 | + - name: psql |
| 100 | + containerPort: 5432 |
| 101 | + protocol: TCP |
| 102 | + readinessProbe: |
| 103 | + tcpSocket: |
| 104 | + port: 5432 |
| 105 | + initialDelaySeconds: 10 |
| 106 | + periodSeconds: 5 |
| 107 | + livenessProbe: |
| 108 | + tcpSocket: |
| 109 | + port: 5432 |
| 110 | + initialDelaySeconds: 60 |
| 111 | + periodSeconds: 10 |
| 112 | + {{- if .Values.resources }} |
| 113 | + resources: {{ toYaml .Values.resources | trimSuffix "\n" | nindent 10 }} |
| 114 | + {{- end }} |
| 115 | + volumeMounts: |
| 116 | + - name: config |
| 117 | + mountPath: /bitnami/pgbouncer/conf/ |
| 118 | + - name: userlist |
| 119 | + mountPath: /etc/userlist/ |
| 120 | + {{- if .Values.extraVolumeMounts -}} |
| 121 | + {{ toYaml .Values.extraVolumeMounts | trimSuffix "\n" | nindent 8 }} |
| 122 | + {{- end }} |
| 123 | + {{- if .Values.pgbouncerExporter.enabled }} |
| 124 | + - name: exporter |
| 125 | + image: {{ template "pgbouncer.exporterImage" . }} |
| 126 | + imagePullPolicy: {{ .Values.pgbouncerExporter.image.pullPolicy }} |
| 127 | + args: |
| 128 | + - --web.listen-address=:{{ .Values.pgbouncerExporter.port }} |
| 129 | + - --web.telemetry-path=/metrics |
| 130 | + - --log.level={{ .Values.pgbouncerExporter.log.level }} |
| 131 | + - --log.format={{ .Values.pgbouncerExporter.log.format }} |
| 132 | + - --pgBouncer.connectionString=postgres://$(PGBOUNCER_USER):$(PGBOUNCER_PASS)@127.0.0.1:5432/pgbouncer?sslmode=disable&connect_timeout=10 |
| 133 | + env: |
| 134 | + - name: PGBOUNCER_USER |
| 135 | + valueFrom: |
| 136 | + secretKeyRef: |
| 137 | + name: {{ template "pgbouncer.fullname" . }}-secret |
| 138 | + key: adminUser |
| 139 | + - name: PGBOUNCER_PASS |
| 140 | + valueFrom: |
| 141 | + secretKeyRef: |
| 142 | + name: {{ template "pgbouncer.fullname" . }}-secret |
| 143 | + key: adminPassword |
| 144 | + {{- if .Values.pgbouncerExporter.resources }} |
| 145 | + resources: {{ toYaml .Values.pgbouncerExporter.resources | trimSuffix "\n" | nindent 10 }} |
| 146 | + {{- end }} |
| 147 | + ports: |
| 148 | + - name: exporter |
| 149 | + containerPort: {{ .Values.pgbouncerExporter.port }} |
| 150 | + protocol: TCP |
| 151 | + {{- end }} |
| 152 | + {{ if .Values.extraContainers -}} |
| 153 | + {{ toYaml .Values.extraContainers | trimSuffix "\n" | indent 6 | trimPrefix " " }} |
| 154 | + {{ end -}} |
| 155 | + volumes: |
| 156 | + - name: config |
| 157 | + configMap: |
| 158 | + defaultMode: 0777 |
| 159 | + name: {{ template "pgbouncer.fullname" . }}-configmap |
| 160 | + - name: userlist |
| 161 | + secret: |
| 162 | + secretName: {{ template "pgbouncer.fullname" . }}-userlist-secret |
| 163 | + {{- if .Values.extraVolumes -}} |
| 164 | + {{ toYaml .Values.extraVolumes | trimSuffix "\n" | nindent 6 }} |
| 165 | + {{ end -}} |
0 commit comments