By Xiao Gao, Technical Product Marketing Manager at VMware, and Jonathan Katz, Director of Customer Success & Communications at Crunchy Data

Kubernetes is a popular platform to deploy modern applications, and while Kubernetes-based orchestration platforms have enabled seamless management for stateless applications, managing databases requires more intimate knowledge of how data is persisted beyond the lifecycle of a container.

As a result, operations teams have looked at different ways to securely manage their enterprise databases at scale. However, infrastructure snowflakes, manual steps in database setup, patching and upgrades introduce road blocks that most agile development teams find difficult to overcome.

Kubernetes 1.7 introduced an important feature called custom controllers. With a custom controller, you can write application-specific operators to configure and manage instances of complex stateful applications on behalf of a Kubernetes user–a change that makes it possible to use an operator to deploy a PostgreSQL cluster.

This blog showcases how you can deploy an enterprise-grade PostgreSQL cluster on-demand using the Crunchy PostgreSQL Operator with VMware Enterprise PKS.
 

Operator Pattern

The operator pattern was developed to meet the needs of running stateful applications in a Kubernetes environment by providing an API for a team to capture the knowledge and methods of a Site Reliability Engineer (SRE) for a stateful environment.

With the operator pattern, developers can codify the various tasks that a SRE must perform on stateful applications so they can be applied en masse in a standard, consistent way. With the right combination of features, such as stateful service creation, scaling, and deleting, an operator can help you run your own platform-as-a-service (PaaS), which lets you take full advantage of the benefits of open-source software.
 

Crunchy PostgreSQL Operator

Crunchy Data developed the Crunchy PostgreSQL Operator to implement essential database management tools for PostgreSQL. These tools enable you to do the following things across thousands of PostgreSQL clusters:

  • Provision and delete database clusters on-demand
  • Elastically scale replicas
  • Provide high-availability and automated failover
  • Perform backups, restores, and upgrades
  • Deliver user authorization, access control, policy management, and multi-tenancy

The Crunchy PostgreSQL Operator comes as part of the open-source Crunchy PostgreSQL for Kubernetes, which includes essential microservices for running a PostgreSQL cluster in production.
 

VMware Enterprise PKS

VMware Enterprise PKS is a turnkey solution that enables enterprises and service providers to offer Kubernetes as a service to their organization. It builds on native upstream Kubernetes, BOSH, VMware NSX-T, and Harbor to provide a production-grade, CNCF-certified Kubernetes distribution with advanced networking and security. VMware Enterprise PKS operates on VMware vSphere and public clouds.
 
Enterprise PKS Marketecture
 
For enterprise developers, VMware Enterprise PKS exposes Kubernetes in its native form without adding any layers of abstraction or proprietary extensions so you use the native Kubernetes CLI and API.
 

Setting Up the Crunchy Operator on VMware Enterprise PKS

After you deploy VMware Enterprise PKS, you can create a CNCF-certified Kubernetes cluster with a single command:
 
pks create-cluster mycluster --external-hostname mycluster.corp.local --plan [small |medium| large]

You can store your Crunchy PostgreSQL container image in Harbor registry, sign the image as trusted, scan it for vulnerabilities, and set policies defining its use. Crunchy Operator installation can be triggered by using Bash through makefile targets or automated by using Ansible. With either method, the installation process creates the required Kubernetes resources, such as the Crunchy Operator role bindings, RBAC policies, and end-to-end network security for your PostgreSQL statefulsets using the standard Kubernetes API.

Once deployed to VMware Enterprise PKS, the Crunchy PostgreSQL Operator lets you manage the full lifecycle of all your PostgreSQL clusters in an architecture that looks like this:
 
Enterprise PKS
 
The Crunchy PostgreSQL Operator also comes with a command-line interface (CLI) to manage PostgreSQL clusters. For instance, to create a high-availability PostgreSQL cluster with two replicas, you can run the following command:
 
pgo create cluster pksdemo --autofail --replica-count 2

You can further scale, back up, and delete the cluster using the same pgo command-line interface. You can also scale a cluster horizontally by adding worker nodes and vertically by changing the size of the node virtual machines through the PKS CLI.
 
pks resize mycluster --num-nodes NUMBER-OF-WORKER-NODES

The following diagram is the application view of the deployment:
 
Deployment diagram
 
Crunchy Data integrates with Prometheus for application metric monitoring in a standard deployment. For PKS customers that leverage Wavefront by VMware for application metrics, forwarding of Prometheus metrics to Wavefront by VMware is a fully supported configuration. Wavefront by VMware helps correlate data across all Kubernetes layers. Using Wavefront by VMware as the central aggregation for all your Kubernetes Infrastructure and application data, you can enable advanced use cases, such as detecting noisy neighbors or horizontal auto-scaling based on application transaction load.

Crunchy Data has released an implementation of the Open Service Broker API called pgo-osb, which works with the Crunchy PostgreSQL Operator. By using pgo-osb, you can provision and deprovision PostgreSQL database clusters as well as bind PostgreSQL user credentials to service instances:
 

 
You can deploy pgo-osb by following these instructions and then provision an instance by using the following command:

You can then bind your cluster for use with your applications with the following command:
bsvcat bind osbdemo --name osbdemo-bindingsvcat bind osbdemo --name osbdemo-binding
 

Wrapping Up

The Crunchy PostgreSQL Operator not only lets you run stateful workloads on VMware Enterprise PKS but also provides a self-hosted Kubernetes as a service that unlocks the flexibility of open-source software. You can manage both Kubernetes cluster as well as your application using out of box tools bundled with the solution. For more information, see the following resources: