Guide to installing and using the CloudNativePG Kubernetes operator to deploy and manage PostgreSQL clusters with StatefulSets, Services, and monitoring via Glasskube.
Welcome back. In this lesson we’ll add a managed PostgreSQL database to the cluster using the CloudNativePG operator. CloudNativePG is a Kubernetes operator that simplifies running and operating PostgreSQL clusters on Kubernetes by provisioning StatefulSets, Services, and handling failover and replica management.
Overview: this is the fourth and final cluster-scoped package we install. Key characteristics of this package:
Property
Details
Scope
Cluster-scoped package
Values
No value definitions
Entry points
No entry points
Dependencies
No dependencies
We install the CloudNativePG operator into the cnpg-system namespace. The operator watches Postgres Cluster custom resources and creates StatefulSet-backed PostgreSQL instances and the Service endpoint applications use to connect. The diagram below shows the operator running in a system namespace while a sample application in a different namespace connects to the database cluster.
Create a Postgres cluster by applying a Cluster manifest. The operator will translate this manifest into StatefulSets, PersistentVolumes (via PVCs), Services, and monitoring resources.Example minimal Cluster manifest (3 instances, 1Gi storage, PodMonitor enabled):
You can install CloudNativePG from the Glasskube UI or via the Glasskube CLI. This is the installation screen in Glasskube:
Confirm the operator package is available in the Glasskube catalog with glasskube list. Sample output showing the cloudnative-pg entry:
glasskube listPACKAGE NAME NAMESPACE NAME VERSION AUTO-UPDATE REPOSITORY STATUSingress-nginx glasskube Not installedquickwit glasskube Not installedNAME VERSION AUTO-UPDATE REPOSITORY STATUSakri - - glasskube Not installedargo-cd v2.11.7+1 Enabled glasskube Readycaddy-ingress-controller - - glasskube Not installedcert-manager - - glasskube Not installedcloudnative-pg - - glasskube Not installedcyclops - - glasskube Not installedkube-prometheus-stack v61.6.0+1 - glasskube Readykubetail v0.6.0+1 Enabled glasskube Ready
In this walkthrough we enabled automatic updates and installed CloudNativePG from the Glasskube catalog. After installation, the package will appear as installed in the UI.Before applying the Cluster manifest, switch your kubectl context to the cnpg-system namespace so commands default there:
After the cluster is ready, CloudNativePG creates a Kubernetes Service for client connections and maintains that Service through failover events. Inspect the Service and Endpoints in cnpg-system to get host and port information used by applications.
That completes the demo. Practice installing the CloudNativePG operator and creating a Postgres Cluster using the manifest above.Links and references: