ข้ามไปยังเนื้อหา

This is the Stable version of the documentation. The latest version is experimental and under active development. You can use the version selector in the top-right menu to switch versions for this specific page, or click here to go to the latest version's homepage.

CloudnativePG Installation

เนื้อหานี้ยังไม่มีในภาษาของคุณ

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.

  1. Connect to 🟢 Management Kubernetes 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 $HOME/opstella-installation/shell-values/kubernetes/management_cluster.vars.sh
    Terminal window
    export KUBECONFIG="$HOME/opstella-installation/kubeconfigs/management_cluster.yaml"
  2. 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-manager will be installed on 🟢 Management Kubernetes Cluster.

    Create Namespace for cert-manager:

    Terminal window
    kubectl create namespace cert-manager

    Install 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
  3. Create Namespace for CloudnativePG Controller

    Terminal window
    kubectl create namespace cnpg-system
  4. Add CloudnativePG Helm Repository

    Terminal window
    helm repo add cnpg https://cloudnative-pg.github.io/charts
    helm repo update
  5. 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: 1
    image:
    repository: ghcr.io/cloudnative-pg/cloudnative-pg
    pullPolicy: IfNotPresent
    # tag: "" # Overrides default tag
    # Enable CRD creation by the chart
    crds:
    create: true
    # Operator configuration
    config:
    create: true
    name: cnpg-controller-manager-config
    clusterWide: true
    monitoring:
    podMonitorEnabled: false # Enabled per-cluster in the Cluster manifest usually
    # Monitoring / Prometheus Operator integration
    monitoring:
    podMonitorEnabled: false # This is for monitoring the operator itself, usually not needed unless debugging operator
    EOF
  6. 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 Production
    resources:
    limits:
    cpu: 200m
    memory: 256Mi
    requests:
    cpu: 100m
    memory: 128Mi
    EOF
  7. Install CloudnativePG Helm Release

    Terminal window
    helm upgrade --install cnpg cnpg/cloudnative-pg \
    --version 0.27.0 \
    --namespace cnpg-system \
    -f $HOME/opstella-installation/helm-values/cnpg-full-values.yaml
  8. 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 $HOME/opstella-installation/helm-values/cnpg-barman-full-values.yaml
  1. Get Pod Status - CloudnativePG Controller

    Terminal window
    kubectl get pods -n cnpg-system

    💡 CloudnativePG Controller and Barman Plugin should be Running

    NAME READY STATUS RESTARTS AGE
    ... (deducted)
    cnpg-cloudnative-pg-XXXXXXXX-YYYYYY 1/1 Running 0 XdXh
    cnpg-plugin-barman-XXXXXXXX-YYYYYY 1/1 Running 0 XdXh

Finished?

Use the below navigation to proceed