<p>I have one own nginx configuration <code>/home/ubuntu/workspace/web.conf</code> generated by script. I prefer to have it under <code>/etc/nginx/conf.d</code> besides <code>default.conf</code></p>

<p>Below is the <code>nginx.yaml</code></p>

<pre>
apiVersion: v1
kind: Pod
metadata:
    name: nginx
spec:
    volumes:
      - name: webconf
        hostPath:
          path: /home/ubuntu/workspace/web.conf
    containers:
      - image:  nginx
        name: nginx
        ports:
          - containerPort: 18001
            protocol: TCP                               
        volumeMounts:
          - mountPath: /etc/nginx/conf.d/web.conf
            name: web
</pre>

<p>While it is mapped as folder only</p>

<pre>
$ kubectl create -f nginx.yaml
pod "nginx" created
$ kubectl exec -it nginx -- bash
root@nginx:/app# ls -al /etc/nginx/conf.d/
total 12
drwxr-xr-x 1 root root 4096 Aug  3 12:27 .
drwxr-xr-x 1 root root 4096 Aug  3 11:46 ..
-rw-r--r-- 2 root root 1093 Jul 11 13:06 default.conf
drwxr-xr-x 2 root root    0 Aug  3 11:46 web.conf
</pre>

<p>It works for docker container <code>-v hostfile:containerfile</code>.</p>

<p>How can I do this in kubernetes ?</p>

<p>BTW: I use minikube <code>0.21.0</code> on <code>Ubuntu 16.04 LTS</code> with <code>kvm</code></p>

<p>Try using the <code>subPath</code> key on your <code>volumeMounts</code> like this:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: singlefile
spec:
  containers:
  - image: ubuntu
    name: singlefiletest
    command:
      - /bin/bash
      - -c
      - ls -la /singlefile/ &amp;&amp; cat /singlefile/hosts
    volumeMounts:
    - mountPath: /singlefile/hosts
      name: etc
      subPath: hosts
  volumes:
  - name: etc
    hostPath:
      path: /etc
</code></pre>

<p>Example:</p>

<pre><code>$ kubectl apply -f singlefile.yaml
pod "singlefile" created
$ kubectl logs singlefile
total 24
drwxr-xr-x. 2 root root 4096 Aug  3 12:50 .
drwxr-xr-x. 1 root root 4096 Aug  3 12:50 ..
-rw-r--r--. 1 root root 1213 Apr 26 21:25 hosts
# /etc/hosts: Local Host Database
#
# This file describes a number of aliases-to-address mappings for the for 
# local hosts that share this file.
...
</code></pre>
