PostgreSQL Database Operators

There are a number of PostgreSQL database Kubernetes operators available—including Crunchy PostgreSQL for KubernetesZalando PostgreSQL Operator, and Percona Distribution for PostgreSQL on Kubernetes to name just a few—however, for this blog post, I will be taking the popular EnterpriseDB (EDB) PostgreSQL Operator out for a spin.

If you want to try looking at using other database operators, visit OperatorHub.io, which provides a registry of Kubernetes operators.

Before we start, let’s take a quick look at my Kubernetes environment:

Kubectl

Install Cloud Native PostgreSQL

To begin, let’s install the latest Cloud Native PostgreSQL operator:

Kubectl-1

Next, let’s confirm the Operator installation:

Kubectl-2

Create Portworx Storage Class

Use a text editor to create a file, in the example below I have set the replication factor to 2, io profile for database workloads, and asked Portworx to support volume expansions.

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: px-postgresql-sc
provisioner: kubernetes.io/portworx-volume
parameters:
  repl: "2"
  io_profile: "db_remote"
allowVolumeExpansion: true

Next, create a Kubernetes storage class; you can use kubectl apply, for example.

Kubectl-3

Deploy PostgreSQL Cluster

Create a file named “px-postgresql-cluster.yaml”:

Kubectl-4

Next, use kubectl to create a 3-node PostgreSQL cluster:

kubectl apply -f px-postgresql-cluster.yaml

Then, check the PostgreSQL pod status:

Kubectl-5

Next, check the Portworx PersistentVolumeClaims:

Kubectl-6

Finally, check the PostgreSQL cluster status:

Kubectl-10

If you want additional details, you can obtain them with kubectl get cluster -o json.

Next, we want to get the cluster name:

Kubectl-7

Then, we want to get the cluster description:

Kubectl-8

The next step is to get the cluster current primary:

Kubectl-9

And finally, we want to get the cluster status:

Kubectl-11

Cloud Native PostgreSQL Plugin

EnterpriseDB provides a plugin for kubectl to manage a PostgreSQL cluster in Kubernetes. We can install this with:

Kubectl-12

The cnp extension provides some additional features to kubectl:

Kubectl-13

Checking the Cloud Native PostgreSQL Status

CNP shows we are running two replicas; if the primary fails for any reason, the cluster will failover to one of them.

Kubectl-14

Summary

In this post, I have shared how we can deploy a PostgreSQL database on Kubernetes using the EDB PostgreSQL operator and provide additional resilience using Portworx persistent storage.

Share
Subscribe for Updates

About Us
Portworx is the leader in cloud native storage for containers.

ron_ekins_

Ron Ekins

Principal Field Solutions Architect
Explore Related Content:
  • databases
  • kubernetes
  • portworx
  • postgresql
link
Twitter
April 7, 2020 Product Announcements
Announcing Portworx Essentials: The #1 Kubernetes storage platform for any app
Michael Ferranti
Michael Ferranti
link
DeployingOnKubernetes
January 7, 2020 Lightboard
Lightboard Session: Deploying Portworx On Kubernetes
Ryan Wallner
Ryan Wallner
link
kubernetes
May 29, 2018 How To
PostgreSQL Kubernetes: How to run HA Postgres on Kubernetes
Janakiram MSV
Janakiram MSV