Installing the CloudNativePG operator (for the VizOperator)

We use the CloudNativePG operator for our Data Visualisation service. It is used to create databases in the namespace the visualisation is expected to run.

Installing the operator

One path is to start with the cnpg plugin for kubectl, which helps you create (fine-tune) the installation manifests for the operator. On macOS: -

brew install kubectl-cnpg

With this done we can generate an operator.yaml file that defines an operator that installs in the cloud-native-pg-operator Namespace that watches two of our Data Manager namespaces: -

kubectl cnpg install generate \
  -n cloud-native-pg-operator \
  --watch-namespace "data-manager-api-dev, data-manager-api-test" \
  > operator.yaml

And installed with: -

kubectl apply --server-side -f operator.yaml

Creating an “image catalogue”

The operator allows for custom PostgreSQL images using an ImageCatalogue that is deployed into the Namespace where the database is expected. this allows us to provide custom images indexed by major database version. Here’s an example catalogue for our data-manager-api-dev Namespace that uses the Release_2024_03_3 image: -

---
# A PostgreSQL image catalogue.
# This defines custom images mapped against major versions.
# The map belongs in the target namespace (not the operator's).
# The catalogue allows us to use any image,
# which we refer to by "major" version in the CRD.
apiVersion: postgresql.cnpg.io/v1
kind: ImageCatalog
metadata:
  name: rdkit
  namespace: data-manager-api-dev
spec:
  images:
    - major: 15
      image: informaticsmatters/rdkit-cartridge-debian:Release_2024_03_3

We then install this with kubectl: -

kubectl apply --server-side -f rdkit-catalogue.yaml

Creating a database

With the operator running and an image catalogue defined we can now provision a database with a suitable CRD: -

---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: viz-org-0000
  namespace: data-manager-api-dev
spec:
  instances: 1
  enableSuperuserAccess: true
  imageCatalogRef:
    apiGroup: postgresql.cnpg.io
    kind: ImageCatalog
    name: rdkit
    major: 15
  postgresUID: 100
  postgresGID: 102
  storage:
    size: 1Gi
    storageClass: csi-cinder-sc-delete
  bootstrap:
    initdb:
      database: viz
      owner: viz-a
      postInitApplicationSQL:
      - CREATE EXTENSION IF NOT EXISTS rdkit

Key elements here include: -

  • A reference to the entry in the ImageCatalog
  • A UID and GID suitable for our image
  • The storageClass
  • Customised post-initialisation commands

The above creates a single viz-org-0000-1 database Pod, and various viz-org-000 Services to access it. Comprehensive details of the database, including credentials will be deposited in the viz-org-0000-app Secret.