<p>So I want to deploy a master-slaves MySQL cluster in k8s. I found 2 ways that seem popular:</p>
<ol>
<li>The first one is to use statefulsets directly from k8s official document: <a href="https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/" rel="nofollow noreferrer">https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/</a></li>
<li>The second one is to use operator, i.e. <a href="https://github.com/oracle/mysql-operator" rel="nofollow noreferrer">https://github.com/oracle/mysql-operator</a></li>
</ol>
<p>Which way is most commonly used?</p>
<p>Also, in statefulsets, if my MySQL master dies, will k8s automatically promote the slave to be the master?</p>
<p>Lastly, when my logic backend app performs an operation (CRUD) to MySQL cluster, how does k8s know which pod to route to, i.e. write operation can only be sent to master while read is sent to all?</p>

kent
<p>Users can deploy and maintain a set of highly available MySQL services in k8s based on StatefulSets, the process is relatively complex. This process requires users to familiarize themselves with various k8s resource objects, learn many MySQL operation details and maintain a set of complex management scripts. Kubernetes Operators are designed to reduce the threshold for deploying complex applications on k8s.</p>
<p>Operator hides the orchestration details of complex applications and greatly reduces the threshold to use them in k8s. If you need to deploy other complex applications, we recommend that you use the Operator.</p>
<p>Speaking about master election while using StatefulSet.
Electing potential slave to be a master is not an automatic process - you have to configure this manually using <a href="https://www.percona.com/software/mysql-database/percona-xtrabackup" rel="nofollow noreferrer">Xtrabackup</a> - here is more information - <a href="https://www.percona.com/doc/percona-xtrabackup/2.1/howtos/setting_up_replication.html" rel="nofollow noreferrer">setting_up_replication</a>.</p>
<p>Take a look: <a href="https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/#cloning-existing-data" rel="nofollow noreferrer">cloning-existing-data</a>, <a href="https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/#starting-replication" rel="nofollow noreferrer">starting-replication</a>, <a href="https://medium.com/@Alibaba_Cloud/kubernetes-application-management-stateful-services-ca17640f93fa" rel="nofollow noreferrer">mysql-statefulset-operator</a>.</p>
<p>Useful tools:  <a href="https://github.com/vitessio/vitess" rel="nofollow noreferrer">vitess</a> for better MySQL networking management and <a href="https://github.com/helm/charts/tree/master/stable/percona-xtradb-cluster" rel="nofollow noreferrer">percona-xtradb-cluster</a> that provides superior performance, scalability and instrumentation.</p>
