Why do my databases disappear after deployments?

I have a 1 replica PostgreSQL (alpine:latest) instance running. It works great but every time I do a deployment or every time I scale to 0 then back to 1 pod my database disappears.

When I look in the logs I see that the init scripts in docker-entrypoint-initdb.d are run indicating that the PV is empty; these shoudl only be run if the directory is empty. When I look at the PV its been around for some time:

postgres-data   Bound    pvc-830e8f59-9628-11e9-88b9-36ca52c85694   3Gi        RWO            do-block-storage   104d

Nothing else seems to be impacted this way. For example I have minio running as an object store and it keeps its data after deployments or scaling.

Any tips appreciated.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.


You need to make sure that you have your volumeMounts and mountPath set up correctly in your deployment file so that the PostgreSQL data folder is actually mounted on your PV.

If you wish you could share your yaml file here so that I could try to advise you further.

Regards, Bobby