Deploy Database For Villain Microservice
Deploy PostgreSQL database from external container registry
Right click in view area then select Container image menu.
PostgreSQL database deployment 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
PostgreSQL database deployment Scroll down to to bottom of the page, then Uncheck "Create a route" checkbox. And then click on Deployment link.
PostgreSQL database deployment Click Add value link to add more input fields of environment variables
PostgreSQL database deployment Enter following environment variables. Then click on Labels link.
POSTGRESQL_USER:
superbad
POSTGRESQL_PASSWORD:
superbad
POSTGRESQL_DATABASE:
villains_database
PostgreSQL database deployment Enter
system=quarkus-super-heroes
then click Create button.PostgreSQL database deployment A new
villains-db
PostgreSQL instance should be created. Wait for awhile unti it's up and running.PostgreSQL database deployment
Initial data to database
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.
Web Terminal 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
Use
psql
(PostgreSQL client) to connect to thevillains-db
PostgreSQL server. The password issuperbad
.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=>
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=>
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)
Query number of rows in the table.
select count(*) from villain;
Sample output:
villains_database=> select count(*) from villain; count ------- 100 (1 row)
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
Last updated