<p>Im new to kubernetes and this topic is confusing for me. I've learned that stateful set doesn't share the PV and each replica has it's own PV. On the other hand I saw the examples when one was using one pvc in stateful set with many replicas. So my question is what will happen then? As PVC to PV are bind 1:1 so one pvc can only bind to one pv, but each replica should have its own PV so how is it possible to have one pvc in stateful set in this scenario?</p>

<p>You should usually use a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#volume-claim-templates" rel="nofollow noreferrer">volume claim template</a> with a StatefulSet.  As you note in the question, this will create a new PersistentVolumeClaim (and a new PersistentVolume) for each replica.  Data is not shared, except to the extent the container process knows how to replicate data between its replicas.  If a StatefulSet Pod is deleted and recreated, it will come back with the same underlying PVC and the same data, even if it is recreated on a different Node.</p>
<pre class="lang-yaml prettyprint-override"><code>spec:
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: [ReadWriteOnce]
        resources:
          requests:
            storage: 1Gi
  template:
    spec:
      containers:
        - name: name
          volumeMounts:
            - name: data
              mountPath: /data
</code></pre>
<p>You're allowed to manually create a PVC and attach it to the StatefulSet Pods</p>
<pre class="lang-yaml prettyprint-override"><code># not recommended -- one PVC shared across all replicas
spec:
  template:
    spec:
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: manually-created-pvc
      containers:
        - name: name
          volumeMounts:
            - name: data
              mountPath: /data
</code></pre>
<p>but in this case the single PVC/PV will be shared across all of the replicas.  This often doesn't work well: things like database containers have explicit checks that their storage isn't shared, and there is a range of concurrency problems that are possible doing this.  This also can prevent pods from starting up since the <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#types-of-persistent-volumes" rel="nofollow noreferrer">volume types</a> that are straightforward to get generally only support a ReadWriteOnce <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes" rel="nofollow noreferrer">access mode</a>; to get ReadWriteMany you need to additionally configure something like an NFS server outside the cluster.</p>
