Multiple databases with one rest api

12/4/2018

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
azure
java
jdbc
kubectl
kubernetes

2 Answers

12/4/2018

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
Source: StackOverflow

12/7/2018

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
Source: StackOverflow