<p>I'm running a Java application and in order to start the application it needs some Java environment variables. Below is the way how the variables are passed to the pod.</p>
<p>I created the value (Password) for -Dzookeeper.ssl.keyStore.password as a Kubernetes Secret and then passed as <code>&quot;valueFrom: secretKeyRef:&quot;</code> (As below) But when I exec into the pod and execute 'env' command, I cannot see <code>-Dzookeeper.ssl.keyStore.password</code> environment variable.</p>
<pre><code>      containers:
        - name: java_app
          image: some_image_here
          env:
            - name: JAVA_TOOL_OPTIONS
              value: &gt;-
                -Dspring.profiles.active=some_profile_here
                -Dlogging.config=some_stuff_here
                 .....
                 .....
            - name: -Dzookeeper.ssl.keyStore.password
              valueFrom:
                secretKeyRef:
                  name: password
                  key: PASSWORD
</code></pre>
<p>But when I describe the Pod, it shows as below</p>
<pre><code>-Dzookeeper.ssl.keyStore.password: &lt;set to the key 'PASSWORD' in secret 'password'&gt;  Optional: false
</code></pre>
<p>And eventually Pod crashes since <code>-Dzookeeper.ssl.keyStore.password</code> is missing</p>

Container-Man
<p>You need to create an env variable for the Secret itself which can then be referenced in the subsequent env variable <code>JAVA_TOOL_OPTIONS</code></p>
<pre><code>    containers:
    - name: java_app
      image: some_image_here
      env:
        - name: ZOOKEEPER_KEYSTORE_PASS
          valueFrom:
            secretKeyRef:
              name: password
              key: PASSWORD
        - name: JAVA_TOOL_OPTIONS
          value: &gt;-
            -Dspring.profiles.active=some_profile_here
            -Dlogging.config=some_stuff_here
            -Dzookeeper.ssl.keyStore.password=$(ZOOKEEPER_KEYSTORE_PASS)
             .....
             .....
</code></pre>
<blockquote>
<p>Note that order matters in the env list. An environment variable is
not considered &quot;defined&quot; if it is specified further down the list.</p>
</blockquote>
<p>See the <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-interdependent-environment-variables/" rel="nofollow noreferrer">docs</a> for more details</p>
