Skip to content

Latest commit

 

History

History
97 lines (72 loc) · 3.93 KB

File metadata and controls

97 lines (72 loc) · 3.93 KB

OpenShift Configuration Lab

Application Configuration Structure

Browse Catalog

Create a Mongo DB

  1. Click on the project we just created from the My Projects list on the right panel then click on Add to Project on the top-right corner and then select Browse Catalog

  2. Click on Databases tab and select Mongo and then click on MongoDB

  3. Take all default settings, click on Next and then Create.

  4. After creation, click on Show parameter values under Applied Parameter Values

  5. Examine the parameters under Applied Parameter Values, we will bind the database connection information to a node application later.

Create a Node application (skip this step if we have created the application)

  1. Go back to Commandline console, set current project as cascon-oc-config

     oc project cascon-oc-config
  2. Create a new node application under the project from the example github repository

     oc new-app https://github.com/jwsliu/nodejs-ex
  3. Expose the node application

     oc expose svc nodejs-ex

Binding environment variables from OpenShift secrets

The node application takes environment variables to confugure the database connection, we want to set these environment variables from OpenShift secrets.

  1. Let's take a look at the application before we set environment variables. Go to minshift web console, expand the application and click on the url under Route

  2. After the application is open in a new tab, you can see the database is not configued

  3. Add a path "/env" to the application url, the application prints out all environment variables it can access.

  4. Now, let's create some new environment vaiables and bind them to Mongo DB secrets. Go back to minishift web console, click on the application under Deployment Config

  5. Select on Environment tab and add a environment variable for database service name, DATABASE_SERVICE_NAME = mongodb

  6. Click on Add Value from Config Map or Secret

  7. Enter "MONGODB_USER" as Name, select "mongodb" secret and select the key as "database-user"

  8. Repeat the last two steps to set these env variables

    Name                      secret       Key
    MONGODB_DATABASE          mongodb      database-name
    MONGODB_PASSWORD          mongodb      database-password
    MONGODB_ADMIN_PASSWORD    mongodb      database-admin-password

    then click save, you should have these env variables set like this:

  9. Wait the application redeployment is completed, open the application url again, you should see the database info and page count.

  10. Go to the env page again, you should see the new variables are listed in the page.

  11. You can examine the secrets by oc commands

      oc login -u system:admin  # login as admin
      oc project cascon-oc-config # swtich to the project
      oc get secrets # list all secretes under the current project
      oc get secret mongodb -o yaml # get mongodb secret contents in yaml

    You should see the mongodb secret contents in yaml like this

  12. You can also look at the project deployment configuration to see the bindings between the openshift secrets and environmental variables:

       oc get dc <application_name> -o yaml

References:

  1. The lab is inspired by the course "Application Deployment with Red Hat OpenShift Container Platform" provided by https://training-lms.redhat.com
  2. Part of Lab example code are from https://github.com/sclorg/nodejs-ex and https://github.com/redhat-gpte-devopsautomation/PrintEnv