Config Maps to Connect Strings

12/11/2018

I have a rest api where I have the databases in azure and the application with docker + kubernetes, so alright.

I have more than 10 clients and each client owns a database, I did not want to have a docker image for each client, just have a base image where for each client would have a connect string, the proposed solution was to make a setenv.sh to make the connections

setenv.sh

#!/bin/bash

dbuser="xxx@iafox"
dbpassword="mypassword"
dbconnectstring="jdbc:sqlserver://xxx.database.windows.net:1433;database=ts-demo1;user=xxx@iafox;password=mypassword;encrypt=true;trustServerCertificate=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;"
dburl="jdbc:sqlserver://xxx.database.windows.net:1433;database=ts-demo1;"

export CATALINA_OPTS=" ${SYSTEM_PROPS} -Ddbuser='${dbuser}' -Ddbpassword=${dbpassword} -Ddbconnectstring='${dbconnectstring}' -Ddburl='${dburl}'"

server.xml

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

Until then everything is working. But now I do not know the next step, if for every setenv that I create I will have a configmap in kubernetes, or if I will have all the connect strings in the same setenv .... I wanted a help in this

-- Bruno Luis
azure
database-connection
java
kubernetes
tomcat

1 Answer

12/12/2018

You can set multiple environment variables from one configMap as documented here.

But I would recommend storing passwords and connection strings with sensitive information in a secret.

You can reference Kubernetes secrets in a similar way to set the container's environment vars.

-- switchboard.op
Source: StackOverflow