# Video

# Overriding Configuration At Runtime

ASP.NETCore provides a machanism for overriding the appsettings.json at runtime. This provides a simple way to "inject" our runtime configuration from a Kubernetes/OpenShift ConfigMap or Secret.

  1. Modify the Program.cs to add an optional configuration file to be loaded
    public static IHostBuilder CreateHostBuilder(string[] args) =>
             .ConfigureAppConfiguration((hostingContext, config) =>
                config.AddJsonFile("/tmp/config/runtimesettings.json", optional: true, reloadOnChange: false);
             // SNIP - Remaining Host Builder
  2. Now, when we deploy our application on OpenShift, it will look for a file in /tmp/config called runtimesettings.json and those settings will override any settings in our appsettings.json.
  3. We can define our Deployment or DeploymentConfig such that we mount a ConfigMap or Secret containing that JSON configuration in that location
Last Updated: 12/18/2021, 5:53:27 PM