Cloud Native / Kubernetes / Storage

Tutorial: Deploy PostgreSQL on Kubernetes Running the OpenEBS Storage Engine

20 Mar 2020 8:12am, by

In the last part of this series, I covered the steps to install OpenEBS on the Amazon Elastic Kubernetes Service (Amazon EKS). In this tutorial, we will deploy a highly available instance of PostgreSQL.

Create a Storage Class for PostgreSQL

We will first create a storage class based on the storage pool claim configured in the last tutorial.

The ReplicaCount key will ensure that the data is written across three nodes to add redundancy.

Deploying PostgreSQL through a Helm Chart

We will now deploy PostgreSQL backed by OpenEBS. By pointing the persistence.storageClass to the cStor storage class created in the last step, the deployment will dynamically create a Persistent Volume (PV) and Persistent Volume Claim (PVC)

Let’s verify the Pod, PVC, and PV associated with the deployment.

Creating Test Data

Access the PgSQL client to create a test database, table, and adding a row.

First, let’s retrieve the password from the deployment.

INSERT INTO products VALUES (1, ‘Cheese’, 9.99);

Simulating a Node Failure

Let’s find the node running the PostgreSQL database Pod and cordon it off which will prevent new Pods from being scheduled on it.

Finally, we will delete the Pod running on the cordoned node.

Verifying the Data in the new Pod

As soon as the Pod is deleted, the Kubernetes controller will create a new Pod and schedules it in a different node. It cannot be placed on the same node as the scheduling is disabled after cordoning it.

Even though the PVC has the access mode as ReadWriteOnce which is mounted by a specific node for read-write access, the Pod is able to target the same PVC through the cStor storage pool which abstracted the underlying EBS volumes into a single storage layer.

Now, let’s connect to the new Pod and check if the data is intact.

The data is intact even after deleting the Pod and rescheduling it on a different node. This confirms that the replication factor of OpenEBS is working properly.

In the next part of this series, we will see how to take volume snapshots and backup the state of the workload. Stay tuned!

Janakiram MSV’s Webinar series, “Machine Intelligence and Modern Infrastructure (MI2)” offers informative and insightful sessions covering cutting-edge technologies. Sign up for the upcoming MI2 webinar at

Feature image via Pixabay.

A newsletter digest of the week’s most important stories & analyses.