Understanding PVC, stateful sets and restarted pods

Hello, i’m pretty new at k8s, i’m reading about the persistent volumes and i’m trying to understand how exactly kubernetes manages them when pod is scheduled for a restart?

Let’s say i have 5 pods that each one needs to store a state in the PV, and should reload the data when a pod crashes and restarts.

  1. How does the scheduler knows to attach the new pod to the old PV? This happens only on stateful sets and not stateless right? (in stateless it will recreate the pod with a fresh volume?)
  2. For Stateful sets - when pod is rescheduled, how does it know to attach itself to one of the failed pods?

Again, my use case is to have a “private” storage for each pod. whenever i add replicas - they will use of course new “private” storage, and when a pod fails - it should restart as a replacement of the failed pod (and should use the old storage it had).

Interesting questions. Sad to see nobody addressing them for such a long time.