Accessing Postgresql data of Kubernetes cluster

Accessing Postgresql data of Kubernetes cluster

I found a solution to my problem of downloading the volume directory, however when I run multiple replicasets of postgres, the tables of the DB are still scattered between the pods.

Heres what I did to download the postgres volume:

First of all, minikube supports some specific directories for volume appear:

minikube is configured to persist files stored under the following directories, which are made in the Minikube VM (or on your localhost if running on bare metal). You may lose data from other directories on reboots.

/data
/var/lib/minikube
/var/lib/docker
/tmp/hostpath_pv
/tmp/hostpath-provisioner

So Ive changed the mount path to be under the /data directory. This made the database volume visible.

After this I sshed into minikube and copied the database volume to a new directory (I used /home/docker as the user of minikube is docker).

sudo cp -R /data/pgdata /home/docker

The volume pgdata was still owned by root (access denied error) so I changed it to be owned by docker. For this I also set a new password which I knew:

sudo passwd docker # change password for docker user
sudo chown -R docker: /home/docker/pgdata # change owner from root to docker

Then you can exit and copy the directory into you local machine:

exit
scp -r $(minikube ssh-key) docker@$(minikube ip):/home/docker/pgdata [your_local_path].

NOTE

Marios advice, which is to use pgdump is probably a better solution to copy a database. I still wanted to download the volume directory to see if it has the full database, when the pods have only a part of all the tables. In the end it turned out it doesnt.

Accessing Postgresql data of Kubernetes cluster

Leave a Reply

Your email address will not be published. Required fields are marked *