ASPNETCORE_ENVIRONMENT env variables pass in docker and kubernetes

We have aspnet core 2.1 application and we are using Azure Pipeline to build and release the application.

We are using docker build to build image in the build pipeline and deploy the application to Kubernetes in the release pipeline.

Now we would like to build the image once and deploy the image to Kubernetes in 3 stages (Development, Staging, and Production).

We are using ASPNETCORE_ENVIRONMENT environment variable to differentiate the stages. We tried to use this variable in DockerFile and Kubernetes deployment.azure.yaml file. Also, We have configured Docker Profile in launchsettings.json in the application.

“Docker”: {
“commandName”: “Docker”,
“environmentVariables”: {
“ASPNETCORE_ENVIRONMENT”: “”,
“ASPNETCORE_URLS”: “”,
“DOTNET_ENVIRONMENT”: “Staging”
}
},

But still, the environment variables are not working as expected. Every time we deploy the application to Kubernetes It is taking the Development variable.

Please suggest a better plan or changes achieve “Build Once, Deploy Everywhere” strategy.

Thanks,
Mrugesh