Get Started Running PostgreSQL on Kubernetes

Jonathan S. Katz

3 min read

Interested in running PostgreSQL natively on Kubernetes? Let's look at a few quick steps to get up and running with the open source Crunchy PostgreSQL Operator for Kubernetes on your choice of Kubernetes deployment.

The Crunchy PostgreSQL Operator (aka "pgo") provides a quickstart script to automate the deployment of the Crunchy PostgreSQL Operator to a number of popular Kubernetes environments, including Google Kubernetes Engine (GKE), OpenShift Container Platform (OCP) and Pivotal Container Service (PKS). You can download the quickstart script here:

The script will deploy the operator to a GKE Kubernetes cluster or an OpenShift Container Platform cluster. The script assumes you have a StorageClass defined for persistence.

Quickly Starting with a quickstart

The Crunchy PostgreSQL Operator contains a quickstart.sh script will allow users to set up the Postgres Operator quickly on GKE, PKS, and Openshift.

The script requires a few things in order to work -

Executing the script will give you a default PostgreSQL Operator deployment that assumes dynamic storage and a StorageClass named standard, user provided values are also allowed by the script to override these defaults.

The script performs the following:

  • Downloads the Operator configuration files
  • Sets the $HOME/.pgouser file to default settings
  • Deploys the Operator as a Kubernetes Deployment
  • sets your .bashrc to include the Operator environmental variables
  • sets your $HOME/.bash_completion file to be the pgo bash_completion file

If you want to set your Kubernetes context to some particular namespace you can run commands similar to this to set it to a demo namespace if that namespace has already been created on your GKE cluster:

kubectl create -f $COROOT/examples/demo-namespace.json
kubectl config set-context demo \
    --cluster=gke_crunchy-a-test_us-central1-a_usera-quickstart \
    --namespace=demo \
    --user=gke_crunchy-a-test_us-central1-a_usera-quickstart
kubectl config use-context demo

For Mac and Windows users, pre-built pgo binaries are available on the releases page. You can download the pgo CLI binaries from the Releases page to your local machine as part of the quick installation:

  • pgo-mac is the binary for Mac
  • pgo.exe is the binary for Windows
  • pgo is the binary for Linux
  • expenv is the expenv binary for Linux
  • expenv-mac is the expenv binary for Mac
  • expenv.exe is the expenv binary for Windows

Currently the quickstart scripts are meant for Linux installs, you will need to modify this script for Windows or Mac installs until we support and provide Windows and Mac installation scripts.

After running the quickstart script, you should be able to start creating PostgreSQL clusters! Try creating your first cluster:

pgo create cluster mynewcluster

You can test that your cluster is up and running with the following command:

pgo test mynewcluster

For a full command reference, including commands for scaling, high-availability, backups, and more, please visit the documentation.

And that's that! You now have your own PostgreSQL environment running natively on Kubernetes!

Avatar for Jonathan S. Katz

Written by

Jonathan S. Katz

December 10, 2018 More by this author