Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

Longhorn: Distributed Storage for Kubernetes

By Kokil Thapa | Last reviewed: September 2026

Stateful workloads on Kubernetes need storage that survives pod rescheduling and node failure. Longhorn: Distributed Storage for Kubernetes fills that gap on bare metal and small clusters. It runs as a CNCF project from Rancher/SUSE and exposes block volumes through the Container Storage Interface (CSI). You get synchronous replication, snapshots, and S3 backups without standing up a full Ceph cluster. If you already manage Kubernetes persistent volumes and storage classes, Longhorn is the next layer: replicated disks on the nodes you already pay for.

What Is Longhorn and How Does Distributed Storage Work on Kubernetes?

Longhorn turns local disk space on Kubernetes worker nodes into replicated block volumes. Each volume is a thin-provisioned replica set managed by a dedicated engine and controller pod. The Longhorn Manager coordinates scheduling, health checks, and rebuilds when a node disappears.

Kubernetes itself only knows about PersistentVolumeClaims (PVCs). Longhorn registers a CSI driver that provisions volumes when a PVC binds to a StorageClass. The kubelet mounts the block device into your pod. From the application side, it behaves like any other persistent disk.

In my experience maintaining production Linux infrastructure, the appeal is operational simplicity. You do not need a separate storage team or dedicated storage servers. Three worker nodes with spare SSD space can host a highly available MySQL or PostgreSQL instance. That trade-off suits teams running K3s at the edge or self-hosted clusters where cloud EBS equivalents are unavailable.

Longhorn ArchitectureKubernetes Control PlaneAPI Server · Scheduler · CSI SidecarsLonghorn ManagerOrchestrates replicasLonghorn UIVolumes · SnapshotsCSI DriverProvision · AttachWorker Node AReplica 1 · EngineWorker Node BReplica 2 · EngineWorker Node CReplica 3 · Engine
Longhorn: Distributed Storage for Kubernetes — manager, CSI driver, and replicated engine pods across worker nodes

Core components you will interact with

  • Longhorn Manager — DaemonSet on every node; handles volume lifecycle and replica placement.
  • Instance Manager — Runs the iSCSI engine process for attached volumes on a node.
  • CSI Plugin — Implements create, attach, detach, expand, and snapshot operations.
  • Longhorn UI — Web dashboard for volume status, node disks, backups, and recurring jobs.

The official project documentation at longhorn.io/docs remains the authoritative reference for version-specific behaviour. Cross-check CSI behaviour against the Kubernetes CSI volume documentation when debugging mount failures.

How Do You Install Longhorn on a Kubernetes Cluster?

Installation takes minutes on a three-node cluster with openiscsi and sufficient disk space. Longhorn ships as a Helm chart or a single manifest bundle. Most production teams use Helm for upgrade control.

Prerequisites on every worker node

  1. Install open-iscsi and ensure the service is running.
  2. Mount a dedicated disk or partition at a path like /var/lib/longhorn.
  3. Open port 9500 for the UI if you expose it through an Ingress.
  4. Confirm your Kubernetes version is supported by the Longhorn release you pick.
# Ubuntu 24.04 worker nodes
sudo apt-get update
sudo apt-get install -y open-iscsi nfs-common
sudo systemctl enable --now iscsid

# Add the Longhorn Helm repo
helm repo add longhorn https://charts.longhorn.io
helm repo update

# Install into dedicated namespace
kubectl create namespace longhorn-system
helm install longhorn longhorn/longhorn \
  --namespace longhorn-system \
  --set defaultSettings.defaultReplicaCount=3

After pods reach Ready state, port-forward the UI for a first look:

kubectl port-forward -n longhorn-system svc/longhorn-frontend 8080:80

On bare-metal clusters I have supported, the first failure is almost always missing open-iscsi. The Longhorn Manager logs show attach errors that look like generic volume mount problems. Fix the host package before chasing Kubernetes RBAC.

For Laravel or PHP workloads moving to containers, pair this storage layer with guidance from Kubernetes for Laravel getting started. Your PVC holds uploaded files, session data, or queue payloads the same way a local disk would on a VM.

How Do You Create and Configure Longhorn Volumes for Production Workloads?

Once installed, define a StorageClass and let applications claim volumes through standard PVC manifests. Longhorn creates a default StorageClass named longhorn unless you disable it at install time.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: longhorn-fast
provisioner: driver.longhorn.io
allowVolumeExpansion: true
reclaimPolicy: Retain
parameters:
  numberOfReplicas: "3"
  staleReplicaTimeout: "2880"
  fsType: "ext4"
  dataLocality: "best-effort"
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-data
  namespace: production
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn-fast
  resources:
    requests:
      storage: 50Gi

