Red Hat OpenShift is a popular enterprise Kubernetes application platform. Openshift has been traditionally considered a platform for stateless applications. However, many developers are exploring the possibility of running stateful workloads, such as PostgreSQL, on OpenShift. If you are considering extending OpenShift for stateful workloads, this tutorial will help you experiment on your existing OpenShift environment by providing step-by-step instructions.
Deploy PostgreSQL on OpenShift Using Helm
In this tutorial, we will deploy a PostgreSQL database on OpenShift using Helm with a single command, load data in the database, and register the PostgreSQL Helm release as an application with ROBIN Storage.
Before you begin this tutorial, install ROBIN Storage on your existing OpenShift cluster.
After you have installed ROBIN, let us install the PostgreSQL client as the first step, so that we can use the PostgreSQL database once deployed.
Let us now confirm that OpenShift cluster is up and running.
You should see an output similar to below, with the list of nodes and their status as “Ready”.
Let us confirm that ROBIN is up and running. Run the following command to verify that ROBIN Storage is ready.
Let us now setup helm. ROBIN has helper utilities to initialize helm.
Let us now create a PostgreSQL database using Helm and ROBIN Storage. The following command will install PostgreSQL. We are setting the storageClass to robin-0-3 to benefit from the data management capabilities that ROBIN Storage brings.
Run the following command to verify our database called “movies” is deployed and all relevant Kubernetes resources are ready.
You should be able to see an output showing the status of your PostgreSQL database.
You would also want to make sure PostgreSQL database services are running before proceeding further. Run the following command to verify the services are running.
Now that we know the PostgreSQL services are up and running, let us get the Service IP address of our database.
Let us now get the Password of our PostgreSQL database from Kubernetes Secret.
Adding data to the PostgreSQL database
We’ll use movie data to load data into our PostgreSQL database. Let’s create a database “testdb” and connect to this “testdb”.
For the purpose of this tutorial, let us create a table named “movies”.
To perform various operations, we need some sample data. Let us add 9 movies to the “movies” table.
Let us verify the data was added to the “movies” table by running the following command.
You should see an output with the “movies” table and the nine rows in it as follows:
We now have a PostgreSQL database with a table and some sample data. Now, let’s take a look at the data management capabilities ROBIN brings, such as taking snapshots, making clones, and creating backups.
Registering the PostgreSQL Helm release as an application
To benefit from the data management capabilities, we’ll register our PostgreSQL database with ROBIN. Doing so will let ROBIN map and track all resources associated with the Helm release for this PostgreSQL database.
Let us first get the ‘robin’ client utility and set it up to work with this OpenShift cluster.
To get the link to download robin client, run the following command:
You should see an output similar to below:
Find the field ‘Get _ Robin _ Client’ and run the corresponding command to get the ROBIN client.
In the same output above notice the field ‘Master _ Ip’ and use it to set up your ROBIN client to work with your OpenShift cluster, by running the following command.
Now you can register the Helm release as an application with ROBIN. Doing so will let ROBIN map and track all resources associated with the Helm release for this PostgreSQL database. To register the Helm release as an application, run the following command:
Let us now verify that ROBIN is tracking our PostgreSQL Helm release as a single entity (app).
You should see an output similar to this:
We have successfully registered our Helm release as an app called “movies”.
This concludes the Deploy PostgreSQL on OpenShift tutorial. Now that we have deployed the PostgreSQL database, loaded data, and registered the PostgreSQL Helm release with ROBIN, we can create a PostgreSQL database snapshot and create a PostgreSQL clone including app plus data.