Getting Started with PGO, Postgres Operator 5.0

Jonathan S. Katz

4 min read

We recently announced the release of version 5.0 of PGO, the open source Postgres Operator from Crunchy Data. In this previous post, I discussed the design decisions and architecture around building the next generation of Kubernetes Native Postgres Operator. Now let's further dive into the feature set and demonstrate how easy it is to get started.

With many years of active development, PGO put forward a strong feature set for managing open source Postgres databases on Kubernetes as conveniently as possible. Our goal was to combine the core features needed to run Postgres in production and our lessons running Postgres on Kubernetes to create a Kubernetes Operator built for the declarative workflow.

An important design goal for PGO 5.0 was to make it as easy as possible to run production-ready Postgres with the features that one expects. Let's see what it takes to run cloud native Postgres that is ready for production.

Cloud Native Postgres Ready for Production

There are a certain set of features that are essential to running any database, let alone Postgres in production. We had implemented all of these features in previous versions of the Postgres Operator and moved them into a fully declarative workflow for PGO 5.0:

  • High Availability: Ensure data was always accessible without a single-point-of-failure (SPOF).
  • Disaster Recovery: Providing a mature backup/restore system for data of all sizes, and the ability to store backups on Kubernetes, AWS S3, Google Cloud Storage (GCS), and Azure Blob Storage.
  • Monitoring: Deliver Postgres health insights tailored for running in Kubernetes.
  • Customizability: Making it easy to tune Postgres knobs in a Kubernetes-friendly way.
  • Security: Following both Kubernetes and Postgres best practices for safely running databases

The best way to see the next generation Postgres on Kubernetes is to try it out for yourself.

Start Running Postgres on Kubernetes

A great way to get started running Postgres on Kubernetes is through example. We create a repository of "Postgres Operator examples" that cover a lot of common Postgres use cases. To get started, we recommend forking the PGO example repository, which makes it convenient to plug it into GitOps tools like ArgoCD:

Once you're set up, the first thing you need to do is deploy PGO, the Postgres Operator. Here are a few commands to help you do exactly that:

YOUR_GITHUB_UN="<your GitHub username>"
git clone --depth 1 "${YOUR_GITHUB_UN}/postgres-operator-examples.git"
cd postgres-operator-examples
kubectl -k kustomize/install

The "-k" command on "kubectl" lets you run a Kustomization that will install all of the objects needed to run PGO, including creating a namespace called "postgres-operator". You can use the command below to let you know when PGO is up and running, which usually takes only a few seconds:

kubectl -n postgres-operator get pods \ \

Using the examples, you can deploy a Postgres cluster by running:

kubectl apply -k kustomize/postgres

Or, if you want to see how you can deploy an application alongside your Postgres cluster, you can run the example that deploys the Keycloak identity management system backed by a Postgres database created with PGO:

kubectl apply -k kustomize/keycloak

Creating a Postgres cluster with PGO also creates a Kubernetes Secret that contains all of the information you need to connect an application to a database, including the host information user credentials. The great thing about this is that you don't need to be aware of any of the contents of the Secret: you mount it to your application and that's all! Using the Keycloak example, this looks something like:

- name: DB_ADDR
  valueFrom: { secretKeyRef: { name: keycloakdb-pguser, key: host } }
- name: DB_PORT
  valueFrom: { secretKeyRef: { name: keycloakdb-pguser, key: port } }
  valueFrom: { secretKeyRef: { name: keycloakdb-pguser, key: dbname } }
- name: DB_USER
  valueFrom: { secretKeyRef: { name: keycloakdb-pguser, key: user } }
  valueFrom: { secretKeyRef: { name: keycloakdb-pguser, key: password } }

And there you go, you can securely connect your application to a Postgres database managed by PGO!

Next Steps

There is a lot more to cover than what I can do in this blog post. Topics like high availability, resource sizing, backup management, monitoring, applying software updates, connection pooling, and much more.

I encourage you to explore the Postgres Operator tutorial, start building applications out with it, and provide feedback on your experience.

Avatar for Jonathan S. Katz

Written by

Jonathan S. Katz

July 8, 2021 More by this author