What is Longhorn?
Longhorn is a lightweight, distributed block storage system designed for Kubernetes. Created by Rancher Labs, it’s built specifically for cloud-native environments and enables highly available persistent volumes using standard Kubernetes interfaces.
Key Features
- Cloud-native: Designed specifically for Kubernetes.
- Highly Available: Replicates volumes across nodes.
- UI and CLI Tools: Easily manage storage through web interface or CLI.
- Incremental Snapshots and Backups: Built-in support.
- Easy to Deploy and Use: Helm and YAML options available.
Why Use Longhorn?
Kubernetes does not manage storage on its own — it needs a CSI (Container Storage Interface) driver. Longhorn is a popular open-source choice that offers:
- Minimal operational overhead
- High availability with replication
- Easy recovery and backup
- Support for dynamic provisioning of volumes
How to Install Longhorn
Prerequisites
- A running Kubernetes cluster (1.20+)
- Helm 3 installed
- Open TCP ports
9500
,9501
, and3260
on all nodes
Step-by-Step Installation with Helm
helm repo add longhorn https://charts.longhorn.io
helm repo update
kubectl create namespace longhorn-system
helm install longhorn longhorn/longhorn --namespace longhorn-system
Access the Longhorn UI
kubectl port-forward service/longhorn-frontend 8080:80 -n longhorn-system
Then open http://localhost:8080
How to Use Longhorn in Your Apps
- Create a StorageClass (optional):
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: longhorn
provisioner: driver.longhorn.io
reclaimPolicy: Retain
- Create a PersistentVolumeClaim:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: longhorn
resources:
requests:
storage: 2Gi
- Mount in Your Deployment
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: my-pvc
Pros and Cons
✅ Pros
- Easy to set up and use
- Supports UI, CLI, and API
- Incremental backups
- Lightweight and open-source
❌ Cons
- Performance can be lower than native local volumes
- Doesn’t support all CSI features yet
- More components = more points of failure
Conclusion
Longhorn is a powerful and easy-to-use storage solution for Kubernetes, especially for clusters that need persistent volumes with high availability. It’s ideal for DevOps teams looking for a robust, open-source alternative to complex distributed storage systems.