<p>I want to update the existing file <code>settings.ini</code> in container at the time of helm deployment without harming existing data in container.</p>
<p>Here are my helm files -</p>
<p><code>config.yaml</code></p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Values.metadata.name }}-config
data:
  settings.ini: |
    [server]
    hostname = &quot;localhost&quot;
    hot_deployment = false
    # offset  = 10

    [user_store]
    type = &quot;read_only_ldap&quot;
</code></pre>
<p>deployment part from <code>Deployment.yaml</code></p>
<pre class="lang-yaml prettyprint-override"><code>containers:
  - name: {{ .Chart.Name }}
    securityContext:
      {{- toYaml .Values.securityContext | nindent 12 }}
    image: &quot;{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}&quot;
    imagePullPolicy: {{ .Values.image.pullPolicy }}
    ports:
      - name: http
        containerPort: 80
        protocol: TCP
    volumeMounts:
    - name: config-volume
      mountPath: /home/bin/conf/
      subPath: settings.ini
volumes:
  - name: config-volume
    configMap:
      name: {{ .Values.metadata.name }}-config
</code></pre>
<p>I can see it creating config map successfully but when I check logs in the cluster it complains about missing files</p>
<p>How can I resolve this issue?</p>
<p>Also is there any efficient way to achieve this, if I just want to update some of the configurations for my <code>settings.ini</code> file with different values in different env?</p>

megha
<p>In the recent versions of k8s <a href="https://kubernetes.io/docs/concepts/configuration/configmap/#mounted-configmaps-are-updated-automatically" rel="nofollow noreferrer">Mounted ConfigMaps are Updated Automatically</a>:</p>
<blockquote>
<p>When a ConfigMap currently consumed in a volume is updated, projected keys are eventually updated as well. The kubelet checks whether the mounted ConfigMap is fresh on every periodic sync.</p>
</blockquote>
<blockquote>
<p>A container using a subPath volume mount may not receive the updates.</p>
</blockquote>
<h3>Possible solution:</h3>
<p>Use two containers:</p>
<ul>
<li>Main Container: Will run your application, listen to a specific port/endpoint_path for HTTP requests. On receiving the request, your application should reload the configurations. Since the <code>subPath</code> method is avoided, you may store the configMap to some other directory, later move/update to the desired directory while reloading configurations.</li>
<li>SideCar: Will run file change watcher like <a href="https://github.com/jimmidyson/configmap-reload" rel="nofollow noreferrer">configmap-reload</a>, on changes of file it will send an HTTP request to the main container.</li>
</ul>
<p>Sample:</p>
<pre class="lang-yaml prettyprint-override"><code>containers:
  - name: main-container
    image: application:v1.0.0
    ports:
      - name: http
        containerPort: 80
        protocol: TCP
    volumeMounts:
    - name: config-volume
      mountPath: /some/path

  - name: side-car
    image: jimmidyson/configmap-reload:latest
    args:
    - &quot;-volume-dir=/some/path&quot;
    - &quot;-webhook-url=localhost:80/reload-config&quot;
    volumeMounts:
    - name: config-volume
      mountPath: /some/path

volumes:
  - name: config-volume
    configMap:
      name: {{ .Values.metadata.name }}-config

</code></pre>
