Working a lot with .NET Core, using colon (‘:’) in appsettings is quite common. This allow a better separation of variables and, in the end, a better visibility.

Today, I’ve encountered an issue when trying to deploy my ASP.NET Core application on Kubernetes cluster:

##[error]The Deployment "XXXX" is invalid: spec.template.spec.containers[0].env[10].name: Invalid value: "PropertyName:PropertyValue": a valid environment variable name must consist of alphabetic characters, digits, '_', '-', or '.', and must not start with a digit (e.g. 'my.env-name',  or 'MY_ENV.NAME',  or 'MyEnvName1', regex used for validation is '[-._a-zA-Z][-._a-zA-Z0-9]*')

Ok, that’s gonna be funny 🙂

As I didn’t wanted to change my code to replace colon with something else, I searched on Internet and found the following Github issue: https://github.com/kubernetes/kubernetes/issues/53201

This allow me to find the good solution (as usual, explained in the documentation: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/index?tabs=basicconfiguration&view=aspnetcore-3.1#environment-variables-configuration-provider). Indeed, the current workaround is just to replace ‘:’ with “__” (double underscore) when you define your environment variable:

env:
    - name: PropertyName
    value: "PropertyValue"

Pretty simple actually (when you know it ;))

Happy coding !


How to write a pull request comment during your Azure DevOps build ? Why my Azure Media Services assets are not displayed?

Leave a Reply

Your email address will not be published. Required fields are marked *