TL;DR:
- Call the module once per desired target cluster.
- The provider alias you pass into the module determines the cluster.
- Customize the Kubernetes resources per environment using Terraform syntax.
Use the module
To provision the PostgreSQL Operator Terraform module on a Kubernetes cluster, call the module, set source
and version
, and pass an aliased kustomization
provider into the module.
The provider configuration determines what cluster the Kuberneters resources are provisioned on.
Framework documentation includes a complete example of how the kubeconfig
output of a cluster module can be used to configure a kustomization
provider alias.
module "eks_zero_postgresql" {providers = {kustomization = kustomization.eks_zero}source = "kbst.xyz/catalog/postgresql/kustomization"version = "1.7.1-kbst.2"}
module "aks_zero_postgresql" {providers = {kustomization = kustomization.aks_zero}source = "kbst.xyz/catalog/postgresql/kustomization"version = "1.7.1-kbst.2"}
module "gke_zero_postgresql" {providers = {kustomization = kustomization.gke_zero}source = "kbst.xyz/catalog/postgresql/kustomization"version = "1.7.1-kbst.2"}
Customize resources
All Kubestack cluster service modules support the same module attributes and per environment configuration. The module configuration is a Kustomization set in the per environment configuration map following Kubestack's inheritance model.
This example overwrites the metadata.namespace
of all Kubernetes resources provisioned by the PostgreSQL Operator module using a Terraform variable.
module "example_postgresql" {providers = {kustomization = kustomization.example}source = "kbst.xyz/catalog/postgresql/kustomization"version = "1.7.1-kbst.2"configuration = {apps = {namespace = var.example_postgresql_namespace}ops = {}loc = {}}}
Full documentation how to customize a module's Kubernetes resources is available in the cluster service module configuration section of the framework documentation.
Usage
Once the operator has been deployed to the Kubernetes cluster, you can use it to provision and operate one or more database clusters by creating a custom object of the operator's custom resource.
PostgreSQL Custom Object
Below is an example of a minimal PostgreSQL custom object to instruct the operator to provision a database cluster.
To get started, put the example below into a file called postgresql.yaml
and add it to your application's manifests. Then apply the manifests including the postgresql.yaml
as usual.
apiVersion: "acid.zalan.do/v1"kind: postgresqlmetadata:name: acid-minimal-clusternamespace: defaultspec:postgresql:version: "10"teamId: "ACID"volume:size: 1GinumberOfInstances: 2users:# admin useradmin:- superuser# application userapp_user: []databases:# db_name: user_nameapp_db: app_user
Configuring your cluster
Make sure to configure name and namespace and the users and databases according to your application's requirements.
You can find additional information on these parameters and additional options in the upstream project's documentation.