Setting up replication with CloudNativePG
This will probably be one of the simplest recipes in this book, and it is because the automation achieved through the cloud-native operator is such that setting up replication is reduced to increase the value of the integer that describes how many instances you want to deploy in your cluster.
Getting ready
We assume for this recipe that you already have a Kubernetes environment with the CloudNativePG operator, as described in the PostgreSQL in Kubernetes recipe in Chapter 1, First Steps. In that recipe, we wrote our first manifest to deploy a single instance. In this recipe, we will increase the number of instances of the same manifest.
How to do it…
Adding more instances is as simple as editing the number of instances in the spec
section of the manifest file, cluster-example.yaml
. In this case, we will have 3 instances, meaning 1 primary node and 2 replicas:
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata...