At PGConf.de in Berlin this year, I had the pleasure of presenting on the powerful combination of CloudNativePG and GitOps. For those who couldn’t attend — or anyone looking to streamline their PostgreSQL cluster management — this blog post shows how to apply GitOps principles with CloudNativePG for a more efficient and reliable database infrastructure.

This guide focuses on experimenting locally with CloudNativePG and ArgoCD using kind, a tool for running Kubernetes clusters in Docker.

CloudNativePG is a Kubernetes operator that simplifies the management of PostgreSQL clusters. It automates tasks like creation, scaling, backups, and recovery, making it a great tool for running PostgreSQL in a cloud-native environment. But what if we could take this a step further and manage our database infrastructure with the same declarative and version-controlled approach we use for applications? That’s where GitOps comes in.

GitOps: Declarative Infrastructure Management

GitOps is a modern operational model that applies DevOps best practices — version control, collaboration, and automation — to infrastructure. In this model, your Git repository is the single source of truth for your system’s desired state. Tools like ArgoCD ensure that your runtime environment continuously matches what’s defined in Git.

Why Combine CloudNativePG and GitOps?

Combining CloudNativePG with ArgoCD provides major advantages:

  • Declarative Configuration: Define PostgreSQL clusters as YAML files in Git.
  • Versioning and Rollback: Use Git history to track and revert changes.
  • Automation: ArgoCD syncs changes from Git to your cluster automatically.
  • Scalability: Scale by simply updating the Git repository.
  • Security: Reduce direct access to production clusters.
  • Auditability: Every change is documented and traceable.

Getting Started: Local GitOps with CloudNativePG and ArgoCD

You can try this setup using the resources in my GitHub repository:

https://github.com/proventa/cloudnativepg-with-gitops

It provides:

  • a kind cluster with 5 nodes
  • installation instructions for ArgoCD and CloudNativePG
  • example PostgreSQL cluster definitions

Prerequisites

Install the following tools:

Step-by-Step Setup

1. Set up the Kubernetes Cluster

Copy to Clipboard

2. Install CloudNativePG

Copy to Clipboard

Verify the controller is running:

Copy to Clipboard

3. Install ArgoCD

Copy to Clipboard

4. Access the ArgoCD UI

Copy to Clipboard

Retrieve the initial admin password:

Copy to Clipboard

Visit https://localhost:8080 and log in with username admin.

⚠️ Note: Your browser may warn you about the self-signed certificate when accessing the ArgoCD UI.

5. Define Your PostgreSQL Cluster in Git

Example file (cnpg-cluster.yaml):

Copy to Clipboard

6. Define an ArgoCD Application

Example file (cnpg-cluster.yaml):

File: argocd-app/cnpg.yaml

Copy to Clipboard

7. Apply the ArgoCD Application

Copy to Clipboard

8. Observe ArgoCD in Action

In the ArgoCD UI, you’ll see the application status and sync controls. If auto-sync is enabled, changes pushed to Git will be applied automatically. Otherwise, click Sync to trigger deployment.

Further Exploration

The repository also includes optional tools for more advanced scenarios:

  • cnpg plugin for kubectl – e.g. to trigger backups or failovers
  • Kubernetes Dashboard – install via Helm for visual inspection
  • ArgoCD CLI – manage applications via terminal or sync directly from local manifests
  • LoadBalancer support – expose PostgreSQL to the outside if needed

Conclusion

Integrating CloudNativePG with GitOps provides a robust and efficient way to manage your PostgreSQL clusters in a Kubernetes environment. By leveraging declarative configuration, version control, and automation, you can improve consistency, reliability, and collaboration within your team. While the setup outlined here is for experimentation, the principles and workflows can be adapted for more complex production environments.

Feel free to fork the repository, adapt it to your use case, and share feedback or improvements!

Theodor Herlo

Theodor Herlo ist als Senior Consultant für die Proventa AG tätig. Sein technologischer Schwerpunkt liegt bei Datenbankarchitekturen mit PostgreSQL sowie Data-Management-Lösungen mit Pentaho. Er verfügt über Erfahrung in Branchen wie Telekommunikation, Finanzen und öffentlicher Sektor.