Super Heroes on OpenShift Workshop
  • Super Heroes on OpenShift Workshop
    • About Workshop
    • Application Architecture
    • Getting Started
  • Application Services Deployment
    • Databases Deployment
      • Deploy Database For Hero Microservice
      • Deploy Database For Villain Microservice
      • Deploy Database For Fight Microservice
    • AMQ Streams (Kafka) Deployment
    • Service Registry (Apicurio) Deployment
  • Application Deployment
    • Microservices Deployment
      • Hero Microservice
      • Villain Microservice
      • Fight Microservice
      • Super Hero UI Microservice
      • Statistics and UI Microservices
      • Beautify The Topology View
  • Continuous Deployment (CD)
    • GitOps
  • Application Monitoring
    • Application Metrics
      • Configure Service Monitoring
      • Query Application Metrics
    • Distributed Tracing
      • Configure OpenShift Distributed Tracing Platform
      • Configure OpenShift Distributed Tracing Data Collection
      • Trace Application Transaction
  • Appendix
    • What's Quarkus?
    • Useful Resources
Powered by GitBook
On this page
  • Deploy PostgreSQL database from external container registry
  • Initial data to database
  • What have you learnt?
  1. Application Services Deployment
  2. Databases Deployment

Deploy Database For Villain Microservice

PreviousDeploy Database For Hero MicroserviceNextDeploy Database For Fight Microservice

Last updated 2 years ago

Deploy PostgreSQL database from external container registry

  1. Right click in view area then select Container image menu.

  2. Enter following inputs as a screenshot below:

    • Image name from external registry: registry.redhat.io/rhel9/postgresql-13

    • Runtime icon: postgresql

    • Application: Create application

    • Application Name: villains-service

    • Name: villains-db

  3. Scroll down to to bottom of the page, then Uncheck "Create a route" checkbox. And then click on Deployment link.

  4. Click Add value link to add more input fields of environment variables

  5. Enter following environment variables. Then click on Labels link.

    • POSTGRESQL_USER: superbad

    • POSTGRESQL_PASSWORD: superbad

    • POSTGRESQL_DATABASE: villains_database

  6. Enter system=quarkus-super-heroes then click Create button.

  7. A new villains-db PostgreSQL instance should be created. Wait for awhile unti it's up and running.

Initial data to database

  1. Click on the Web Terminal icon located on top right corner of web console. Wait for a few moment, you should see a terminal shows up.

  2. Use curl command to download SQL script.

    curl https://raw.githubusercontent.com/rhthsa/developer-advocacy-2022/main/manifest/super-heroes/villains-db-init.sql -o villains-db-init.sql

    Sample output:

      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
    100  105k  100  105k    0     0   303k      0 --:--:-- --:--:-- --:--:--  303k
  3. Use psql (PostgreSQL client) to connect to the villains-db PostgreSQL server. The password is superbad.

     psql postgresql://villains-db:5432/villains_database?user=superbad

    Sample output:

    bash-4.4 ~ $ psql postgresql://villains-db:5432/villains_database?user=superbad
    Password:
    psql (10.21, server 13.7)
    WARNING: psql major version 10, server major version 13.
            Some psql features might not work.
    Type "help" for help.
    
    villains_database=>
  4. Execute the SQL script with this command:

     \i villains-db-init.sql

    Sample output:

    heroes_database=> \i villains-db-init.sql
    DROP TABLE
    DROP SEQUENCE
    CREATE SEQUENCE
    CREATE TABLE
    INSERT 0 1
    INSERT 0 1
    ....
    ....
    ....
    villains_database=>
  5. Use \dt command to check if a new table gets created.

    \dt

    Sample output:

    villains_database=> \dt
          List of relations
    Schema |  Name   | Type  |  Owner
    --------+---------+-------+----------
    public | villain | table | superbad
    (1 row)
  6. Query number of rows in the table.

    select count(*) from villain;

    Sample output:

    villains_database=> select count(*) from villain;
    count
    -------
    100
    (1 row)
  7. Use \q command to disconnect from PostgreSQL server.

    \q

What have you learnt?

How to deploy PostgreSQL database service container from external container registry, in this case, Red Hat Registry (can be Docker Hub or other registries as well) with following settings:

  • Application icon and name

  • Environment variables for application container

  • User-defined label

PostgreSQL database deployment
PostgreSQL database deployment
PostgreSQL database deployment
PostgreSQL database deployment
PostgreSQL database deployment
PostgreSQL database deployment
PostgreSQL database deployment
Web Terminal