<p>I'm new to Kubernetes and I'm having trouble with a Deployment that specifies the backend database for the system. For some reason, the Pod hosting the database container gets randomly recreated, and so the data get wiped out. I'm adding a config for the database deployment to use a separate <code>emptyDir</code> volume, but I'm not sure how persistent that is. Will it survive recreation of the Pod? Also, is there a way to check why the Pod seems to get randomly recreated? How do I force Kubernetes to recreate the Pod so I can check if <code>emptyDir</code> volume persists?</p>

<p>Kubernetes' Deployment abstraction is not a good fit for stateful programs such as a database. It's not entirely impossible to that right, but that's not the right tool for the job.</p>

<p>I suggest you look into <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">StatefulSet</a>, which as the the name suggests is meant for stateful loads.</p>

<p>With either, to force a recreation of a pod, simply delete the pod hosting your database, and observe the difference between a pod created by a Deployment and one created by a StatefulSet controller.</p>
