I have an application running in K8s, which uses Postgres as backend DB. There is a PV configured to preserve the data in the event of the container crashing. When I simulate a crash ie kubectl delete pod....
Kubernetes then brings up amother pod but this fails. I suspect that this is because in the entrypoint.sh - postgres runs initdb and because the dir not empty, fails.
So my question is, I either need to archive the data or import the data in the event of a container failure.
If archiving, how could I copy the data to the node running the pod? I have also tried commenting the initdb on the entrypoint.sh of the docker image to no avail.
is postgresql running as statefulset? if not, try changing it to statefulset.
can you update the startup script to check for files in mounted dir and if files are present then ignore db creation or else proceed with the script execution.
create a file named run.initialized.txt when the container is started and then go ahead and execute the scripts. ensure that file is persisted to the mount point. that way when the pod gets deleted and new one gets launched, it would find the run.initialized.txt in the mount dir and ignore the script