Member-only story

Deploy PostgreSQL in Kubernetes using CloudNativePG

Luca Berton
2 min readOct 30, 2024

CloudNativePG is a Kubernetes operator designed to manage PostgreSQL clusters in a cloud-native environment. It automates the lifecycle of PostgreSQL databases, including provisioning, scaling, backup, and disaster recovery, following Kubernetes-native patterns. CloudNativePG simplifies deploying and operating PostgreSQL in Kubernetes by leveraging Custom Resource Definitions (CRDs) and the PostgreSQL Operator pattern.

Key Features of CloudNativePG:

  1. PostgreSQL Cluster Management: CloudNativePG manages the entire lifecycle of PostgreSQL clusters, including provisioning, scaling, and upgrades.
  2. High Availability: Provides native support for high-availability PostgreSQL clusters with automated failover and replication.
  3. Backup and Restore: Integrated backup and recovery solutions with support for continuous backups using tools like pgBackRest.
  4. Disaster Recovery: Multi-cluster and cross-region disaster recovery mechanisms using asynchronous replication.
  5. Monitoring and Observability: Built-in monitoring features through integration with tools like Prometheus, providing detailed metrics for cluster health and performance.

Example: CloudNativePG Cluster YAML

Here’s an example configuration file to deploy a PostgreSQL cluster using CloudNativePG:

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: my-postgresql-cluster
namespace: my-database-namespace
spec:
instances: 3
storage:
size: 1Gi
primaryUpdateStrategy: unsupervised
backup:
barmanObjectStore:
destinationPath: s3://my-bucket/my-cluster-backups
s3Credentials:
accessKeyId: my-access-key
secretAccessKey: my-secret-key
monitoring:
enabled: true
exporter:
image: quay.io/prometheuscommunity/postgres-exporter

Breakdown:

  • instances: Defines how many PostgreSQL instances to run in the cluster.
  • storage: Defines the persistent volume size for PostgreSQL data.
  • primaryUpdateStrategy: Defines the update strategy for the primary instance.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Luca Berton
Luca Berton

Written by Luca Berton

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday

No responses yet

Write a response