<p>For example I want to place an application configuration file inside:</p>

<pre><code>/opt/webserver/my_application/config/my_config_file.xml
</code></pre>

<p>I create a ConfigMap from file and then place it in a volume like: </p>

<pre><code>/opt/persistentData/
</code></pre>

<p>The idea is to run afterwards an script that does something like: </p>

<pre><code>cp /opt/persistentData/my_config_file.xml  /opt/webserver/my_application/config/
</code></pre>

<p>But it could be any startup.sh script that does needed actions. </p>

<p>How do I run this command/script? (during Pod initialization before Tomcat startup).</p>

Alexander Meise
<p>I would first try if this works.</p>

<pre><code>  spec:
    containers:
    - volumeMounts:
      - mountPath: /opt/webserver/my_application/config/my_config_file.xml
        name: config
        subPath: my_config_file.xml
    volumes:
    - configMap:
        items:
        - key: KEY_OF_THE_CONFIG
          path: my_config_file.xml
        name: config
      name: YOUR_CONFIGMAP_NAME
</code></pre>

<p>If not, add an <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">init container</a> to copy the file.</p>

<pre><code>spec:
  initContainers:
  - name: copy-config
    image: busybox
    command: ['sh', '-c', '/bin/cp /opt/persistentData/my_config_file.xml  /opt/webserver/my_application/config/']
</code></pre>
