Creating a database instance inside Red Hat OpenShift is as simple as one command. Building the database, tables, and initializing any tables with data is a different story. There are multiple ways to perform these important tasks, including logging into a terminal session inside a pod to running commands in a script on your local machine.
Kubernetes, the basis for OpenShift, includes init container objects, which can be used to run important steps before starting an application. These steps include creating a database, creating a table, and populating the table.
You will need the following in order to complete this activity:
- A Developer Sandbox for Red Hat OpenShift (Developer Sandbox) account.
occommand line interface installed on your computer.
- A web browser to access your sandbox dashboard.
What you’ll be doing
This learning path covers how to prepare the database on your local machine and then instance objects in your OpenShift cluster. The result will be a PostgreSQL database instance, a database (foods), a table (food), data inside the table, and a Quarkus web service to retrieve the data (Figure 1).
Here are the steps:
- Get the code from GitHub.
- Create the PostgreSQL instance.
- Make the files available.
- Deploy the application.
- View the results.
How long will this activity take?
- You should budget 45-60 minutes to complete this learning path.
What you will learn
- When you have finished this activity, you will be able to use init containers to build and populate databases.
- You don’t need to know any programming languages to complete this task. If you’re interested in viewing the code, the getfood microservice is a Quarkus application written in Java.
If you need help
- If you get stuck, if something isn’t working, or you simply have questions, you can easily contact us via email at email@example.com.