<p><em>Let me make a statement first: I'm new to Kubernetes, please take it easy if I'm asking wrong questions.</em></p>

<p>Ok, here is what I'm gonna do. I'm planning to build a Kubernetes for my project using some <strong>physical machines</strong>.</p>

<p>I have 1 server for master and 2 worker nodes. My service dockers (pods) will be allocated by Kubernetes master, they will need storage for the database <code>(MySQL)</code>.</p>

<p>After searching around, I came up with a solution of <code>Persistent Volume</code>, but I don't want to use those online cloud services out there such as <strong>Google Cloud</strong> or <strong>Azure Cloud</strong>, etc. It leads me to another solution - <code>Local Persistent Volume (LPV)</code>, this is where I stuck currently. </p>

<p>The problem with <code>LPV</code> is it's attached with a specific node, so I wouldn't be able to replicate (backup) the database on other nodes, if something happens to this node, or something wrong with the physical disk, I'm gonna lose all the databases, right? </p>

<p>The question is, are there any solutions to set up replication on the database using <code>Local Persistent Volume</code>? For example, I have a database on <strong>Node 1</strong>, and a backup version on <strong>Node 2</strong>, so when <strong>Node 1</strong> is not available, the pods will mount to the backup database on <strong>Node 2</strong>.</p>

<p>Thanks in advance!</p>

<ol>
<li><p>You can deploy the database as statefulset using local volumes on nodes.Just create the volumes and put them in a StorageClass</p></li>
<li><p>For backup , you need to setup the replication on the database level ( not volume level ) to some other cluster /other database instance running somewhere else/or on some other cluster. </p></li>
<li><p>Pod failures are handled by kubernetes anyway , it will restart the pod if goes unhelathy.</p></li>
<li><p>Node failures can't be handled in statefulset ( one node can't replace another , in other words , in statefulset a pod will not be restarted on other node , kubernetes will wait for node to come back )</p></li>
<li><p>If you are going for simple single pod deployement rather than statefulset , you can deploy the database as single pod and another instance as single pod and use node selector to run those on different nodes , then setup the replication from one instance to another instance on database level , and configure your client app to failover to fallback instance in case the primary is not available , this needs to be synchronous replication.</p></li>
</ol>

<p>Links:</p>

<p><a href="https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/" rel="nofollow noreferrer">Run a Single-Instance Stateful Application ( MYSQL)
</a></p>

<p><a href="https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/" rel="nofollow noreferrer">Run a Replicated Stateful Application ( MYSQL )
</a></p>
