<hr>

<p>I'm trying to translate a bunch of docker-compose files into kubernetes yamls.  I have used <a href="https://github.com/kubernetes/kompose" rel="nofollow noreferrer">kompose</a>, which has gotten me part way, but I'm getting stuck on one particular part for multiple containers.</p>

<p>This is one of the containers. Notice the docker container is mounting <code>/u/data/. . .</code> to <code>/var/lib/mysql</code>.  This is actually necessary as the mysql directory contains the database and configurations.</p>

<pre><code>server1-backend-mysql:
image: mysql
container_name: server-backend-mysql
restart: always
volumes:
   - /u/data/server-backend-mysql:/var/lib/mysql
networks:
  - eolnet
</code></pre>

<p>What is the correct way to make this happen in Kubernetes? Note that for k8 I will be mounting an nfs volume (this is only for testing purposes).</p>

<p>I did look into <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">hostpath</a>, but so far no luck.</p>

<p>When declaring a Pod, specify the volume at <code>spec.volumes</code>, and then the volume mount at <code>spec.containers[*].volumeMounts</code>:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: server1-backend-mysql
spec:
  containers:
  - image: mysql
    name: mysql
    volumeMounts:
    - mountPath: /var/lib/mysql
      name: mysql-data
  volumes:
  - name: mysql-data
    hostPath:
      path: /u/data/...
      type: Directory
</code></pre>

<p>When declaring a <code>Deployment</code> or <code>StatefulSet</code> (which you <em>should</em> do instead of declaring a Pod), move the respective configurations to <code>spec.template.spec.volumes</code> and <code>spec.template.spec.containers[*].volumeMounts</code>.
For more information, have a look at the <a href="https://kubernetes.io/docs/concepts/storage/volumes/#hostpath" rel="nofollow noreferrer">documentation</a>.</p>

<hr/>

<p>As a side note unrelated to your question: if you're planning to run MySQL from a NFS volume, keep in mind that running MySQL from NFS is possible, but <a href="https://dev.mysql.com/doc/refman/5.7/en/disk-issues.html" rel="nofollow noreferrer">not something that MySQL is really optimized for</a>. Be sure to configure your MySQL server accordingly, and check if your environment permits you to use a networked block device (and not a network file system) like a Ceph RBD volume or similar.</p>
