<p>I have a statefulSet where I have an ElasticSearch image running. I want to copy the certificates through Kubernetes secrets into files. I mkdir the folder where I want the certificates to go and then echo the env variable w/ the cert into a file. I can log into the specific container and the env variable is populated, however this copy step just doesn't work. The mkdir never fired and no cert is present.</p>
<pre><code>      initContainers:
      - name: certificates
        image: busybox
        command: [&quot;sh&quot;, &quot;-c&quot;, &quot;mkdir -p /usr/share/elasticsearch/certs &amp;&amp; echo $gd_bundle_g2_g1_crt &gt; /usr/share/elasticsearch/certs/gd_bundle-g2-g1.crt&quot;]
        securityContext:
          privileged: true
</code></pre>
<p>If I run the command in the pod after I log in, it works fine. It just doesn't work as part of the initContainer.</p>
<p>Since the image is &quot;busybox&quot;, it's my understanding that this is an initialization container outside of the main elasticsearch one. Does the init container have access to the file system then used by the main elasticsearch container? Pointers appreciated.</p>

mj_
<p>According to your spec, I do not see any volume mounted. So you mkdir only on the initContainer and when it is done, your copy is gone.</p>
<p>As a solution, you could mount a volume (it could be PVC, or an <code>emptyDir</code>) on both initContainer and your main container on the path you want to copy your cert (<code>/usr/share/elasticsearch/certs</code>).</p>
