<p>The <a href="https://github.com/kubernetes/minikube/blob/master/README.md" rel="nofollow noreferrer">kubernetes docs</a> provides for each OS and each driver the name VM when mounting a volume of type <strong>hostPath</strong>.</p>

<p>Nevertheless, it is missing that case:</p>

<ul>
<li>OS: linux</li>
<li>Driver: kvm</li>
<li>Host folder: /home</li>
<li>VM folder: ???</li>
</ul>

<p>This is the targeted deployment I would like to use in order to avoid to recreate the image after each change of the code.</p>

<p>This is only for the development env. In the production env, the code will be directly in the image.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
    name: php-hostpath
spec:
  replicas: 1
  template:
    metadata:
  labels:
    app: php-hostpath
spec:
  containers:
  - name: php-hostpath
    image: php:7.0-apache
    ports:
    - containerPort: 80
    volumeMounts:
      - name: vol-php-hostpath
        mountPath: /var/www/html
  volumes:
  - name: vol-php-hostpath
    hostPath:
      path: /hosthome/amine/DockerProjects/gcloud-kubernetes/application/06-hostPath-volume-example-minikube/src/
</code></pre>

<p>Thanks...</p>

<p>Based on this <a href="https://github.com/kubernetes/minikube/blob/master/README.md" rel="nofollow noreferrer">doc</a>, Host folder sharing is not implemented in the KVM driver yet. This is the driver I am using actually.</p>

<p>To overcome this, there are 2 solutions:</p>

<ul>
<li><p>Use the <strong>virtualbox</strong> driver so that you can mount your hostPath volume by changing the path on you localhost <code>/home/THE_USR/...</code> to <code>/hosthome/THE_USR/...</code> </p></li>
<li><p>Mount your volume to the minikube VM based on the command <code>$ minikube mount /home/THE_USR/...</code>. The command will return you the path of your mounted volume on the minikube VM. Example is given down.</p></li>
</ul>

<h1>Example</h1>

<p><strong>(a) mounting a volume on the minikube VM</strong></p>

<p>the <code>minikube mount</code> command returned that path /mount-9p</p>

<pre><code>$ minikube mount -v 3 /home/amine/DockerProjects/gcloud-kubernetes/application/06-hostPath-volume-example-minikube
Mounting /home/amine/DockerProjects/gcloud-kubernetes/application/06-hostPath-volume-example-minikube into /mount-9p on the minikubeVM
This daemon process needs to stay alive for the mount to still be accessible...
2017/03/31 06:42:27 connected
2017/03/31 06:42:27 &gt;&gt;&gt; 192.168.42.241:34012 Tversion tag 65535 msize 8192 version '9P2000.L'
2017/03/31 06:42:27 &lt;&lt;&lt; 192.168.42.241:34012 Rversion tag 65535 msize 8192 version '9P2000'
</code></pre>

<p><strong>(b) Specification of the path on the deployment</strong></p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: php-hostpath
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: php-hostpath
    spec:
      containers:
      - name: php-hostpath
        image: php:7.0-apache
        ports:
        - containerPort: 80
        volumeMounts:
          - name: vol-php-hostpath
            mountPath: /var/www/html
      volumes:
      - name: vol-php-hostpath
        hostPath:
          path: /mount-9p
</code></pre>

<p><strong>(c) Checking if mounting the volume worked well</strong></p>

<pre><code>amine@amine-Inspiron-N5110:~/DockerProjects/gcloud-kubernetes/application/06-hostPath-volume-example-minikube$ kubectl exec -ti php-hostpath-3498998593-6mxsn bash
root@php-hostpath-3498998593-6mxsn:/var/www/html# cat index.php 
&lt;?php
echo "This is my first docker project";
root@php-hostpath-3498998593-6mxsn:/var/www/html# cat index.php                                                                                                                                 
&lt;?php

echo 'This is my first hostPath on kubernetes';
root@php-hostpath-3498998593-6mxsn:/var/www/html# cat index.php 
&lt;?php

echo 'This is my first hostPath on kubernetes';
root@php-hostpath-3498998593-6mxsn:/var/www/html# 
</code></pre>

<p><strong>NB:</strong> this kind of volume mounting is only development environment. If I were in production environment, the code will not be mounted: it will be in the image.</p>

<p>Hope it helps others.</p>
