Databases

Last modified by Tomas Terälä on 2025/03/21 13:33

Running a local instance of a database in OpenShift is possible, but not recommended because this leaves backups to be configured by the project team.

Using a Database From the University’s Shared Database Service

Instructions for ordering a database can be found here . Remember to mention OpenShift, since some of the databases refure connections from outside the OpenShift clusters. (In order to fix this problem we will try to find an easier way to view your database)

Remember to leave database addresses and passwords as environmental variables, so they will not show in version control. The database url is the same as the one in the email.

Consider using Secrets or ConfigMaps for the values above, Instructions here.

Below an example of how a project using Node.js defined their environmental variables. The variables were given in OpenShift as ENV values with similar names.

require('dotenv').config()

const DATABASE_URL = process.env.DATABASE_URL
const DATABASE_USERNAME = process.env.DATABASE_USERNAME
const DATABASE_PASSWORD = process.env.DATABASE_PASSWORD
const PORT = process.env.PORT
const DATABASE_HOST = process.env.DATABASE_HOST
const SECRET = process.env.SECRET

module.exports = {
  DATABASE_URL,
  DATABASE_PASSWORD,
  DATABASE_USERNAME,
  PORT,
  DATABASE_HOST,
  SECRET,
}

Using a Database Hosted in OpenShift

You can either connect to an external database or deploy a database into the OpenShift.

The Red Hat OpenShift Container Platform supports the deployment of a number of databases, such as MySQL, PostgreSQL, and MongoDB, using the OpenShift web console Developer view, or the OpenShift command line client (oc).

After deploying a database, you can deploy other applications to OpenShift to access, store, and manage data in the database. Store the database credentials in an OpenShift secret, and then connect to the database from applications using environment variables. OpenShift injects the secret data, as environment variables, into application pods at run time.

Examples

OpenShift DB-service database connection string for Node.js based applications is:

postgresql://myapp:mypass@mydbservice:5432/mydb

External database running on a host server

postgresql://myapp:mypass@mydbhost.example.com:5432/mydb

For more information, refer to the Creating an application with a database section in the OpenShift Container Platform 4.15 CLI Tools guide

OpenShift and Databases

OpenShift Port Forwarding