CloudNativePG is an open-source Kubernetes operator that automates PostgreSQL management, including creation, scaling, backup, and healing. It combines custom resource definitions with a controller, exposing PostgreSQL operations through Kubernetes resources. section 5.4
Use CloudNativePG through three operational layers:
- Install the operator and its PostgreSQL-related CRDs, which add resources such as clusters, backups, databases, and scheduled backups. section 5.4.2
- Distinguish a CRD from a custom resource: the CRD defines a resource type, while a CR is an instance created from that definition. section 5.4.3
- Verify the controller Deployment and inspect the resulting PostgreSQL cluster with kubectl. section 5.4.3
Create and verify a PostgreSQL cluster
Apply a Cluster custom resource with apiVersion postgresql.cnpg.io/v1, one instance, and 1Gi of storage: kubectl apply -f postgres-cluster.yaml. Then run kubectl get cluster my-postgres-cluster and kubectl get pods; successful output shows a healthy cluster and a Running PostgreSQL pod. section 5.4.3
root@kind-control-plane:/# kubectl apply --server-side -f https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/release- 1.26/releases/cnpg-1.26.1.yaml namespace/cnpg-system serverside-applied customresourcedefinition.apiextensions.k8s.io/backups.postgresql.cnpg.io serverside-applied customresourcedefinition.apiextensions.k8s.io/clusterimagecatalogs.postgres ql.cnpg.io serverside-applied customresourcedefinition.apiextensions.k8s.io/clusters.postgresql.cnpg.io serverside-applied customresourcedefinition.apiextensions.k8s.io/databases.postgresql.cnpg.io serverside-applied customresourcedefinition.apiextensions.k8s.io/imagecatalogs.postgresql.cnpg .io serverside-applied customresourcedefinition.apiextensions.k8s.io/poolers.postgresql.cnpg.io serverside-applied customresourcedefinition.apiextensions.k8s.io/publications.postgresql.cnpg. io serverside-applied
Review the server-side installation output to identify the cnpg-system namespace and the PostgreSQL CRDs installed by CloudNativePG. section 5.4.2
