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.
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 -
StorageClassdefined on your Kubernetes instance
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/.pgouserfile to default settings
- Deploys the Operator as a Kubernetes Deployment
- sets your
.bashrcto include the Operator environmental variables
- sets your
$HOME/.bash_completionfile to be the pgo
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 \
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-macis the binary for Mac
pgo.exeis the binary for Windows
pgois the binary for Linux
expenvbinary for Linux
expenvbinary for Mac
expenvbinary 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!
Jonathan S. Katz
December 10, 2018 •More by this author