简体   繁体   中英

set env variables in server.xml inside kubernetes

I need to set up variables inside my server.xml but this at the time of creating my pod, I did this and it did not work

server.xml

<Realm className="org.apache.catalina.realm.JDBCRealm" connectionURL="${db_url}" driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver" roleNameCol="role" userCredCol="password" userNameCol="login" userRoleTable="userRole" userTable="v_login"/>

and my pod.yaml

apiVersion: v1
kind: Pod
metadata:
 name: dbtest
spec:
 containers:
 - name: dbtest-container
   image: xxx.azurecr.io/iafoxteste:latest
   ports:
     - containerPort: 8080
   env: 
     - name: db_url
       value: "jdbc:sqlserver://xxx.database.windows.net:1433;database=xxx;user=xxx@iafox;password=xxxx;encrypt=true;trustServerCertificate=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;"

unless java can do that natively kubernetes wont do that for you. so you need an init script that would read env. variables and replace tokens in your server.xml. or make your app do that somehow.

kubernetes cant do token replacement.

As it was mentioned kubernetes doesn't do it for you. In order to pass that value to tomcat you need to add db_url as java system property ex. -db_url="jdbc:sqlserver://xxx.database.windows.net:1433;database=xxx;user=xxx@iafox;password=xxxx;encrypt=true;....". Then you need to have a starter shell scripts that gets this value from environment variable and pass that to your CATALINA_OPTS. Check this stackoverflow question Java system properties and environment variables

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM