<p>Is it reasonable to use Kubernetes for a clustered database such as MySQL in production environment? </p>

<p>There are example configurations such as <a href="https://github.com/eBay/Kubernetes/tree/master/examples/mysql-galera" rel="noreferrer">mysql galera example</a>. However, most examples do not make use of persistent volumes. As far as I've understood persistent volumes must reside on some shared file system as defined here <a href="http://kubernetes.io/docs/user-guide/persistent-volumes/#types-of-persistent-volumes" rel="noreferrer">Kubernetes types of persistent volumes</a>. A shared file system will not guarantee that the database files of the pod will be local to the machine hosting the pod. It will be accessed over network which is rather slow. Moreover, there are issues with MySQL and NFS, for example. </p>

<p>This might be acceptable for a test environment. However, what should I do in a production environment? Is it better to run the database cluster outside Kubernetes and run only application servers with Kubernetes?  </p>

<p>The Kubernetes project introduced <a href="http://kubernetes.io/docs/user-guide/petset/" rel="nofollow">PetSets</a>, a new  pod management abstraction, intended to run stateful applications. <strong>It is an alpha feature at present</strong> (as of version 1.4) and moving rapidly. A list of the various issues as we move to beta are listed <a href="https://github.com/kubernetes/kubernetes/issues/28718" rel="nofollow">here</a>. Quoting from the section on <a href="http://kubernetes.io/docs/user-guide/petset/#when-to-use-petset" rel="nofollow">when to use petsets</a>:</p>

<p>A PetSet ensures that a specified number of "pets" with unique identities are running at any given time. The identity of a Pet is comprised of: </p>

<ul>
<li>a stable hostname, available in DNS </li>
<li>an ordinal index </li>
<li>stable storage: linked to the ordinal &amp; hostname</li>
</ul>

<p>In addition to the above, it can be coupled with several other features which help one deploy clustered stateful applications and manage them. Coupled with <a href="http://blog.kubernetes.io/2016/10/dynamic-provisioning-and-storage-in-kubernetes.html" rel="nofollow">dynamic volume provisioning</a> for example, it can be used to provision storage automatically. </p>

<p>There are several YAML configuration files available (such as the ones you referenced) using ReplicaSets and Deployments for MySQL and other databases which may be run in production and are probably being run that way as well. However, PetSets are expected to make it a lot easier to run these types of workloads, while supporting upgrades, maintenance, scaling and so on.</p>

<p>You can find some examples of distributed databases with petsets <a href="https://github.com/kubernetes/contrib/tree/master/pets" rel="nofollow">here</a>. </p>

<hr>

<p>The advantage of provisioning persistent volumes which are networked and non-local (such as GlusterFS) is realized at scale. However, for relatively small clusters, there is a proposal to allow for <a href="https://github.com/kubernetes/kubernetes/issues/7562" rel="nofollow">local storage persistent volumes</a> in the future.</p>

<hr>
