PostgreSQL Operator for Kubernetes
PostgreSQL Operator for Kubernetes
com/blog/streaming-replication-across-kubernetes-postgres-clusters
https://www.crunchydata.com/blog/postgres-operator-for-kubernetes
Operators
Last November the team at CoreOS introduced the concept of an “application-specific
controller” for Kubernetes called software Operators. In their announcement, CoreOS suggested
Operators as a means to more efficiently manage database infrastructure.
Crunchy Data has previously released a suite of containers for deploying, administering and
monitoring PostgreSQL and leveraging the Operator concept to further advance the deployment
and management of PostgreSQL functions within Kubernetes was a natural extension of our
work to date.
Initial Scope
For the initial release of a PostgreSQL operator our team has focused on a few basic operations
that a user would interact with on a daily basis including:
Design Features
The Operator concept makes use of Third Party Resources (TPR) to create a set of domain
specific objects that pertain to a specific application. This Operator creates PostgreSQL specific
objects, including: pgdatabase, pgcluster, and pgbackup. A few additional notes on the design:
The PostgreSQL Operator runs in a Deployment on the Kubernetes cluster and watches for TPR events
The user interface of the PostgreSQL Operator is a command line utility called pgo
The PostgreSQL Operator allows for a variety of Persistent Volume technologies to be used such as
HostPath, NFS, and block storage.
The PostgreSQL Operator allows for different deployment strategies to be defined. A Deployment
Strategy in the case is the set of objects that the Operator will create for a new database or PostgreSQL
cluster including Pods, Services, Deployments, etc. This is a key feature in that different customers will
want to customize exactly how their PostgreSQL databases are deployed.
The following diagram shows the pgo client communicating to the Postgres Operator running
within the Kubernetes Cluster and causing the Operator to create or act upon PostgreSQL
containers.
Source Code
The PostgreSQL Operator is primarily written in golang and available on GitHub. Instructions
on building the code is found under the heading Build-Setup Documentation.
A binary release is provided along with the requisite Docker images on Docker Hub.
Getting Started
In order to get started, a user can build a single master PostgreSQL database using
the pgo command line utility as follows:
This command creates a database TPR upon which the Operator will act. This command will
cause the PostgreSQL Operator to use the default database deployment strategy and create a Pod
running the PostgreSQL database along with a Service mapped to the database pod.
A user can then view the database using the following command:
database : mydatabase**
Once the database is created, a user can perform a database backup using the following
command:
└── backup-mydatabase-63fw1
└── mydatabase
├── mydatabase-backups/2017-03-27-13-54-33
├── mydatabase-backups/2017-03-27-13-56-49
└── mydatabase-backups/2017-03-27-14-02-38
Once the backup has been created, it is possible to create a database off of that backup using the
following command:
--backup-path=mydatabase/2017-03-27-14-02-38 --backup-pvc=mydatabase-pvc
This command creates a master database deployment, replica database deployment, a service for
the master, and a service for the replicas.
cluster : mycluster
├── deployment : mycluster
Finally, it is possible to delete of all of the databases created using the following command:
Conclusion
The Third Party Resource API and golang client projects are both emerging frameworks that let
allow application providers like Crunchy Data to build a rich native orchestration layer for
Kubernetes In our case, our orchestration is focused on the PostgreSQL database but the pattern
and frameworks could certainly be applied to other applications.
In particular, the Operator concept provides an exciting new platform Crunchy Data looks
forward to build on and further advances our objective of saving users time in deploying and
managing container based PostgreSQL databases infrastructure. This blog provides an discussion
of an initial set of PostgreSQL Operator functions. Crunchy Data plans to continue our
development to offer more extensive and advanced PostgreSQL automation in future versions of
the PostgreSQL Operator, so please stay tuned!