<p>I am reading <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/storage/local-storage-overview.md" rel="nofollow noreferrer">local storage design</a> of kubernetes. It has a section for <code>distributed database</code> where db replicates data by itself. </p>

<p>My question is that if any process of db goes down, will it be restarted on the same node/machine ? I think it's a yes.</p>

<p>If it's yes, will it have access to its <code>local storage</code> that it had before it crashed ?</p>

<p>I read an <a href="https://kubernetes.io/blog/2016/12/statefulset-run-scale-stateful-applications-in-kubernetes" rel="nofollow noreferrer">older article</a> about <code>stateful sets</code> when it was in beta. The article didn't encourage use of local storage at that time.</p>

<p>I am new to Kubernetes, so please answer this question with more information that a some new needs for understanding.</p>

Ashish Negi
<p>In the local storage design, as you can read <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/storage/local-storage-overview.md#alice-manages-a-database-which-needs-access-to-durable-and-fast-scratch-space" rel="nofollow noreferrer">here</a>, it is used with stateful sets. So for example if you want three mongodb instances named mongodb, then k8s will create for you three pods:</p>

<ul>
<li>mongodb-1</li>
<li>mongodb-2</li>
<li>mongodb-3</li>
</ul>

<p>If the mongodb-2 fails then k8s will restart it with the same local storage or persistent volume.
If you increase the number of replicas, then k8s will create new persistent volumes through your persistentVolumeClaimTemplate. If you shrink it down to two those newly created volumes won't be deleted and will be used it you go back to your previous number of replicas.</p>

<p>If your persistent volume is bound to a specific node then k8s will know to create your pod on that node.</p>

<p>You can read about a mongodb cluster statefulset example here : <a href="https://kubernetes.io/blog/2017/01/running-mongodb-on-kubernetes-with-statefulsets" rel="nofollow noreferrer">https://kubernetes.io/blog/2017/01/running-mongodb-on-kubernetes-with-statefulsets</a></p>

<p>Or you can check a great talk here (with demos):
<a href="https://www.youtube.com/watch?v=m8anzXcP-J8&amp;feature=youtu.be" rel="nofollow noreferrer">https://www.youtube.com/watch?v=m8anzXcP-J8&amp;feature=youtu.be</a></p>

<p>The use of statefuls sets and local storage is really well explained.</p>
