<p>I have to pass env variables in JAVA SpringBoot Application.</p>
<p>I have created k8s secrets. I am passing them in k8s deployment YAML as env variables USER_NAME and USER_PWD.</p>
<p>But How to read these env variables in the application.properties file.
I have tried ${USER_NAME} but it's not working.</p>
<p>Ex. from application.properties file.</p>
<p><code>spring.datasource.username=${USER_NAME}</code></p>

<p>Your Deployment yml should be like this</p>
<pre><code>kind: Deployment
apiVersion: apps/v1
metadata:
  name: 
spec:
    ...
    spec:
      containers:
        ...
        env:
         - name: spring.datasource.password
           valueFrom:
            secretKeyRef:
             name: your-secret-name
             key: your-secret-key
</code></pre>
<p>Kubernetes will add your spring.datasource.password and its value to your pod environment variable.</p>
<p>To make Spring boot use it you should add the property spring.datasource.password in your application.properties or application.yml.</p>
