Introduction
Longhorn is a CNCF project providing distributed block storage for Kubernetes. It aggregates local storage from your cluster nodes and presents it as persistent, replicated volumes for stateful applications. Key features include snapshots, backups (to S3/NFS), and an intuitive UI.
Best Practices & Configuration
Disk Allocation
- Dedicated Disks: It is recommended to use a dedicated disk. If you do, you can lower the
minimal available storage percentagesetting to10%. - Root Disks: If using the root disk, set the
minimal available storage percentageto25%and theoverprovisioning percentageto100%to minimize the chance ofDiskPressure.
PostgreSQL (CloudNativePG) Integration
- For
cloudnative-pgdeployments,strict-localis the recommended option for data-locality. More details can be found here. - You should define a
StorageClassspecifically tailored for PostgreSQL purposes.
Example PostgreSQL StorageClass
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: hyper-converged
provisioner: driver.longhorn.io
allowVolumeExpansion: true
parameters:
numberOfReplicas: "1"
dataLocality: "strict-local"
staleReplicaTimeout: "120" # 2 hours in minutes
fsType: "ext4"
fromBackup: ""
dataEngine: "v1"
Snapshots vs. Backups
It's crucial to understand the difference between snapshots and backups:
-
Snapshot: A point-in-time, read-only image of a volume's data.
- It is stored locally alongside the volume's replicas inside your cluster.
- Snapshots are fast to create and useful for quick rollbacks.
- Note: Removing the original PVC will also remove the snapshot by default unless you change the
ReclaimPolicyof your storage class toRetain.
-
Backup: A copy of a snapshot's data.
- It is stored externally in a remote location (your Backup Target, like S3 or NFS).
- Backups are meant for disaster recovery and are safe even if your entire cluster fails.