0

Good morning, I have the following distribution in the moment

  • I have several non azure databases
  • A container record in azure linked with the kubernetes with images of my REST API application inside

in my application I have a server.xml that

 <Realm className = "org.apache.catalina.realm.LockOutRealm">
    <Realm className = "org.apache.catalina.realm.JDBCRealm" connectionURL = "jdbc: sqlserver: //xxxx.database.windows.net:1433; database = demo1; user = xxx @ xxx; password =` `; encrypt = true; trustServerCertificate = true; hostNameInCertificate = *. database.windows.net; loginTimeout = 30; " driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver" roleNameCol = "role" userCredCol = "password" userNameCol = "login" userRoleTable = "userRole" userTable = "v_login" />
        </ Realm>

which references my database and through this makes the connection .... its that okay.

However I was using for each bank an image changing these parameters, but now I want to have only one image and change the parameter externally

I searched a lot and did not find a way to change these parameters externally (in deploy.yaml or service.yaml)

I need your help

Bruno Luis
  • 25
  • 10

2 Answers2

0

You can pass command line arguments in your deployment yaml: .spec.template.spec.containers[0].args. This is an array of strings, every string is a command line argument to your executable.

Example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
  namespace: default
  labels:
    app: my-app
spec:
  selector:
    matchLabels:
      app: my-app
  replicas: 2
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - image: my-image
        name: my-app
        args: [
          "argument-1",
          "argument-2"
        ]
Markus Dresch
  • 5,290
  • 3
  • 20
  • 40
  • But this args needs to be inside the **server.xml**, how do I access this file? or will my problem be solved just by passing the connect string directly to the argument? – Bruno Luis Dec 05 '18 at 10:08
  • ok, so you actually want to swap out the server.xml - this answer should help: https://stackoverflow.com/questions/45751832/send-tomcat-conf-files-to-container-using-kubernetes – Markus Dresch Dec 05 '18 at 10:25
  • but so I have to change my entire **dockerfile**? Because I have an application in which I did a multi build stage with **maven + tomcat + rest api** ... I did not understand what my structure would look like – Bruno Luis Dec 05 '18 at 11:02
0

Dont bake the jdbc url inside your docker image. Externalize those using environment variables. Tomcat supports java system property interpolation inside server.xml. you need to use catalina_opts to set the java system property from environment variables.

check this post evironment/system variables in server.xml.

Another thing, use configmap and/or secrets to set the env variables into the deployment https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-container-environment-variables-using-configmap-data

Bal Chua
  • 1,134
  • 9
  • 10