<p>I'm following example found <a href="http://kubecloud.io/minikube-workflows/" rel="nofollow noreferrer">here</a>.</p>

<p>I'm simply trying to understand how volumes work with Kubernetes.  I'm testing locally so I need to contend with minikube.  I'm trying to make this as simple as possible.  I'm using nginx and would like to have it display content that is mounted from a folder on my localhost.</p>

<p>Environment:
macOS 10.12.5
minikube 0.20.0 + xhvve VM</p>

<p>I'm using the latest <a href="https://hub.docker.com/_/nginx/" rel="nofollow noreferrer">ngninx image from GitHub</a> with no modifications. </p>

<p>This works perfectly when I run the docker image outside of minikube.</p>

<pre><code>docker run --name flow-4 \
 -v $(pwd)/website:/usr/share/nginx/html:ro \
 -P -d nginx
</code></pre>

<p>But <strong>when I try to run it in minikube I get a 404 response when I visit the hosted page -always.  Why?</strong></p>

<p>Here are my kubernetes config files...<br>
kubernets/deploy/deployment.yaml</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    run: flow-4
  name: flow-4
spec:
  replicas: 1
  selector:
    matchLabels:
      run: flow-4
  template:
    metadata:
      labels:
        run: flow-4
    spec:
      containers:
      - image: nginx
        name: flow-4
        ports:
        - containerPort: 80

        volumeMounts:
        - mountPath: /usr/share/nginx/html
          name: flow-4-volume
      volumes:
      - name: flow-4-volume
        hostPath:
          path: /Users/myuser/website
</code></pre>

<p>kubernets/deploy/svc.yaml</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    run: flow-4
  name: flow-4
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    run: flow-4
  type: NodePort
</code></pre>

<p>Finally, I run it like this:</p>

<pre><code>kubectl create -f kubernetes/deploy/
minikube service flow-4
</code></pre>

<p>When it opens in my browser, instead of seeing my index.html page in the website folder, I just get a '404 Not Found' message (above a nginx/1.13.3 footer)</p>

<p><strong>Why am I getting 404?  Is nginx not able to see the contents of my mounted folder?</strong>  Does the VM hosting kubernetes not have access to my 'website' folder?</p>

<p>I suspect this is the problem.  I ssh into the kubernetes pod</p>

<pre><code>kubectl exec -it flow-4-1856897391-m0jh1 /bin/bash
</code></pre>

<p>When I look in the /usr/share/nginx/html folder, it is empty.  If I manually add an index.html file, then I can see it in my browser.  But why won't Kubernetes mount my local drive to this folder?</p>

<p><strong>Update</strong>  </p>

<p>There seems to be something wrong with mounting full paths from my /Users/** folder.  Instead, I used the 'minikube mount' command to mount local folder container index.html into the minikube VM. Then in a separate terminal I started my deployment and it could see the index.html file just fine.  </p>

<p>Here is my updated deployment.yaml file which has clearer file names to better explain the different folders and where they are mounted...</p>

<p>Here are my kubernetes config files...<br>
kubernets/deploy/deployment.yaml</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    run: flow-4
  name: flow-4
spec:
  replicas: 1
  selector:
    matchLabels:
      run: flow-4
  template:
    metadata:
      labels:
        run: flow-4
    spec:
      containers:
      - image: nginx
        name: flow-4
        ports:
        - containerPort: 80

        volumeMounts:
        - mountPath: /usr/share/nginx/html
          name: flow-4-volume
      volumes:
      - name: flow-4-volume
        hostPath:
          path: /kube-website
</code></pre>

<p>It's using the same svc.yaml file from earlier in the post.</p>

<p>I then ran the whole thing like this from my current directory.<br>
1. <code>mkdir local-website</code><br>
2. <code>echo 'Hello from local storage' &gt; local-website/index.html</code><br>
3. <code>minikube mount local-website:/kube-website</code><br>
Let this run....  </p>

<p>In a new terminal, same folder...<br>
4. <code>kubectl create -f kubernetes/deploy/</code>  </p>

<p>Once all the pods are running...<br>
5. <code>minikube service flow-4</code>  </p>

<p>You should see the 'Hello from local storage' message great you in your browser.  You can edit the local index.html file and then refresh your browser to see the contents change.</p>

<p>You can tear it all down with this... 
<code>kubectl delete deployments,services flow-4</code></p>

<p>Probably the folder you created is not in kubernetes node (it is minikube vm).</p>

<p>Try to create folder inside vm and try again</p>

<pre><code>ssh -i ~/.minikube/machines/minikube/id_rsa docker@$(minikube ip)
mkdir /Users/myuser/website
</code></pre>

<p>Also take a look at <a href="https://github.com/kubernetes/minikube/blob/master/docs/host_folder_mount.md" rel="nofollow noreferrer">minikube host mount folder</a> feature</p>
