<p>I'm learning Kubernetes and there is something I don't get well.
There are 3 ways of setting up static storage:</p>
<ul>
<li>Pods with volumes you attach diretctly the storage to</li>
<li>Pods with a PVC attached to its volume</li>
<li>StatefulSets with also PVC inside</li>
</ul>
<p>I can understand the power of PVC when working together with StorageClass, but not when working with <strong>static storage</strong> and local storage like hostPath</p>
<p>To me, it sounds very similar:</p>
<ul>
<li>In the first case I have a volume directly attached to a pod.</li>
<li>In the second case I have a volume statically attached to a PVC, which is also manually attached to a Pod. In the end, the volume will be statically attached to the Pod.</li>
</ul>
<p>On both cases, the data will remain when the Pod is terminates and will be adopted by the next Pod which the corresponing definition, right?</p>
<p>The only profit I see from using PVCs over plain Pod is that you can define the acces mode. Apart of that. Is there a difference when working with hostpath?</p>
<p>On the other hand, the advantage of using a StatefulSet instead of a PVC is (if understood properly) that it get a headless service, and that the rollout and rollback mechanism works differently. Is that the point?</p>
<p>Thank you in advance!</p>

Francisco Roa Prieto
<p>Extracted from <a href="https://kubernetes.io/blog/2019/04/04/kubernetes-1.14-local-persistent-volumes-ga/#how-is-it-different-from-a-hostpath-volume" rel="nofollow noreferrer">this blog</a>:</p>
<blockquote>
<p>The biggest difference is that the Kubernetes scheduler understands
which node a Local Persistent Volume belongs to. With HostPath
volumes, a pod referencing a HostPath volume may be moved by the
scheduler to a different node resulting in data loss. But with Local
Persistent Volumes, the Kubernetes scheduler ensures that a pod using
a Local Persistent Volume is always scheduled to the same node.</p>
</blockquote>
<p>Using <code>hostPath</code> does not garantee that a pod will restart on the same node. So you pod can attach <code>/tmp/storage</code> on <code>k8s-node-1</code>, then if you delete and re-create the pod, it may attach <code>tmp/storage</code> on <code>k8s-node-[2-n]</code></p>
<p>On the contrary, if you use PVC/PV with local persistent storage class, then if you delete and re-create a pod, it will stick on the node which handle the local persistent storage.</p>
<p>StatefulSet creates pods and has <code>volumeClaimTemplate</code> field, which creates a dedicated PVC for each pod. So each pod created by the statefulSet will have its own dedicated storage, linked with Pod-&gt;PVC-&gt;PV-&gt;Storage. So StatefulSet use also the PVC/PV mechanism.
More details are available <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-storage" rel="nofollow noreferrer">here</a>.</p>
