<p>I want to overwrite the file on the pod container. Right now I have <code>elasticsearch.yml</code> at location <code>/usr/share/elasticsearch/config</code>.</p>
<p>I was trying to achieve that with <code>initContainer</code> at kubernetes deployment file, so I added something like:</p>
<pre class="lang-yaml prettyprint-override"><code>        - name: disabled-the-xpack-security
          image: busybox
          command: 
          - /bin/sh 
          - -c 
          - |
            sleep 20
            rm /usr/share/elasticsearch/config/elasticsearch.yml 
            cp /home/x/IdeaProjects/BD/infra/istio/kube/elasticsearch.yml /usr/share/elasticsearch/config/
          securityContext:
            privileged: true
</code></pre>
<p>But this doesn't work, error looks like:</p>
<pre><code>rm: can't remove '/usr/share/elasticsearch/config/elasticsearch.yml': No such file or directory
cp: can't stat '/home/x/IdeaProjects/BD/infra/istio/kube/elasticsearch.yml': No such file or directory
</code></pre>
<p>I was trying to use some <code>echo &quot;some yaml config&quot; &gt;&gt; elasticsearch.yml</code>, but this kind of workarounds doesn't work, because I was able to keep proper yaml formatting.</p>
<p>Do you have any suggestions, how can I do this?</p>

Ice
<p>Note if you don't want to override everything in the mounted directory you could mount the file only using &quot;subPath&quot; in whatever directory you want.</p>
<p><a href="https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath" rel="noreferrer">https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath</a></p>
