.NET Core App Settings with Kubernetes Deployment

Hi All,

Our .NET Core applications have been using appsettings.json file to store of its app settings. When deploying to the different Azure environments, we are using Octopus’s feature to transform json files on each deployment.

How do you do the same with Kubernetes (k8s) deployment?

When the k8s deployment step starts, the container image must already exist, and there’s no way of editing the appsettings.json within it. So we have been re-building the image from a nuget package during each deployment (we are using Azure Container Registry to build our images), although this approach works, it is not ideal for so many reason.

Ideally, we would like to do the following:

  1. Unpack a nuget package (from octopus package source)
  2. Pick the ‘appsettings.json’ in the package
  3. Perform variable substitution on the file
  4. Create a ‘Config Map’ resource in K8s based on the newly transformed appsettings.json
  5. Use the above Config Map resource during K8s deployment

Any ideas how to do this?

Hi @sireza, thanks for reaching out.

There are two ways you can tackle this.

The first is similar to the steps you have described:

  1. Place your Kubernetes configmap template file in a Nuget package.
  2. Create a Run a kubectl CLI Script step.
  3. Add the Nuget package as an additional package. The blog post at https://octopus.com/blog/script-step-packages has details on this.
  4. Enable the Substitute Variables in File feature. The documentation at https://octopus.com/docs/deployment-process/configuration-features/substitute-variables-in-files has more information on this feature.
  5. The script itself can then upload the processed configmap file with a command like kubectl create -f configmap.yaml.
  6. The new configmap can be mounted either as environment variables or as a file in the Kubernetes pod.

Alternatively you can define a ConfigMap directly in the Deploy Kubernetes containers step. The documentation at https://octopus.com/docs/deployment-examples/kubernetes-deployments/deploy-container#conifgmap has more details on this feature.

Matt C

Thanks for the pointer. Got it working