dhi.io/cloudnative-pg-chart
CloudNativePG is the Kubernetes operator that covers the full lifecycle of a highly available PostgreSQL database cluster with a primary/standby architecture, using native streaming replication.
All examples in this guide use the public chart and images. If you've mirrored the repository for your own use (for example, to your Docker Hub namespace), update your commands to reference the mirrored chart instead of the public one.
For example:
dhi.io/<repository>:<tag><your-namespace>/dhi-<repository>:<tag>For more details about customizing the chart to reference other images, see the documentation.
To optionally mirror a chart to your own third-party registry, you can follow the instructions in How to mirror an image for either the chart, the image, or both.
The same regctl tool that is used for mirroring container images can also be used for mirroring Helm charts, as Helm
charts are OCI artifacts.
For example:
regctl image copy \
"${SRC_CHART_REPO}:${TAG}" \
"${DEST_REG}/${DEST_CHART_REPO}:${TAG}" \
--referrers \
--referrers-src "${SRC_ATT_REPO}" \
--referrers-tgt "${DEST_REG}/${DEST_CHART_REPO}" \
--force-recursive
The Docker Hardened Images that the chart uses require authentication. To allow your Kubernetes cluster to pull those images, you need to create a Kubernetes secret with your Docker Hub credentials or with the credentials for your own registry.
Follow the authentication instructions for DHI in Kubernetes.
For example:
kubectl create secret docker-registry helm-pull-secret \
--docker-server=dhi.io \
--docker-username=<Docker username> \
--docker-password=<Docker token> \
--docker-email=<Docker email>
To install the chart, use helm install. Make sure you use helm login to log in before running helm install.
Optionally, you can also use the --dry-run flag to test the installation without actually installing anything.
helm install my-cloudnative-pg oci://dhi.io/cloudnative-pg-chart --version <version> \
--set "imagePullSecrets[0].name=helm-pull-secret" \
Replace <version> accordingly. If the chart is in your own registry or repository, replace dhi.io with your own
registry and namespace. Replace helm-pull-secret with the name of the image pull secret you created earlier.
The deployment's pod should show up and running almost immediately:
$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/my-cloudnative-pg-5d7f856996-wv4dp 1/1 Running 0 19s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/cnpg-webhook-service ClusterIP 10.43.97.117 <none> 443/TCP 19s
service/kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 33s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/my-cloudnative-pg 1/1 1 1 19s
NAME DESIRED CURRENT READY AGE
replicaset.apps/my-cloudnative-pg-5d7f856996 1 1 1 19s
With the operator ready, we can follow CloudNativePG quick start and launch a simple three replicas PostgreSQL cluster. First create the following yaml file.
#postgres-example.yaml
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example
spec:
instances: 3
# dhi.io/postgres uid/gid
postgresUID: 70
postgresGID: 70
imageName: dhi/postgres:18
imagePullSecrets:
- name: helm-pull-secret
storage:
size: 1Gi
To finally apply it to the cluster:
kubectl apply -f postgresql-example.yaml
After a few seconds, you should see the the cluster resource and three replicas ready:
kubectl get clusters.postgresql.cnpg.io
NAME AGE INSTANCES READY STATUS PRIMARY
cluster-example 84s 3 3 Cluster in healthy state cluster-example-1
kubectl get all
NAME READY STATUS RESTARTS AGE
pod/cluster-example-1 1/1 Running 0 60s
pod/cluster-example-2 1/1 Running 0 41s
pod/cluster-example-3 1/1 Running 0 23s
pod/my-cloudnative-pg-5d7f856996-wv4dp 1/1 Running 0 88s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/cluster-example-r ClusterIP 10.43.159.115 <none> 5432/TCP 82s
service/cluster-example-ro ClusterIP 10.43.151.142 <none> 5432/TCP 82s
service/cluster-example-rw ClusterIP 10.43.157.12 <none> 5432/TCP 82s
service/cnpg-webhook-service ClusterIP 10.43.28.246 <none> 443/TCP 88s
service/kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 101s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/my-cloudnative-pg 1/1 1 1 88s
NAME DESIRED CURRENT READY AGE
replicaset.apps/my-cloudnative-pg-5d7f856996 1 1 1 88s