Create an Instance

Feature Overview

This feature allows users to create and manage PostgreSQL database instances within a Kubernetes cluster. Users can quickly deploy database instances that meet their needs by configuring:

  • Resource specifications
  • Account information
  • Storage requirements

Prerequisites

Before creating a PostgreSQL instance, please ensure that:

  1. Appropriate storage classes have been configured.
  2. Postgres Operator is correctly installed and running.
  3. You have the necessary permissions to create resources.

Version Support

Currently, PostgreSQL versions 11,12,14 are supported, with the recommendation to use the latest stable version.

Architecture Choices

Postgres Operator supports the following architectures:

  • Single Node: Suitable for development and testing environments
  • Primary-Replica Replication: Recommended for production environments with:
    • Automatic failover
    • High availability
    • Data redundancy

Procedure

CLI
Web Console

Create a Single Node Instance

# Example minimal HA cluster configuration
cat << EOF | kubectl create -f -
apiVersion: acid.zalan.do/v1
kind: postgresql  # Custom resource definition for PostgreSQL clusters
metadata:
  name: pg-single
  namespace: c1-midautons
spec:
  ipFamilyPrefer: ""
  teamId: ACID
  enableExporter: true
  enablePgpool2: false
  spiloPrivileged: false
  spiloRunAsGroup: 103
  spiloRunAsUser: 101
  spiloAllowPrivilegeEscalation: false
  enableReadinessProbe: true
  postgresql:
    parameters:
      log_directory: /var/log/pg_log
    version: "14"
  numberOfInstances: 1
  resources:
    requests:
      cpu: "1"
      memory: 2Gi
    limits:
      cpu: "1"
      memory: 2Gi
  volume:
    size: 5Gi
    storageClass: c1-topolvmsc
EOF

Create a High Availability Cluster

cat << EOF | kubectl -n $NAMESPACE create -f -
apiVersion: acid.zalan.do/v1
kind: postgresql
metadata:
  name: pg-ha
  namespace: default
spec:
  ipFamilyPrefer: ""
  teamId: ACID
  enableExporter: true
  enablePgpool2: false
  spiloPrivileged: false
  spiloRunAsGroup: 103
  spiloRunAsUser: 101
  spiloAllowPrivilegeEscalation: false
  enableReadinessProbe: true
  postgresql:
    parameters:
      log_directory: /var/log/pg_log
    version: "14"
  numberOfInstances: 3
  resources:
    requests:
      cpu: "1"
      memory: 2Gi
    limits:
      cpu: "1"
      memory: 2Gi
  volume:
    size: 50Gi
    storageClass: default
  patroni:
    ttl: 30
    loop_wait: 10
    retry_timeout: 10
EOF

After creation, you can check the instance status using the following command:

kubectl -n $NAMESPACE get postgresql

Expected output:

NAME                            AGE
pg-ha                           21h

Output fields:

FieldDescription
NAMEInstance name
AGETime since creation

Note

  1. For production environments, use the primary-replica architecture
  2. Verify your storage class supports dynamic provisioning before deployment
  3. Configure appropriate resource limits
  4. Implement regular backup procedures for critical data

Warning

  • Improper resource limits may lead to performance issues or pod evictions
  • Without backups, data loss may occur during failures