Get Started Running PostgreSQL on Kubernetes
Jonathan S. Katz
3 min readMore by this author
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 -
wgetutility installedkubectlorocutility installedStorageClassdefined 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 pgobash_completionfile
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-macis the binary for Macpgo.exeis the binary for Windowspgois the binary for Linuxexpenvis theexpenvbinary for Linuxexpenv-macis theexpenvbinary for Macexpenv.exeis theexpenvbinary 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!
Related Articles
- PostGIS Performance: pg_stat_statements and Postgres tuning
4 min read
- Is Postgres Read Heavy or Write Heavy? (And Why You Should Care)
10 min read
- PostGIS Performance: Indexing and EXPLAIN
3 min read
- Postgres Migrations Using Logical Replication
7 min read
- Postgres 18: OLD and NEW Rows in the RETURNING Clause
2 min read