Skip to content

Commit 68c84ff

Browse files
desaintmartindargolith
authored andcommitted
[stable/postgresql] Add dedicated tmpfs for /dev/shm. (helm#19025)
* [stable/postgresql] Add dedicated tmpsfs for /dev/shm. Start a database pod without limitations on shm memory. By default docker limit to (see e.g. the [docker issue](docker-library/postgres#416), which could be not enough if PostgreSQL uses parallel workers heavily. If this option is present and value is , to the target database pod will be mounted a new tmpfs volume to remove this limitation. Signed-off-by: Cédric de Saint Martin <[email protected]> * [stable/postgresql] SHM: Second version after review + improvements. Signed-off-by: Cédric de Saint Martin <[email protected]>
1 parent 2f03180 commit 68c84ff

8 files changed

+69
-7
lines changed

stable/postgresql/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v1
22
name: postgresql
3-
version: 7.4.0
3+
version: 7.5.0
44
appVersion: 11.6.0
55
description: Chart for PostgreSQL, an object-relational database management system (ORDBMS) with an emphasis on extensibility and on standards-compliance.
66
keywords:

stable/postgresql/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ The following tables lists the configurable parameters of the PostgreSQL chart a
116116
| `service.loadBalancerIP` | loadBalancerIP if service type is `LoadBalancer` | `nil` |
117117
| `service.loadBalancerSourceRanges` | Address that are allowed when svc is LoadBalancer | [] |
118118
| `schedulerName` | Name of the k8s scheduler (other than default) | `nil` |
119+
| `shmVolume.enabled` | Enable emptyDir volume for /dev/shm for master and slave(s) Pod(s) | `true` |
119120
| `persistence.enabled` | Enable persistence using PVC | `true` |
120121
| `persistence.existingClaim` | Provide an existing `PersistentVolumeClaim`, the value is evaluated as a template. | `nil` |
121122
| `persistence.mountPath` | Path to mount the volume at | `/bitnami/postgresql` |
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Leave this file empty to ensure that CI runs builds against the default configuration in values.yaml.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
shmVolume:
2+
enabled: false

stable/postgresql/templates/statefulset-slaves.yaml

+19-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ spec:
6666
{{- if .Values.serviceAccount.enabled }}
6767
serviceAccountName: {{ default (include "postgresql.fullname" . ) .Values.serviceAccount.name}}
6868
{{- end }}
69-
{{- if or .Values.slave.extraInitContainers (and .Values.volumePermissions.enabled .Values.persistence.enabled) }}
69+
{{- if or .Values.slave.extraInitContainers (and .Values.volumePermissions.enabled .Values.persistence.enabled) .Values.shmVolume.enabled }}
7070
initContainers:
71-
{{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }}
71+
{{- if or (and .Values.volumePermissions.enabled .Values.persistence.enabled) .Values.shmVolume.enabled }}
7272
- name: init-chmod-data
7373
image: {{ template "postgresql.volumePermissions.image" . }}
7474
imagePullPolicy: "{{ .Values.volumePermissions.image.pullPolicy }}"
@@ -83,12 +83,19 @@ spec:
8383
chmod 700 {{ .Values.persistence.mountPath }}/data
8484
find {{ .Values.persistence.mountPath }} -mindepth 0 -maxdepth 1 -not -name ".snapshot" -not -name "lost+found" | \
8585
xargs chown -R {{ .Values.securityContext.runAsUser }}:{{ .Values.securityContext.fsGroup }}
86+
{{- if .Values.shmVolume.enabled }}
87+
chmod -R 777 /dev/shm
88+
{{- end }}
8689
securityContext:
8790
runAsUser: {{ .Values.volumePermissions.securityContext.runAsUser }}
8891
volumeMounts:
8992
- name: data
9093
mountPath: {{ .Values.persistence.mountPath }}
9194
subPath: {{ .Values.persistence.subPath }}
95+
{{- if .Values.shmVolume.enabled }}
96+
- name: dshm
97+
mountPath: /dev/shm
98+
{{- end }}
9299
{{- end }}
93100
{{- if .Values.slave.extraInitContainers }}
94101
{{ tpl .Values.slave.extraInitContainers . | indent 8 }}
@@ -197,6 +204,10 @@ spec:
197204
- name: postgresql-password
198205
mountPath: /opt/bitnami/postgresql/secrets/
199206
{{- end }}
207+
{{- if .Values.shmVolume.enabled }}
208+
- name: dshm
209+
mountPath: /dev/shm
210+
{{- end }}
200211
{{- if .Values.persistence.enabled }}
201212
- name: data
202213
mountPath: {{ .Values.persistence.mountPath }}
@@ -229,6 +240,12 @@ spec:
229240
configMap:
230241
name: {{ template "postgresql.extendedConfigurationCM" . }}
231242
{{- end }}
243+
{{- if .Values.shmVolume.enabled }}
244+
- name: dshm
245+
emptyDir:
246+
medium: Memory
247+
sizeLimit: 1Gi
248+
{{- end }}
232249
{{- if not .Values.persistence.enabled }}
233250
- name: data
234251
emptyDir: {}

stable/postgresql/templates/statefulset.yaml

+21-4
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ spec:
7070
{{- if .Values.serviceAccount.enabled }}
7171
serviceAccountName: {{ default (include "postgresql.fullname" . ) .Values.serviceAccount.name }}
7272
{{- end }}
73-
{{- if or .Values.master.extraInitContainers (and .Values.volumePermissions.enabled .Values.persistence.enabled) }}
73+
{{- if or .Values.master.extraInitContainers (and .Values.volumePermissions.enabled .Values.persistence.enabled) .Values.shmVolume.enabled }}
7474
initContainers:
75-
{{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }}
75+
{{- if or (and .Values.volumePermissions.enabled .Values.persistence.enabled) .Values.shmVolume.enabled }}
7676
- name: init-chmod-data
7777
image: {{ template "postgresql.volumePermissions.image" . }}
7878
imagePullPolicy: "{{ .Values.volumePermissions.image.pullPolicy }}"
@@ -87,12 +87,19 @@ spec:
8787
chmod 700 {{ .Values.persistence.mountPath }}/data
8888
find {{ .Values.persistence.mountPath }} -mindepth 0 -maxdepth 1 -not -name ".snapshot" -not -name "lost+found" | \
8989
xargs chown -R {{ .Values.securityContext.runAsUser }}:{{ .Values.securityContext.fsGroup }}
90+
{{- if .Values.shmVolume.enabled }}
91+
chmod -R 777 /dev/shm
92+
{{- end }}
9093
securityContext:
9194
runAsUser: {{ .Values.volumePermissions.securityContext.runAsUser }}
9295
volumeMounts:
9396
- name: data
9497
mountPath: {{ .Values.persistence.mountPath }}
9598
subPath: {{ .Values.persistence.subPath }}
99+
{{- if .Values.shmVolume.enabled }}
100+
- name: dshm
101+
mountPath: /dev/shm
102+
{{- end }}
96103
{{- end }}
97104
{{- if .Values.master.extraInitContainers }}
98105
{{ tpl .Values.master.extraInitContainers . | indent 8 }}
@@ -277,6 +284,10 @@ spec:
277284
- name: postgresql-password
278285
mountPath: /opt/bitnami/postgresql/secrets/
279286
{{- end }}
287+
{{- if .Values.shmVolume.enabled }}
288+
- name: dshm
289+
mountPath: /dev/shm
290+
{{- end }}
280291
{{- if .Values.persistence.enabled }}
281292
- name: data
282293
mountPath: {{ .Values.persistence.mountPath }}
@@ -382,11 +393,17 @@ spec:
382393
{{- if .Values.master.extraVolumes }}
383394
{{- toYaml .Values.master.extraVolumes | nindent 8 }}
384395
{{- end }}
385-
{{- if and .Values.metrics.enabled .Values.metrics.customMetrics }}
396+
{{- if and .Values.metrics.enabled .Values.metrics.customMetrics }}
386397
- name: custom-metrics
387398
configMap:
388399
name: {{ template "postgresql.metricsCM" . }}
389-
{{- end }}
400+
{{- end }}
401+
{{- if .Values.shmVolume.enabled }}
402+
- name: dshm
403+
emptyDir:
404+
medium: Memory
405+
sizeLimit: 1Gi
406+
{{- end }}
390407
{{- if and .Values.persistence.enabled .Values.persistence.existingClaim }}
391408
- name: data
392409
persistentVolumeClaim:

stable/postgresql/values-production.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ service:
239239
# loadBalancerSourceRanges:
240240
# - 10.10.10.0/24
241241

242+
## Start master and slave(s) pod(s) without limitations on shm memory.
243+
## By default docker and containerd (and possibly other container runtimes)
244+
## limit `/dev/shm` to `64M` (see e.g. the
245+
## [docker issue](https://github.com/docker-library/postgres/issues/416) and the
246+
## [containerd issue](https://github.com/containerd/containerd/issues/3654),
247+
## which could be not enough if PostgreSQL uses parallel workers heavily.
248+
## If this option is present and value is `true`,
249+
## to the target database pod will be mounted a new tmpfs volume to remove
250+
## this limitation.
251+
shmVolume:
252+
enabled: true
253+
242254
## PostgreSQL data Persistent Volume Storage Class
243255
## If defined, storageClassName: <storageClass>
244256
## If set to "-", storageClassName: "", which disables dynamic provisioning

stable/postgresql/values.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ service:
239239
# loadBalancerSourceRanges:
240240
# - 10.10.10.0/24
241241

242+
## Start master and slave(s) pod(s) without limitations on shm memory.
243+
## By default docker and containerd (and possibly other container runtimes)
244+
## limit `/dev/shm` to `64M` (see e.g. the
245+
## [docker issue](https://github.com/docker-library/postgres/issues/416) and the
246+
## [containerd issue](https://github.com/containerd/containerd/issues/3654),
247+
## which could be not enough if PostgreSQL uses parallel workers heavily.
248+
## If this option is present and value is `true`,
249+
## to the target database pod will be mounted a new tmpfs volume to remove
250+
## this limitation.
251+
shmVolume:
252+
enabled: true
253+
242254
## PostgreSQL data Persistent Volume Storage Class
243255
## If defined, storageClassName: <storageClass>
244256
## If set to "-", storageClassName: "", which disables dynamic provisioning

0 commit comments

Comments
 (0)