Hi AspNetZero,
We have been migrating AspNetZero in docker using Kubernetes.
Currently, our settings like SQL Connection String (i.e.ConnectionStrings in appsettings.json) are hard-coded in these appsettings json files as seen below. What we are currently doing now is we split the appsettings based on the environment and we just set ASPNETCORE_ENVIRONMENT as env variable according to the environment where it's deployed and running.
We would like to move all these settings as environment variables in Kubernetes as we did with our other apps. Please let us know how to properly do it.
Regards, Allan
5 Answer(s)
-
0
Hi shipserv Do you want to load the configuration items in appsettings.json into environment variables?
-
0
hi Zony,
Yes, that's right. So that all sensitive data such as database connection string will be stored on environment variables rather than in codes of appsettings.json. We don't want these configs to be hardcoded.
Regards, Allan
-
0
hi shipserv, I think you should create an env.yml in which to write environment variables according to the rules. example:
apiVersion: apps/v1 kind: Deployment metadata: name: test-service labels: app: test-service spec: selector: matchLabels: app: test-service template: metadata: labels: app: test-service spec: containers: - name: test-service env: - name: ConnectionStrings__Default value: User ID=postgres;Password=XXXX;Host=XXXX;Port=1433;Database=TestDataBase; - name: ConnectionStrings__AbpTenantManagement value: User ID=postgres;Password=XXX;Host=XXXX;Port=1433;Database=TestDataBase; - name: IdentityServer__AuthorityServer value: http://localhost:5000
Naming rules: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1#environment-variables
-
0
You can also separate environment variables. configMap.yml
apiVersion: v1 data: ConnectionStrings__Default: User ID=postgres;Password=XXXX;Host=XXXX;Port=1433;Database=TestDataBase; kind: ConfigMap metadata: labels: app: test-service name: test-service-config
deploy.yml
apiVersion: apps/v1 kind: StatefulSet metadata: name: test-service labels: app: test-service spec: selector: matchLabels: app: test-service serviceName: test-service replicas: 2 updateStrategy: type: RollingUpdate template: metadata: labels: app: test-service spec: containers: - image: xxx:latest name: test-service envFrom: - configMapRef: name: test-service-config # Here
-
0
Hi @shipserv,
It should work out of the box, see https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/Configuration/AppConfigurations.cs#L37. Have you tried this ?