HA AidboxDB
HA AidboxDB installation with Crunchy Operator
High availability for PostgreSQL is complex because it requires multiple components to work seamlessly, can be time-consuming to set up and configure manually, and ongoing maintenance can be challenging.
Using ready solutions like the Crunchy operator for Kubernetes simplifies the process and improves reliability. Crunchy and similar operators provide a tested and production-ready infrastructure that integrates well with PostgreSQL, as well as features like automatic failover, backups, restores, and upgrades, which can be complex to implement manually. Overall, using a ready solution like Crunchy can reduce complexity and free up time and resources to focus on other aspects of your application.
Crunchy Operator
The Crunchy Operator is an open-source Kubernetes operator that automates the management of PostgreSQL clusters. It provides a simple way to deploy, manage, and operate PostgreSQL clusters in a Kubernetes environment, making it easier to run and scale PostgreSQL workloads.
One of the key benefits of using the Crunchy operator is that it allows for high availability and fault tolerance for your PostgreSQL database. When running a PostgreSQL cluster with the Crunchy operator, you can specify the number of replicas to create, which helps ensure that your database is always available in case of a failure.
Here's how high availability works in terms of the Crunchy operator:
The Crunchy operator deploys a primary PostgreSQL instance and one or more replicas.
The primary instance is responsible for accepting read and write requests and replicating changes to the replicas.
If the primary instance fails, one of the replicas is promoted to become the new primary instance.
The Crunchy operator automatically reconfigures the remaining replicas to replicate from the new primary instance.
This ensures that the cluster remains available even if one or more instances fail.
In addition to high availability, the Crunchy operator also provides other features such as backups and restores, scaling, rolling upgrades, and custom configurations using PostgreSQL custom resource definitions (CRDs).
Install Crunchy
We recommend following official Crunchy Quickstart for how to install and get up and running with PGO. Here are some instructions to get Postgres up and running on Kubernetes:
Fork the Postgres Operator examples repository and clone it to your host machine.
Install PGO using
kustomize
Verify PGO installation
Create cluster
For creating a new PostgreSQL cluster using PGO you should create CRD PostgresCluster.
More detailed information about creating a PGO cluster you can found in official documentation.
Create
aidboxdb.yml
file with the following content
Look at image
property. Generally, you can use the default image provided by Crunchy Operator. But we strongly recommend using healthsamurai/aidboxdb:15.2.0-crunchy image as the image that is optimized for Aidbox.
Important notes
image: healthsamurai/aidboxdb:15.2.0-crunchy
- we recommend use our aidboxdb image build that is preconfigured for use in PGOreplicas: 2
- in this configuration, we install 1 master and 1 replicabackup options
- in this sample, we use local PVC for storing backups. For configuring cloud storages like S3 or GCS you can follow this instructionspg_hba: ["host all all 0.0.0.0/0 md5"]
- for this tutorial we allow non SSL connection
Create a namespace and apply
aidboxdb.yml
resource
Verify PostgreSQL cluster
Connect to the cluster
Get connection credentials. Crunchy operator store all connection information in related
Secret
resource. In our case itaidboxdb-pguser-aidbox
. More detailed information you can be found in the connection tutorial.
Now you can set up this parameter for the Aidbox database connection. Look at Install Aidbox in Kubernetes tutorial
Backup a cluster
You can specify a schedule backup and retention policy for cluster
Define backup schedule. In this spec we define incremental backup from Monday to Saturday and take one full backup every Sunday at 1 AM
Define backup retention policy. In this spec we store all backups 30 days, after that period - delete them
Create manual backup
For creating a manual full backup you should annotate postgrescluster
resource
Clone a Postgres Cluster
You can create a single copy of the existing cluster by creating a new one and specify dataSource
parameter. In the next example, we create a stage
cluster that is a copy of aidboxdb
cluster. Related documentation.
Take care of dataSource
parameter. In this section we specify the source that will be used for cloning.
Restore PITR
When you needed to restore a specific time version of the cluster, or you want to periodically restore you can specify restore
option on backup config.
Now you need to trigger the recovery process
Switchover
To change the primary in your HA cluster, you need to update the PostgresCluster spec to include the following fields:
This will prepare your cluster for a switchover. To trigger the switchover, you need to add the postgres-operator.crunchydata.com/trigger-switchover
annotation to your custom resource. It's recommended to use a timestamp as the value for the annotation so you can track when you initiated the change.
PGO CLI
PGO Command Line Interface (CLI) for the Crunchy Operator built as a kubectl
plugin, the pgo
CLI facilitates the creation and management of PostgreSQL clusters created using the Crunchy Postgres Operator. For more information about using the CLI and the various commands available, please see the pgo
CLI documentation.
Monitoring
Configure
Enable monitoring capabilities by configuring monitoring.
Install Prometheus stack
Install all parts manually
prometheus - metrics and alerting open-source monitoring solution
grafana - open-source observability tool
Or install Prebuild prometheus stack for Kubernetes
kube-prometheus - Prebuild prometheus stack for Kubernetes
Scrape config
Configure scrape config for prometheus and PGO Crunchy Operator
Last updated