<p>I have a ASP.NET Core Worker Service which gets some information like thread count, batch size etc. from <code>appsettings.json</code>. These settings will only take affect on startup and cannot be change when the service is running.
The application will be running in a kubernetes cluster.</p>
<p>What is the best practice for changing these settings while deployed in production?
What I need to have done is, changing the settings and restart the service.</p>
<p>I can come up with these solution:</p>
<ol>
<li>Mapping <code>appsetttings.json</code> to a volume, to be able to change it, so that when container is restarted the appsettings is not reverted.
<ul>
<li>Do I need to move the <code>appsettings.json</code> file to another folder then root? Is there something about not mapping the running application to a volume?</li>
</ul>
</li>
<li>Update the containers environment variables to override settings.
<ul>
<li>Will these settings be reverted back when the container is restarted?)</li>
</ul>
</li>
</ol>
<p>Any other ideas?</p>

Michael
<p>If your application can be configured both with a configuration file and with environment variables, my experience has been that using environment variables is easier.  There are several aspects of this:</p>
<ul>
<li><p>You can directly include the environment variable in your deployment specification</p>
<pre class="lang-yaml prettyprint-override"><code>env:
   - name: SOME_CONFIG_SETTING
     value: its value
</code></pre>
<p>For a config file you need to <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-volume" rel="nofollow noreferrer">create a separate ConfigMap object, add it to a per-pod volume, and mount the volume in a container</a>.  That's routine and well-documented, but harder than just setting an environment variable.</p>
</li>
<li><p>If you use <a href="https://helm.sh" rel="nofollow noreferrer">Helm</a> to deploy your application, it's very easy to substitute a configuration value at deploy time</p>
<pre class="lang-yaml prettyprint-override"><code>- name: SOME_CONFIG_SETTING
   value: {{ .Values.someConfigSetting | default &quot;its value&quot; }}
</code></pre>
</li>
<li><p>If you change the value of the environment variable in the deployment spec, that's enough of a change to automatically delete and recreate the pods running the container; that is, you will get an automatic restart.  If the configuration settings are in a ConfigMap, absent some <a href="https://docs.helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments" rel="nofollow noreferrer">Helm hackery</a>, you will need to manually restart the deployment when the configuration changes.</p>
</li>
</ul>
<p>You should not use <code>kubectl exec</code> here, and you should not need to try to manually restart the process running inside a container.  If a pod is managed by a deployment, <code>kubectl delete pod deployment-name-12345-abcde</code> will cause it to immediately be recreated, effectively restarting that replica of the service.</p>
