For cnpg postgres cluster, they already did replication, so from the idea in this blog:
I tried multiple ways to create a longhorn sc that :
- 1 replica only, that means one copy only, no need replicate
- need to create with the postgres pod, local, since cnpg created on 3 nodes, means need pv at 3 nodes as well.
But failed with all pv created on same node. here is my yaml:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: longhorn-storageclass-1r
provisioner: driver.longhorn.io
parameters:
numberOfReplicas: "1" # Set to 1 replica
staleReplicaTimeout: "30"
fromBackup: "" # (Optional) Leave blank if not restoring from a backup
allowVolumeExpansion: true
reclaimPolicy: Delete
volumeBindingMode: Immediate
You are mixing up quite a lot of things here:
The storage class is relevant for how longhorn handles its internal replication (think of it like raid storage).
As the postgres setup you talk about is also replicated, you don’t necessarily need the additional replication layer ( if both longhorn and pg have 3 replicas, you would end up using 9 times the data size as storage).
in cnpg (as in any other ha- postgres setup) each pod has it’s own pvc/pv and data is replicated via postgres replication.
Good advice, thanks.
I already know that replicate on both layers not good, so I only let postgres to replicate but want to manage the pv and pvc by Longhorn, as Longhorn can expand the volume, also can show nicely on Longhorn UI. The is why I want to know if only set replica as one , means no need to replicate, can do the job.
Since I got the idea from that blog article , looks like other people already doing that.
The storage class looks perfectly fine. You may need to check the data locality settings you configured (https://documentation.suse.com/cloudnative/storage/1.7.0/en/high-availability/data-locality.html)
Great, let me check on my k8s