<p>I'm using kubectl to deploy ASP.Net core apps to K8S cluster.
At the current moment I hardcode container PORTs and ConnectionString for DataBase like this:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: mydeploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mydeploy
  template:
    metadata:
      labels:
        app: mydeploy
    spec:
      containers:
        - name: mydeploy
          image: harbor.com/my_app:latest
          env:
          - name: MyApp__ConnectionString
            value: &quot;Host=postgres-ap-svc;Port=5432;Database=db;Username=postgres;Password=password&quot;
          ports:
            - containerPort: 5076
</code></pre>
<p>But the good solution I think - to use such variables from <code>appsettings.json</code> file (ASP.Net config file).
<strong>So my question - How to load this vars from JSON file and use in yaml file?</strong></p>
<p>JSON file is like this:</p>
<pre><code>{
  &quot;MyApp&quot;: {
    &quot;ConnectionString&quot;: &quot;Host=postgres-ap-svc;Port=5432;Database=db;Username=postgres;Password=password&quot;
  },
  &quot;ClientBaseUrls&quot;: {
    &quot;MyApp&quot;: &quot;http://mydeploy-svc:5076/api&quot;,
  }
}
</code></pre>

<p>You can use following command to create configmap and then mount it to your contianer</p>
<pre><code>kubectl create configmap appsettings --from-file=appsettings.json --dry-run -o yaml
</code></pre>
<p>For mounting you should add a volume to your deployment or sts like this:</p>
<pre><code>  volumes:
    - name: config
      configMap:
        name: appsettings
</code></pre>
<p>And then mount it to your container:</p>
<pre><code> volumeMounts:
        - mountPath: /appropriate/path/to/config/appsettings.json
          subPath: appsettings.json
          name: config
</code></pre>
<p>Also if you want you can use the config map as your environment variables source like this:</p>
<pre><code>envFrom:
      - configMapRef:
          name: config
</code></pre>
