<p>I am using kubernetes for a web application deployement.</p>

<pre><code>  containers:
  - name: myapp
    image: tomcat8-jre8:latest
    imagePullPolicy: Always
    env:     
    - name: DATABASE_HOST
      valueFrom:
        secretKeyRef:
          name: my-secret
          key: external.database.host
    - name: DATABASE_USER
      valueFrom:
        secretKeyRef:
          name: my-secret
          key: external.database.user
    - name: DATABASE_PASSWORD
      valueFrom:
        secretKeyRef:
          name: my-secret
          key: external.database.password
</code></pre>

<p>I also use tomcat JNDI with a custom server.xml and catalina.properties</p>

<pre><code> &lt;Resource factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
            name="jdbc/mysource" 
            auth="Container" 
            type="javax.sql.DataSource" 
            driverClassName="org.postgresql.Driver" 
            url="jdbc:postgresql://******" # secret url
            username="${database.user}"      
            password="${database.password}" /&gt;
</code></pre>

<p>I tried puting a new property into catalina.properties</p>

<pre><code>### catalina specific configuration
database.user = ${DATABASE_USER}              
database.password = ${DATABASE_PASSWORD}   
</code></pre>

<p>server.xml can well read the property but could not resolve the environment variable ${DATABASE_USER} and ${DATABASE_PASSWORD}</p>

<p>Both server.xml and catalina.properties are mounted as config maps, the sensitive information are being held in environment variables. we don't know their values</p>

<p>the environment variable are set when I log into the pod and are recognizable from my webapp (java based) but could not read it from catalina.properties (and/or server.xml)</p>

<p>Can anyone give me a tip on this ?  Is it possible to inject environment variables within tomcat configuration ?</p>

<p>Thanks</p>

Geek Junior
<p>I had the same problem and the answer from <a href="https://stackoverflow.com/a/64037650/3808721">@jamesfry</a> helped me to have it fixed. Though it was hard for me to find how to set &quot;system property&quot; for the container in Kubernetes. So sharing fix with exact code change required in your 'Deployment' based on James's answer:</p>
<pre><code>containers:
  - name: myapp
    image: tomcat8-jre8:latest
    imagePullPolicy: Always
    env:     
    - name: JAVA_OPTS
      value: -Dorg.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource
    - name: DATABASE_HOST
      valueFrom:
        secretKeyRef:
          name: my-secret
          key: external.database.host
    - name: DATABASE_USER
      valueFrom:
        secretKeyRef:
          name: my-secret
          key: external.database.user
    - name: DATABASE_PASSWORD
      valueFrom:
        secretKeyRef:
          name: my-secret
          key: external.database.password
</code></pre>
<p>Note that your JNDI could directly use your env variables in the deployment file, as below:</p>
<pre><code>&lt;Resource factory=&quot;org.apache.tomcat.jdbc.pool.DataSourceFactory&quot;
            name=&quot;jdbc/mysource&quot; 
            auth=&quot;Container&quot; 
            type=&quot;javax.sql.DataSource&quot; 
            driverClassName=&quot;org.postgresql.Driver&quot; 
            url=&quot;jdbc:postgresql://${DATABASE_HOST}&quot; # secret url
            username=&quot;${DATABASE_USER}&quot;      
            password=&quot;${DATABASE_PASSWORD}&quot; /&gt;
</code></pre>
<p>And you don't need to touch catalina.properties.</p>
