<p>My service need a cfg file which need to be changed before containers start running. So it is not suitable to pack the cfg into docker image.
I need to copy from cluster to container, and then the service in container start and reads this cfg.</p>

<p>How can I do this?</p>

<p>I think for your use-case , <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="noreferrer">Init Containers</a> might be the best fit. Init Containers are like small scripts that you can run before starting your own containers in kubernetes pod , they must exit. You can have this config file updated in shared Persistent Volume between your Init container and your container. </p>

<p>Following article gives a nice example as to how this can be done</p>

<p><a href="https://medium.com/@jmarhee/using-initcontainers-to-pre-populate-volume-data-in-kubernetes-99f628cd4519" rel="noreferrer">https://medium.com/@jmarhee/using-initcontainers-to-pre-populate-volume-data-in-kubernetes-99f628cd4519</a></p>

<p><strong>UPDATE :</strong></p>

<p>I found another answer from stackoverflow which might be related and give you a better approach in handling this</p>

<p><a href="https://stackoverflow.com/questions/50012601/can-i-use-a-configmap-created-from-an-init-container-in-the-pod">can i use a configmap created from an init container in the pod</a></p>
