CloudNativePG
CloudNativePG is a Kubernetes operator that manages the full lifecycle of highly available PostgreSQL clusters. It provides native Kubernetes integration for PostgreSQL via a Cluster custom resource, including automated failover, backup/restore, and rolling updates.
This showcase deploys a CloudNativePG operator, a sample PostgreSQL cluster, and pgAdmin 4 as a web-based database management UI — pre-configured to connect to the sample cluster.
Precondition
A running k3d cluster. The httpbin sample is not required for this showcase.
Installation
cd examples/cloudnative-pg
bash setup.shpgAdmin is exposed via Kong Gateway — the sole ingress controller in this cluster.
The following components are installed by setup.sh:
- CloudNativePG operator — Helm Chart (namespace:
cnpg-system) - PostgreSQL cluster —
ClusterCRsample-pg(namespace:cloudnative-pg)- 1 instance (suitable for local demo)
- Database
sampledb, ownerappuser - Exposes
sample-pg-rw(read-write) andsample-pg-ro(read-only) services
- pgAdmin 4 — Helm Chart (namespace:
pgadmin)- Pre-configured server connection to
sample-pg - Exposed via a Kong Gateway
HTTPRoute
- Pre-configured server connection to
Access pgAdmin UI
Open pgAdmin in your browser via http://pgadmin.127-0-0-1.nip.io:8080.
Login credentials:
| Field | Value |
|---|---|
| admin@example.com | |
| Password | admin |
The server sample-pg (primary) is pre-registered under the group CloudNativePG. Use the password apppassword when prompted for the database connection.
Connect to PostgreSQL directly
Retrieve the superuser credentials created by CloudNativePG:
kubectl get secret sample-pg-superuser -n cloudnative-pg \
-o jsonpath='{.data.username}' | base64 -d
kubectl get secret sample-pg-superuser -n cloudnative-pg \
-o jsonpath='{.data.password}' | base64 -dConnect via psql from inside the cluster:
kubectl run psql --rm -it --image=postgres:16 --restart=Never -- \
psql -h sample-pg-rw.cloudnative-pg.svc -U appuser -d sampledbCleanup
kubectl delete cluster sample-pg -n cloudnative-pg
helm uninstall pgadmin4 -n pgadmin
helm uninstall cnpg -n cnpg-system
kubectl delete namespace cloudnative-pg pgadmin cnpg-system