Skip to main content
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.
The image depicts a diagram of a Single-Node Kubernetes Cluster, highlighting observability, continuous deployment, and database components. It is labeled "Cluster Scoped" with icons representing each component.
Overview: this is the fourth and final cluster-scoped package we install. Key characteristics of this package:
The image is about a database operator for managing PostgreSQL workloads, highlighting features like "Cluster scoped," "No value definitions," and "No entry points."
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.
The image is a diagram illustrating a single-node Kubernetes cluster setup, showing a database with PostgreSQL primary instances in separate namespaces and a development namespace containing an application interacting with 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:
The image shows the Glasskube UI for installing the "cloudnative-pg" package, with version selection and installation details.
Confirm the operator package is available in the Glasskube catalog with glasskube list. Sample output showing the cloudnative-pg entry:
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:
Apply the Cluster manifest using a heredoc to kubectl:
Watch the operator and StatefulSet pods initialize. If you have an alias like kgp for kubectl get pods, you can use that; otherwise run:
Initial sample output while pods initialize (you will see init containers and join phases):
After a short time, the StatefulSet pods become Ready and the operator controller-manager is running:
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:

Watch Video

Practice Lab