<p>I'm trying to configure Nginx container on Openshift. My final goal is to overwrite Nginx config file. I know it's possible using config maps. Because any failure with modifying Nginx config directories is crashing the container, temporarily my goal is to just create an index.html file in /opt/app-root/src directory.</p>

<p>I'm facing two problems depends on the configuration</p>

<ul>
<li>config map overwrite whole /opt/app-root/src directory</li>
<li>config map creates index.html directory with index file inside</li>
</ul>

<p>Config map:</p>

<pre><code>apiVersion: v1
data:
  index: |-
    &lt;html&gt;
    &lt;body&gt;
    yo yo!
    &lt;/body&gt;
    &lt;/html&gt;
kind: ConfigMap
metadata:
  creationTimestamp: '2020-01-16T12:53:25Z'
  name: index-for-nginx
  namespace: some-namespace
</code></pre>

<p>Deployment config (part, related to the topic):</p>

<pre><code>spec:
  containers:
    - image: someimage
      ...
      volumeMounts:
        - mountPath: /opt/app-root/src/index.html
          name: index
  volumes:
    - configMap:
        defaultMode: 420
        name: index-for-nginx
      name: index
</code></pre>

<p>When:</p>

<pre><code>volumeMounts:
            - mountPath: /opt/app-root/src/index.html
</code></pre>

<p>It creates index.html directory and index file (with proper content) in /opt/app-root/src</p>

<p>When:</p>

<pre><code>volumeMounts:
            - mountPath: /opt/app-root/src/
</code></pre>

<p>It overwrites /opt/app-root/src directory</p>

<p>My question is - how should I configure it to create index.html file in /opt/app-root/src without overwriting the directory?</p>

<p>You can use <code>subPath</code> to mount the single file you want.</p>

<pre><code>volumeMounts:
  - mountPath: /opt/app-root/src/index.html
    subPath: index
    name: index

</code></pre>

<p><a href="https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath</a></p>
