<p>I am trying to read the environment variable declared in deployment yaml of Kubernetes into springboot application.yaml</p>
<p>Below is sample in deployment.yaml</p>
<pre><code>    spec:
      containers:
        env:
        - name: SECRET_IN
          value: dev
</code></pre>
<p>Below is sample in application.yaml</p>
<pre><code>    innovation:
      in: ${SECRET_IN:demo}
</code></pre>
<p>But on localhost when I try to print innovation.in (@Configuration is created correctly) I am not getting &quot;dev&quot; in  output, it always prints <em>demo</em>, it appears the link between deployment, application yaml is not happening ,could someone please help.</p>

Ravi Sharma
<p>You can store the whole <code>application.YAML</code> config file into the <code>config map</code> or <code>secret</code> and inject it with the deployment only</p>
<p>For example :</p>
<pre><code>kind: ConfigMap
apiVersion: v1
metadata:
  name: demo
data:
  application.yaml: |-
    pool:
      size:
        core: 1
        max:16
</code></pre>
<p>if your <code>application.properties</code> is something like</p>
<p>example:</p>
<pre><code>spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/dbname
spring.datasource.username=user
spring.datasource.password=password
</code></pre>
<p>You can replace it with</p>
<pre><code>jdbc:mysql://${MYSQL_HOST:localhost}:3306/dbname
</code></pre>
<p><code>Deployment.yaml</code> will be something like</p>
<pre><code>spec:
      containers:
      - name: demowebapp
        image: registry.gitlab.com/unicorn/unicornapp:1.0
        ports:
        - containerPort: 8080
        imagePullPolicy: Always
        env:
          - name: MYSQL_HOST
            value: mysql-prod
</code></pre>
<p>You can save more config into the <strong>config map</strong> &amp; <strong>secret</strong> also based on the requirement.</p>
<p>Read more at : <a href="https://pushbuildtestdeploy.com/spring-boot-application.properties-in-kubernetes/" rel="nofollow noreferrer">https://pushbuildtestdeploy.com/spring-boot-application.properties-in-kubernetes/</a></p>
