<p>I am trying to deploy an app to kubernetes cluster and I want to store data in <strong>Persistent Volume</strong>. However, I am very confused about two parameters in the setup. Can someone explains what is the different between <strong>volumes.hostPath</strong> and <strong>volumeMounts.mountPath</strong>? I read some documentations online but it does not help me to understand.</p>

<pre><code>volumeMounts:
  - mountPath: /var/lib/mysql

volumes:
  hostPath:
    path: /k8s
</code></pre>

<p>If my setup is as above, is the volume going to be mounted at <code>/k8s/var/lib/mysql</code>?</p>

<p>The mount path is always the destination inside the Pod a volume gets mounted to.</p>

<p>I think the documentation is pretty clear on what hostPath does:</p>

<blockquote>
  <p>A hostPath volume mounts a file or directory from the host node’s
  filesystem into your Pod. This is not something that most Pods will
  need, but it offers a powerful escape hatch for some applications.</p>
  
  <p>For example, some uses for a hostPath are:</p>

<pre><code>- running a Container that needs access to Docker internals; use a hostPath of /var/lib/docker
- running cAdvisor in a Container; use a hostPath of /sys
- allowing a Pod to specify whether a given hostPath should exist prior to the Pod running, whether it should be created, and what it should exist as
</code></pre>
</blockquote>

<p>So your example does not what you think it does. It would mount the node's <code>/k8s</code> directory into the Pod at <code>/var/lib/mysql</code>.</p>

<p>This should be done only if you fully understand the implications!</p>