Bind that PVC to a StatefulSet or Deployment. ReadWriteOnce is the common mode for databases. Longhorn does not provide ReadWriteMany natively; use NFS or another shared filesystem layer if multiple pods must write concurrently. See NFS as Kubernetes persistent storage for that pattern.

Volume Write ReplicationApp PodWrite I/OLonghorn EngineSynchronous copyReplica Node APrimary copyReplica Node BSync mirrorReplica Node CSync mirrorNode failure triggers rebuildHealthy replica copied to spare node
Synchronous replication in Longhorn: Distributed Storage for Kubernetes — writes fan out before the application receives acknowledgment

Settings that matter in production

  • numberOfReplicas — Use 3 for HA; use 2 only when you accept higher risk on two-node clusters.
  • dataLocality — Set strict-local for latency-sensitive databases on known node pools.
  • reclaimPolicy: Retain — Prevents accidental data loss when someone deletes a PVC.
  • allowVolumeExpansion — Lets you grow disks without rebuilding the volume from scratch.

Track disk consumption early. Longhorn reports per-node usage in the UI. Pair that with cluster-level monitoring from Kubernetes cost monitoring with Kubecost so storage growth does not surprise finance.

How Does Longhorn Compare to OpenEBS, Ceph, and Cloud Block Storage?

Choosing storage is a capacity, ops overhead, and performance decision. Longhorn targets teams that want replicated block storage without Ceph's learning curve. OpenEBS offers multiple engines with different trade-offs. Cloud block storage offloads replication entirely but ties you to a vendor.

CriteriaLonghornOpenEBSCeph RBDCloud Block (EBS/DO Volume)
Ops complexityLow — single Helm install, built-in UIMedium — engine choice mattersHigh — dedicated storage clusterLowest — managed by provider
Minimum viable nodes3 recommended3 for Mayastor replication3 monitors + OSDsN/A — external service
ReplicationSynchronous, configurable replicasDepends on engine (Jiva, cStor, Mayastor)Synchronous across OSDsProvider-managed, zone-aware
Built-in backup UIYes — S3-compatible targetsVaries by engineRBD export + external toolsSnapshots via cloud API
Best fitBare metal, edge, on-prem K8sMixed engine requirementsLarge-scale multi-tenant storageCloud-native production

Deeper comparisons live in dedicated posts on OpenEBS for Kubernetes storage and Ceph storage fundamentals. For Gluster-based approaches, read GlusterFS distributed storage.

Longhorn wins when you run Kubernetes on your own hardware in Nepal or abroad and cloud disks are expensive or unavailable. A three-node VPS cluster at Rs 15,000/month (~USD 110) per node can host both apps and storage. Ceph on the same hardware often needs more RAM and dedicated tuning time.

Storage Choice DecisionNeed persistent K8s storage?Cloud provider?Use managed blockLarge multi-TB fleet?Consider CephSmall bare-metal?Pick LonghornLonghorn selected3 nodes · SSD · open-iscsiValidate with test PVCFail a node · confirm rebuild
When to choose Longhorn: Distributed Storage for Kubernetes over Ceph, OpenEBS, or cloud-managed disks

How Do Snapshots, Backups, and Disaster Recovery Work in Longhorn?

Longhorn distinguishes snapshots from backups. Snapshots are copy-on-write checkpoints stored on the same nodes as the volume. Backups upload snapshot data to external S3-compatible object storage.

Configure a recurring backup job in the UI or through a custom resource. Point it at MinIO, AWS S3, or Backblaze B2. After a total cluster loss, reinstall Longhorn and restore from backup into a fresh PVC.

apiVersion: longhorn.io/v1beta2
kind: RecurringJob
metadata:
  name: nightly-backup
  namespace: longhorn-system
spec:
  cron: "0 2 * * *"
  task: backup
  groups:
    - default
  retain: 7
  concurrency: 2

Combine Longhorn backups with cluster-level tooling from Velero backup and restore for Kubernetes. Velero captures Kubernetes objects and PVC snapshots. Longhorn backups protect the block data even when etcd restore alone is insufficient.

For point-in-time recovery inside the same cluster, use native volume snapshots in Kubernetes. Longhorn implements the VolumeSnapshotClass so CSI snapshots integrate with standard kubectl workflows.

Longhorn Backup PipelineLive VolumeReadWriteOnce PVCSnapshotCoW checkpointBackup JobRecurring cronS3 TargetOff-clusterDisaster recovery path1. Reinstall Longhorn on fresh cluster2. Register same S3 backup target3. Restore volume · reattach workload PVC
Longhorn backup flow — local snapshot to S3-compatible storage for cross-cluster disaster recovery

