<p>I'm using a Helm chart to deploy an app in the Kubernetes. After deployment, I want to copy a file from the chart repository to the container. </p>

<p>Currently I am doing this manually:</p>

<pre><code>kubectl cp custom-samples.json che-8467596d54-7c2hg:/data/templates
</code></pre>

<p>But I want to make this step a part of the deployment that will be performed automatically. Note that I took a look at <code>post-install</code> hooks but I'm not sure it's a good solution.</p>

<p>[UPD] I created this init container:</p>

<pre><code> - name: add-custom-samples
        image: alpine:3.5
        command: ["sh", "-c", "cd /data/templates; touch custom.json;"]
        volumeMounts: [{
              "mountPath": "/data",
              "name": "che-data-volume"
        }]
</code></pre>

<p>But the file <code>custom.json</code> is missing in the mounted volume.</p>

kostiamol
<p>You can <a href="https://docs.helm.sh/chart_template_guide/#accessing-files-inside-templates" rel="noreferrer">include your file in the Helm chart</a>.  You'd generally include that in a Kubernetes ConfigMap object, which can then be <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-volume" rel="noreferrer">mounted in a Pod as a volume</a>.</p>

<p>You need to move the file to somewhere in the Helm chart directory; say it's in <code>charts/mychart/files/custom-samples.json</code>.  You can create a ConfigMap in, say, <code>charts/mychart/templates/configmap.yaml</code> that would look like</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  custom-samples.json" |-
{{ .Files.Get "custom-samples.json" | indent 4 }}
</code></pre>

<p>Then in your Deployment's Pod spec, you'd reference this:</p>

<pre><code>apiVersion: v1
kind: Deployment
spec:
  template:
    spec:
      volumes:
        - name: config
          configMap:
            name: {{ .Release.Name }}-configmap
      containers:
        - name: ...
          volumeMounts:
            - name: config
              mountPath: /data/templates
</code></pre>

<p>Note that this approach causes the file to be stored as a Kubernetes object, and there are somewhat modest size limits; something that looks like a text file and is sized in kilobytes should be fine.  Also, if there are other files in the <code>/data/templates</code> directory, this approach will cause them to be hidden in favor of whatever's in the ConfigMap.</p>
