0

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;"
Bruno Luis
  • 15
  • 8

2 Answers2

1

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.

4c74356b41
  • 59,484
  • 5
  • 63
  • 109
  • Yeah something like https://stackoverflow.com/questions/11926181/evironment-system-variables-in-server-xml – Ryan Dawson Dec 06 '18 at 11:37
  • Sadly the tomcat helm chart doesn't seem to provide a way to do it OOTB currently https://github.com/helm/charts/tree/master/stable/tomcat – Ryan Dawson Dec 06 '18 at 11:43
  • not really a java user here, so dont know much about that :) I'll just agree with you on this one :) – 4c74356b41 Dec 06 '18 at 11:43
  • I see that [https://stackoverflow.com/questions/11926181/evironment-system-variables-in-server-xml] but i don`t understand how kubernetes get inside this, or i make a **setenv.sh** and copy this to /bin/ inside my container and after that i set **env** in kubernetes? – Bruno Luis Dec 06 '18 at 11:49
  • yes, you need to inject that setenv.sh to the pod at build time or at runtime (volumes, for example) – 4c74356b41 Dec 06 '18 at 11:54
  • thanks, I'm seeing how it would be portable for an application that has more than 10 db`s – Bruno Luis Dec 06 '18 at 12:23
1

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

Bal Chua
  • 988
  • 7
  • 8