Test restores quarterly. A backup you have never restored is a guess. On a booking platform like Adventure Third Pole Trek, database downtime during trekking season has real revenue impact. A documented restore runbook beats heroic debugging at 2 AM.

What Production Problems Should You Watch for With Longhorn?

Longhorn is reliable when nodes have clean disk paths and stable networking. Most incidents trace back to configuration gaps rather than software bugs.

Common failure modes and fixes

  • Volume stuck in Attaching — Check open-iscsi on the target node and verify the Instance Manager pod is Running.
  • Degraded replica count — A node drained for maintenance without replica eviction leaves volumes under-replicated. Use Longhorn's node drain policy.
  • Disk pressure — Longhorn schedules new replicas onto nodes with free space. Monitor /var/lib/longhorn usage and add disks before you hit 80%.
  • Network partition — Split-brain is mitigated by quorum logic, but fix flaky VLANs or MTU mismatches first.
  • Slow rebuilds — Rebuilding a 500 GiB volume over 1 Gbps links takes time. Plan maintenance windows accordingly.

When pods enter CrashLoopBackOff after a storage event, follow the diagnostic sequence in debug a CrashLoopBackOff in Kubernetes. The root cause is often a stale mount rather than application code.

Tune worker nodes using guidance from Kubernetes performance tuning and Kubernetes resource limits and requests. Longhorn engine pods consume CPU during rebuilds. Without limits, a rebuild can starve application pods on the same node.

Understand the full PVC lifecycle in Kubernetes persistent volume lifecycle. A Retain policy saves data but orphan PVs accumulate unless you garbage-collect them deliberately.

If your team lacks in-house cluster ops capacity, Linux system administration and support and maintenance services cover storage layer health checks alongside application uptime. For greenfield platforms, enterprise application development can design stateful workloads with the right storage class from day one.

Key Takeaways

  • Longhorn: Distributed Storage for Kubernetes delivers replicated block volumes through CSI on commodity worker nodes—no separate storage cluster required.
  • Install open-iscsi on every node, use three replicas for HA, and set StorageClass reclaimPolicy to Retain for production databases.
  • Configure S3-compatible recurring backups and test restores before you need them during an outage.
  • Choose Longhorn over Ceph for small-to-medium bare-metal clusters; choose cloud block storage when you already run on AWS, GCP, or DigitalOcean.
  • Monitor disk usage on Longhorn data paths and plan rebuild time into node maintenance windows.
  • Pair Longhorn volume backups with Velero for full cluster disaster recovery that includes Kubernetes object state.

People Also Ask

Is Longhorn production-ready for Kubernetes?

Yes. Longhorn is a CNCF incubating project used in production by Rancher customers and self-hosters worldwide. It suits clusters with three or more worker nodes, stable networking, and SSD-backed disks. Very large multi-petabyte deployments typically outgrow it and move to Ceph.

Can Longhorn volumes expand without downtime?

Yes, when the StorageClass sets allowVolumeExpansion: true. Expand the PVC through kubectl or the Longhorn UI. The filesystem inside the pod may need a manual resize with resize2fs or xfs_growfs depending on the fsType you chose at provision time.

Does Longhorn support ReadWriteMany access modes?

Not natively. Longhorn volumes are ReadWriteOnce block devices. For shared file access across multiple pods, front Longhorn with an NFS provisioner or use a dedicated shared filesystem layer documented in the NFS persistent storage guide on this site.

How much CPU and RAM does Longhorn consume?

Idle overhead is modest—roughly 200–400 MB RAM per node for Manager and Instance Manager pods. Rebuild and backup jobs spike CPU and network I/O. Size nodes with headroom beyond application requests so storage maintenance does not trigger eviction storms.

Run Longhorn With Confidence on Your Cluster

Longhorn: Distributed Storage for Kubernetes gives small teams enterprise-style replicated storage without a dedicated storage department. Install it on three nodes, define a StorageClass with three replicas, wire S3 backups, and prove recovery before production traffic depends on it. Validate your YAML manifests with the JSON formatter when converting between API shapes, and review related architecture posts on the blog.

Need help designing a stateful platform or hardening cluster storage? Contact us to discuss your workload, or browse the portfolio for examples of production systems that depend on reliable infrastructure. You can also read more about the author on the about me page or explore the homepage for services that cover the full stack from code to server.

Frequently Asked Questions

Longhorn is a CNCF block storage engine that runs inside your cluster, replicates volumes across worker nodes via CSI, and provides a UI for snapshots, backups, and disaster recovery on bare-metal and edge clusters without cloud block storage.

