<p>I'm approaching k8s volumes and best practices and I've noticed that when reading documentation it seems that you always need to use <strong>StatefulSet</strong> resource if you want to implement persistency in your cluster:</p>
<blockquote>
<p>&quot;StatefulSet is the workload API object used to manage stateful
applications.&quot;</p>
</blockquote>
<p>I've implemented some tutorials, <strong>some of them use StatefulSet, some others don't</strong>.</p>
<p>In fact, let's say I want to persist some data, I can have my stateless Pods (even MySql server pods!) in which I use a PersistentVolumeClaim which persists the state. If I stop and rerun the cluster, I can resume the state from the Volume with no need of StatefulSet.</p>
<p>I attach here an example of Github repo in which there is a stateful app with MySql and no StatefulSet at all:
<a href="https://github.com/shri-kanth/kuberenetes-demo-manifests" rel="nofollow noreferrer">https://github.com/shri-kanth/kuberenetes-demo-manifests</a></p>
<p>So <strong>do I really need to use a StatefulSet</strong> resource for databases in k8s? Or are there some specific cases it could be a necessary practice?</p>

Alessandro Argentieri
<p>PVCs are not the only reason to use Statefulsets over Deployments.
As the Kubernetes <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#using-statefulsets" rel="nofollow noreferrer">manual</a> states:</p>
<p>StatefulSets are valuable for applications that require one or more of the following:</p>
<ul>
<li>Stable, unique network identifiers.</li>
<li>Stable, persistent storage.</li>
<li>Ordered, graceful deployment and scaling.</li>
<li>Ordered, automated rolling updates.</li>
</ul>
<p>You can read more about database considerations when deployed on Kubernetes here <a href="https://cloud.google.com/blog/products/databases/to-run-or-not-to-run-a-database-on-kubernetes-what-to-consider" rel="nofollow noreferrer">To run or not to run a database on Kubernetes</a></p>
