<p>I have containerized microservice built with Java. This application uses the default <code>/config-volume</code> directory when it searches for property files.<br />
Previously I manually deployed via <code>Dockerfile</code>, and now I'm looking to automate this process with <em>Kubernetes</em>.</p>
<p>The container image starts the microservice immediately so I need to add properties to the config-volume folder immediately. I accomplished this in Docker with this simple <code>Dockerfile</code>:</p>
<pre><code>FROM ########.amazon.ecr.url.us-north-1.amazonaws.com/company/image-name:1.0.0

RUN mkdir /config-volume
COPY path/to/my.properties /config-volume
</code></pre>
<p>I'm trying to replicate this type of behavior in a kubernetes <code>deployment.yaml</code> but I have found no way to do it.</p>
<p>I've tried performing a <code>kubectl cp</code> command immediately after applying the deployment and it sometimes works, but it can result in a race condition which cause the microservice to fail at startup.</p>
<p>(I've redacted unnecessary parts)</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-service
spec:
  replicas: 1
  template:
    spec:
      containers:
      - env:
        image: ########.amazon.ecr.url.us-north-1.amazonaws.com/company/image-name:1.0.0
        name: my-service
        ports:
        - containerPort: 8080
        volumeMounts:
        - mountPath: /config-volume
          name: config-volume
      volumes:
        - name: config-volume
          emptyDir: {}
status: {}
</code></pre>
<p>Is there a way to copy files into a volume inside the <code>deployment.yaml</code>?</p>

Joe Caruso
<p>You are trying to emulate a <code>ConfigMap</code> using volumes. Instead, put your configuration into a <code>ConfigMap</code>, and mount that to your deployments. The documentation is there:</p>

<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/</a></p>

<p>Once you have your configuration as a <code>ConfigMap</code>, mount it using something like this:</p>

<pre><code>...
  containers:
    - name: mycontainer
      volumeMounts:
      - name: config-volume
        mountPath: /config-volume
  volumes:
    - name: config-volume
      configMap:
        name: nameOfConfigMap
</code></pre>
