<p>I want to set environment variables via Kubernetes for server.xml in tomcat. Here is my deployment.yaml:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
 name: tomcat-test-pod
...
...
env:
  - name: hostName
    value: 'test.com'
  - name: localhost
    value: 'localhost.com'
</code></pre>
<p>And here is my server.xml:</p>
<pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
&lt;Resource 
      auth=&quot;Container&quot; 
      description=&quot;Global E-Mail Resource&quot; 
      mail.debug=&quot;false&quot; 
      mail.smtp.auth=&quot;false&quot; 
      mail.smtp.ehlo=&quot;true&quot; 
      mail.smtp.host=&quot;${hostName}&quot;
      mail.smtp.localhost=&quot;${localhost}&quot;  
      mail.smtp.port=&quot;25&quot; 
      mail.smtp.sendpartial=&quot;true&quot; 
      mail.transport.protocol=&quot;smtp&quot; 
      name=&quot;mail/Session&quot; 
      type=&quot;javax.mail.Session&quot;/&gt;
</code></pre>
<p>From <a href="https://tomcat.apache.org/tomcat-9.0-doc/config/systemprops.html" rel="noreferrer">https://tomcat.apache.org/tomcat-9.0-doc/config/systemprops.html</a>, it says that I need to set <code>org.apache.tomcat.util.digester. PROPERTY_SOURCE</code> to <code>org.apache.tomcat.util.digester.EnvironmentPropertySource</code>, but I am not sure what I am supposed to do. Do I need to set it in setenv.sh or do I need to create another class? Any help will be appreciated..</p>

<p><code>org.apache.tomcat.util.digester.PROPERTY_SOURCE</code> is a Java system property so you can set it where system properties are accepted:</p>
<ul>
<li>you can add it to the command line options, e.g. by adding to <code>setenv.sh</code>:</li>
</ul>
<pre class="lang-sh prettyprint-override"><code>CATALINA_OPTS=&quot;$CATALINA_OPTS -Dorg.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource
</code></pre>
<p>This will work only if you call <code>catalina.sh/startup.sh</code> to start Tomcat (directly or indirecly). For example it will not work on Windows, when starting Tomcat as a service.</p>
<ul>
<li>add the system property to <code>catalina.properties</code>:</li>
</ul>
<pre><code>org.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource
</code></pre>
<p>This always works.</p>
