Deploying the PostgreSQL Operator on GKE
The Crunchy PostgreSQL Operator 4.0 provides an open source PostgreSQL-as-a-Service for Kubernetes platform.
This post provides some easy steps to help you get started, specifically deploying the Crunchy PostgreSQL Operator in Google Kubernetes Engine (GKE) making use of the Crunchy PostgreSQL Operator Ansible Installer.
PostgreSQL Operator Ansible Installer
The Crunchy PostgreSQL Operator 4.0 provides Ansible playbooks to automate the installation. These Ansible playbooks allow users to deploy the operator to a variety of Kubernetes platforms and automate a number of installation steps, including:
- Generate TLS certificates required by the PostgreSQL Operator
- Configure PostgreSQL Operator settings from a single inventory file
Preparation of GKE Environment
Given that this example leverages GKE, perhaps it goes without saying that you must be either an existing GKE user or begin by creating a GKE account.
If you are an existing GKE user, with the Google Cloud SDK installed and Kubernetes Engine Admin privileges, you can move on to "Installation of the PostgreSQL Operator Playbooks"
If you are not currently a GKE user, Google Cloud Platform provides a quickstart with the necessary steps. A few tips to consider:
Ensure that the Google Kubernetes Engine API is enabled for your project. If you do not see “API enabled”, then you may enable the API by clicking the “Enable this API” button.
It is necessary to install and configure the Google Cloud SDK and include the kubectl component.
Set your default compute service account to include: (1) Kubernetes Engine Admin and (2) Editor (on by default). To set this up, navigate to the IAM section of the Cloud Console.
Installation of the PostgreSQL Operator Playbooks
The Crunchy PostgreSQL Operator roles associated with the Crunchy PostgreSQL Operator Installer are available in the postgres-operator project repository. These roles are dependent on Ansible 2.4.6+.
In order to deploy those roles it is necessary to clone that repository in your local environment.
Configuration of Permissions
The installation of the Crunchy PostgreSQL Operator requires elevated privileges. In particular, it is required that the playbooks are run as a cluster-admin to ensure the playbooks can install:
Please confirm that you have the necessary cluster-admin privileges before proceeding.
Configuration of Operator Variables in the Inventory File
The inventory file included with the PostgreSQL Operator Playbooks allows the Ansible installer to configure how the operator will function when deployed into Kubernetes.
The table provided at the end of this post under the heading "More Information - Default Installation Configurations" provides a list of the installed operator variables implemented by the Ansible playbook.
It is of course worth noting that these values are provided for a simple single zone, "getting started" deployment to evaluate and test the operator, and are not intended for production environments.
This table is provided for your information only, no action is required to complete the install.
Install the PostgreSQL Operator
In order to install the PostgreSQL Operator, it is necessary to simply run the following command:
ansible-playbook -i /path/to/inventory --tags=install --ask-become-pass main.yml
This may take a few minutes to deploy.
Verifying the Installation
To check the status of the deployment run the following:
kubectl get deployments -n pgo
kubectl get pods -n pgo
After the Crunchy PostgreSQL Operator has successfully been installed we will need to configure local environment variables before using the pgo client.
To configure the environment variables used by pgo run the following command:
cat <<EOF >> ~/.bashrc
export PGO_NAMESPACE=pgo
export PGOUSER="${HOME?}/.pgo/pgo/pgouser"
export PGO_CA_CERT="${HOME?}/.pgo/pgo/client.crt"
export PGO_CLIENT_CERT="${HOME?}/.pgo/pgo/client.crt"
export PGO_CLIENT_KEY="${HOME?}/.pgo/pgo/client.pem"
export PGO_APISERVER_URL='https://127.0.0.1:8443'
EOF
Apply those changes to the current session by running:
source ~/.bashrc
Verify pgo Connection
In a separate terminal we need to setup a port forward to the Crunchy PostgreSQL Operator to ensure connection can be made outside of the cluster:
kubectl port-forward <OPERATOR_POD_NAME> -n pgo 8443:8443
On a separate terminal verify the pgo can communicate with the Crunchy PostgreSQL Operator:
pgo version
If the above command outputs versions of both the client and API server, the Crunchy PostgreSQL Operator has been installed successfully.
Ready to Deploy PostgreSQL Clusters
With the Crunchy PostgreSQL Operator Installed, you are ready to go.
Crunchy PostgreSQL Operator extends Kubernetes to support the creation, configuration and management of PostgreSQL clusters at scale. Built on top of the Crunchy PostgreSQL Container Suite, the Crunchy PostgreSQL Operator provides an open source software solution for PostgreSQL scaling, high-availability, disaster recovery, monitoring, and more.
You can find out more about the available PostgreSQL Operator commands available here. To view all of the commands available you can run pgo --help
or review the PGO CLI command help here.
More Information - Default Installation Configurations
The Crunchy PostgreSQL Operator enables enterprise to deploy Kubernetes native PostgreSQL-as-a-Service. In order to support a broad range of enterprise requirements, the Operator provides a number of configuration variables that are intended to enable a broad range of use cases.
To learn more about the range of configuration options in the Crunchy PostgreSQL Operator, please see the Operator documentation.
The table provided below reflects the installed operator variables implemented by the Ansible playbook. It is worth repeating that these default values are provided for a simple single zone, "getting started" deployment to evaluate and test the operator, and are not intended for production environments.
Default Operator Configurations from Ansible Install
Configuration Variable | Configuration Variable Notes | Ansible Installer Default GKE Value |
---|---|---|
kubernetes_context | Set to configure the context name of the kubeconfig used for authentication | To retrieve the kubernetes_context value, run the following command: kubectl config current-context |
pgo_admin_username | Configures pgo administrator username | admin |
pgo_admin_password | Configures pgo administrator password | admin |
pgo_operator_namespace | Set to configure namespace where Operator will be deployed | pgo |
namespace | Set to a comma delimited string of all namespaces Operator will manage. For this demonstration, only one namespace - namespace where the operator will be deployed - will be watched. | pgo |
ccp_image_prefix | Configures image prefix used when creating containers from Crunchy Container Suite | crunchydata |
ccp_image_tag | Configures image tag (version) used when creating containers from Crunchy Container Suite | centos7-11.3-2.4.0 |
pgo_image_prefix | Configures image prefix used when creating containers for Operator (apiserver, operator, scheduler..etc) | crunchydata |
pgo_image_tag | Configures image tag used when creating containers for Operator (apiserver, operator, scheduler..etc) | centos7-4.0.0 |
pgo_client_install | Configures playbooks to install pgo client if set to true | TRUE |
pgo_client_version | Configures which version of pgo playbooks should install. | 4.0.0 |
pgo_tls_no_verify | Set to configure Operator to verify TLS certificates | FALSE |
backrest_storage | Set to configure storage definition to use when creating volumes used by pgBackRest on all newly created clusters | storage1 |
backup_storage | Set to configure storage definition to use when creating volumes used by pgBaseBackup on all newly created clusters | storage1 |
primary_storage | Set to configure storage definition to use when creating volumes used by PostgreSQL primaries on all newly created clusters | storage1 |
replica_storage | Set to configure storage definition to use when creating volumes used by PostgreSQL replicas on all newly created clusters | storage1 |
storage<ID>_access_mode | Set to configure storage definition to all primary pods created by Operator. | storage1_access_mode='ReadWriteOnce' |
storage<ID>_size | Set to configure storage definition to all primary pods created by Operator. | storage1_size='10G' |
storage<ID>_type | Set to configure storage definition to all primary pods created by the Operator. | storage1_type='dynamic' |
storage<ID>_class | Set to configure storage definition to all primary pods created by the Operator. | storage1_class='standard' |
storage<ID>_supplemental_groups | Set to configure storage definition to all primary pods created by the Operator. | Since this demonstration is for GKE, this parameter should be commented out as it’s not applicable to GKE |
storage<ID>_fs_group | Set to configure storage definition to all primary pods created by the Operator. | storage1_fs_group=26 |
Related Articles
- Crunchy Data Warehouse: Postgres with Iceberg for High Performance Analytics
8 min read
- Loading the World! OpenStreetMap Import In Under 4 Hours
6 min read
- Easy Totals and Subtotals in Postgres with Rollup and Cube
5 min read
- A change to ResultRelInfo - A Near Miss with Postgres 17.1
8 min read
- Accessing Large Language Models from PostgreSQL
5 min read