How to create a Longhorn StorageClass for cnpg

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.