<p>I learning k8s and I have a little problem to understand PV.</p>
<p>For example, I want to deploy PostgreSQL which store data in <strong>/var/lib/postgresql/data</strong>
I want to use my local disk for PV so I created that and set my path: <strong>/mnt/ssd/Kubernetes/Postgres</strong></p>
<p>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 <strong>/mnt/ssd/Kubernetes/Postgres</strong> I do not have any files, so</p>
<ol>
<li>How new pod2 know about created database? How PV store data about my created database?</li>
<li>Why does PV need my disk if it doesn't hold any data on it?</li>
</ol>

BElluu
<p>To get a strong understanding of how volumes, persistent volumes and claims work in Kubernetes I strongly suggest going through the official documentation regarding:</p>
<ol>
<li><a href="https://kubernetes.io/docs/concepts/storage/volumes/" rel="nofollow noreferrer">Volumes</a>:</li>
</ol>
<blockquote>
<p>On-disk files in a Container are ephemeral, which presents some
problems for non-trivial applications when running in Containers.
First, when a Container crashes, kubelet will restart it, but the
files will be lost - the Container starts with a clean state. Second,
when running Containers together in a Pod it is often necessary to
share files between those Containers. The Kubernetes <code>Volume</code>
abstraction solves both of these problems.</p>
</blockquote>
<ol start="2">
<li><a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">Persistent Volumes</a>:</li>
</ol>
<blockquote>
<p>A <code>PersistentVolume</code> (PV) is a piece of storage in the cluster that
has been provisioned by an administrator or dynamically provisioned
using Storage Classes. It is a resource in the cluster just like a
node is a cluster resource. PVs are volume plugins like <code>Volumes</code>, but
have a lifecycle independent of any individual Pod that uses the PV.
This API object captures the details of the implementation of the
storage, be that NFS, iSCSI, or a cloud-provider-specific storage
system.</p>
</blockquote>
<ol start="3">
<li>A PersistentVolumeClaim (PVC):</li>
</ol>
<blockquote>
<p>is a request for storage by a user. It is similar to a Pod. Pods
consume node resources and PVCs consume PV resources. Pods can request
specific levels of resources (CPU and Memory). Claims can request
specific size and access modes (e.g., they can be mounted
<code>ReadWriteOnce</code>, <code>ReadOnlyMany</code> or <code>ReadWriteMany</code>, see <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes" rel="nofollow noreferrer">AccessModes</a>).</p>
</blockquote>
<p>After getting a solid theoretical grip of how they work, you can see the <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/" rel="nofollow noreferrer">detailed walkthrough with working examples</a>.</p>
<p>Also, your PostgreSQL is an example of a <a href="https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/" rel="nofollow noreferrer">stateful</a> application. <a href="https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/" rel="nofollow noreferrer">Here</a> you can find a tutorial showing you how to deploy a database and application with Persistent Volumes.</p>
