This is the Experimental version (Latest). It is under active development and may change. For the most reliable documentation, use the version selector in the top-right to switch to Stable, or click here to go to the Stable version's homepage.
CloudnativePG Installation
Last updated:
What is CloudNativePG (CNPG)?
Section titled “What is CloudNativePG (CNPG)?”CloudNativePG (CNPG) is an open-source Kubernetes Operator designed to manage the entire lifecycle of a PostgreSQL database cluster. For those new to “Operators,” think of it as a “digital DBA” (Database Administrator) that lives inside your Kubernetes cluster.
Instead of you manually setting up replication, managing backups, or handling complex failovers, CNPG automates these tasks:
- Self-Healing & High Availability: It automatically manages a primary-standby architecture. If the primary database fails, CNPG detects the failure and promotes a standby to be the new primary within seconds.
- Declarative Management: You define what your database should look like (e.g., “I want 3 replicas with 10GB storage”) in a YAML file, and the operator makes it happen.
- Automated Backups & Recovery: It integrates natively with object storage (like S3 or SeaweedFS) to handle continuous archiving and point-in-time recovery.
- Kubernetes Native: It is designed specifically for Kubernetes, using standard Kubernetes features like Pods, Services, and RBAC to ensure your database is as scalable and resilient as your applications.
CloudNativePG is currently a CNCF Sandbox project, originally developed by EDB, and is the preferred way to run production-grade PostgreSQL in modern cloud-native environments.
CloudNativePG will be installed on 🟢 Management Kubernetes Clusters.
Installation
Section titled “Installation”-
Connect to
🟢 ManagementKubernetes Cluster ; _i.e w/ Kubeconfig File.Set Kubeconfig File
Ensure you have defined and loaded your Global Shell Variables as described in Shell Variables.
Terminal window source $BASE_WORKING_DIR/shell-values/kubernetes/management_cluster.vars.sh -
Install cert-manager
CloudnativePG requires TLS certificates for its Admission Webhooks to ensure secure communication between the Kubernetes API server and the operator. By installing
cert-manager, we enable automated certificate management, which handles the issuance and renewal of these certificates, ensuring the operator functions correctly without manual certificate management.cert-managerwill be installed on🟢 ManagementKubernetes Cluster.Create Namespace for cert-manager:
Terminal window kubectl create namespace cert-managerInstall cert-manager using Helm:
Terminal window helm upgrade --install cert-manager oci://quay.io/jetstack/charts/cert-manager \--version v1.19.2 \--namespace cert-manager \--set crds.enabled=true -
Create Namespace for CloudnativePG Controller
Terminal window kubectl create namespace cnpg-system -
Add CloudnativePG Helm Repository
Terminal window helm repo add cnpg https://cloudnative-pg.github.io/chartshelm repo update -
Create Helm Values Configurations for Operator
Terminal window cat <<EOF > $BASE_WORKING_DIR/helm-values/cnpg-full-values.yaml# CloudNativePG Operator Helm Values (Chart v0.27.0)replicaCount: 1image:repository: ghcr.io/cloudnative-pg/cloudnative-pgpullPolicy: IfNotPresent# tag: "" # Overrides default tag# Enable CRD creation by the chartcrds:create: true# Operator configurationconfig:create: truename: cnpg-controller-manager-configclusterWide: truemonitoring:podMonitorEnabled: false # Enabled per-cluster in the Cluster manifest usually# Monitoring / Prometheus Operator integrationmonitoring:podMonitorEnabled: false # This is for monitoring the operator itself, usually not needed unless debugging operatorEOF -
Create Helm Values Configurations for Barman Plugin
Terminal window cat <<EOF > $BASE_WORKING_DIR/helm-values/cnpg-barman-full-values.yaml# Production overrides for CNPG Barman Cloud Plugin# Version: 0.4.0# Resource Limits for Productionresources:limits:cpu: 200mmemory: 256Mirequests:cpu: 100mmemory: 128MiEOF -
Install CloudnativePG Helm Release
Terminal window helm upgrade --install cnpg cnpg/cloudnative-pg \--version 0.27.0 \--namespace cnpg-system \-f $BASE_WORKING_DIR/helm-values/cnpg-full-values.yaml -
Install CloudnativePG Barman Plugin Helm Release
Terminal window helm upgrade --install cnpg-plugin-barman cnpg/plugin-barman-cloud \--version 0.4.0 \--namespace cnpg-system \-f $BASE_WORKING_DIR/helm-values/cnpg-barman-full-values.yaml
Post-Installation
Section titled “Post-Installation”CloudnativePG Testing
Section titled “CloudnativePG Testing”-
Get Pod Status - CloudnativePG Controller
Terminal window kubectl get pods -n cnpg-system💡 CloudnativePG Controller and Barman Plugin should be
RunningNAME READY STATUS RESTARTS AGE... (deducted)cnpg-cloudnative-pg-XXXXXXXX-YYYYYY 1/1 Running 0 XdXhcnpg-plugin-barman-XXXXXXXX-YYYYYY 1/1 Running 0 XdXh
Finished?
Use the below navigation to proceed