Install open-iscsi and nfs-common on every worker node, mount disk at a path like /var/lib/longhorn, then deploy via Helm into the longhorn-system namespace with helm install longhorn longhorn/longhorn. Most production teams prefer Helm over the single manifest bundle for upgrade control. After pods reach Ready, port-forward svc/longhorn-frontend on port 8080 to inspect the UI. On bare-metal clusters I have supported, missing open-iscsi causes the first attach failure—fix the host package before chasing Kubernetes RBAC errors in Manager logs.

Each worker needs open-iscsi installed with iscsid running, a dedicated disk or partition mounted at a path such as /var/lib/longhorn, and sufficient free space for replicas. Confirm your Kubernetes version is supported by the Longhorn release you choose. Open port 9500 if you expose the UI through an Ingress. Without open-iscsi, volume attach errors look like generic mount failures in Longhorn Manager logs, wasting hours on the wrong diagnostic path.

Longhorn targets low ops complexity—a single Helm install and built-in UI—on three or more nodes with synchronous replication. OpenEBS offers multiple engines with medium complexity depending on engine choice. Ceph RBD suits large-scale multi-tenant storage but needs dedicated monitors, OSDs, and high ops overhead. Cloud block storage like EBS or DigitalOcean Volumes offloads replication entirely but ties you to a vendor. Longhorn wins on self-hosted bare metal where cloud disks are expensive or unavailable; Ceph wins at very large multi-petabyte scale.

No. Longhorn volumes are ReadWriteOnce block devices. Multiple pods writing concurrently require NFS or another shared filesystem layer fronting block storage.

Use three replicas for high availability. Use two only on two-node clusters when you accept higher failure risk.

Set numberOfReplicas to 3 for HA, dataLocality to strict-local for latency-sensitive databases on known node pools, reclaimPolicy to Retain to prevent accidental data loss when someone deletes a PVC, and allowVolumeExpansion to true so you can grow disks without rebuilding volumes. Track per-node disk consumption early in the Longhorn UI before usage crosses 80% on /var/lib/longhorn paths.

Snapshots are copy-on-write checkpoints stored on the same nodes as the volume. Backups upload snapshot data to external S3-compatible object storage such as MinIO, AWS S3, or Backblaze B2. Configure recurring backup jobs through the UI or a RecurringJob custom resource with a cron schedule and retention count. After total cluster loss, reinstall Longhorn and restore from backup into a fresh PVC. Test restores quarterly—a backup you have never restored is a guess.

Yes, when the StorageClass sets allowVolumeExpansion to true. Expand the PVC through kubectl or the Longhorn UI. The filesystem inside the pod may need a manual resize with resize2fs or xfs_growfs depending on the fsType chosen at provision time, such as ext4.

Yes. Longhorn is a CNCF incubating project used in production by Rancher customers and self-hosters worldwide. It suits clusters with three or more worker nodes, stable networking, and SSD-backed disks. Very large multi-petabyte deployments typically outgrow it and move to Ceph. Pair S3-compatible recurring backups with Velero for full cluster disaster recovery that captures Kubernetes object state alongside block data.

The most common cause is missing or misconfigured open-iscsi on the target node. Verify iscsid is running and check that the Instance Manager pod is in Running state. Attach errors often resemble generic volume mount problems in Manager logs. On bare-metal clusters, fix the host package before investigating Kubernetes RBAC or CSI driver configuration.

Idle overhead is roughly 200–400 MB RAM per node for Manager and Instance Manager pods. Rebuild and backup jobs spike CPU and network I/O significantly.

Choose Longhorn when you run Kubernetes on your own hardware—bare metal, edge, or on-prem—and cloud EBS equivalents are unavailable or expensive. A three-node VPS cluster at Rs 15,000 per month (~USD 110) per node can host both applications and replicated storage on spare SSD space. Choose cloud block storage when you already run on AWS, GCP, or DigitalOcean and want provider-managed, zone-aware replication with the lowest ops burden.

Degraded replica counts often follow node drains without replica eviction—use Longhorn's node drain policy. Disk pressure hits when /var/lib/longhorn exceeds roughly 80% capacity before you add disks. Network partitions on flaky VLANs or MTU mismatches cause instability despite quorum logic. Slow rebuilds on 500 GiB volumes over 1 Gbps links need planned maintenance windows. Without CPU limits on engine pods, rebuilds can starve application pods on the same node.

Retain prevents accidental data loss by keeping the PersistentVolume and underlying Longhorn volume after PVC deletion. The data survives, but orphaned PVs accumulate unless you garbage-collect them deliberately. This is the recommended policy for production databases where accidental kubectl delete commands would otherwise destroy replicated block data permanently.

Share this article

0 Comments

Leave a comment

Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

Quick Contact Options
Choose how you want to connect me: