I learning k8s and I have a little problem to understand PV.
For example, I want to deploy PostgreSQL which store data in /var/lib/postgresql/data I want to use my local disk for PV so I created that and set my path: /mnt/ssd/Kubernetes/Postgres
I do not understand how PV and PVC will store my data, because I created pod1 with PostgreSQL, created new DB and kill this pod1. New pod2 still have database which I created few second time ago on pod1 but on my local disk in /mnt/ssd/Kubernetes/Postgres I do not have any files, so
- How new pod2 know about created database? How PV store data about my created database?
- Why does PV need my disk if it doesn't hold any data on it?
To get a strong understanding of how volumes, persistent volumes and claims work in Kubernetes I strongly suggest going through the official documentation regarding:
After getting a solid theoretical grip of how they work, you can see the detailed walkthrough with working examples.
Also, your PostgreSQL is an example of a stateful application. Here you can find a tutorial showing you how to deploy a database and application with Persistent Volumes.