Closed tuupola closed 8 months ago
I think this:
volumeMounts:
- name: data
mountPath: /var/lib/postgresql
Needs to be:
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
(The mount you're seeing at /var/lib/postgresql/data
is likely an anonymous volume created by your underlying container runtime, which I'm guessing is most likely Docker, since I don't think any other runtime will auto-create anonymous volumes from the image config like that.)
I have a StatefulSet With a PersistentVolume mounted to
/var/lib/postgresql
. Debian based Postgres images work as expected. Database is initialized and/var/lib/postgresql/data
folder is stored in the PersistentVolume.With Alpine based images the initialization process creates a separate mount for the
/var/lib/postgresql/data
folder to the OS disk. This will lead to data loss when the pod is recycled (data is not in the PersistenVolume).Not sure if this is a configuration problem in the StatefulSet itself. Atleast it is suprising behaviour which is hard to detect at first. It took me couple of times losing the data before suspecting something is wrong. It is not Longhorn related, I have seen the problem happen with AWS based storage too.
To reproduce checkout the following repository. https://github.com/tuupola/postgres-alpine/
For documentation purposes this is the StateFulset config.