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.
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”.
PGPASSWORD=”$POSTGRES_PASSWORD” psql -h $IP_ADDRESS -U postgres -d testdb -c “CREATE TABLE movies (movieid TEXT, year INT, title TEXT, genre TEXT);”
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.