What is Longhorn?
Longhorn is a lightweight, reliable, and powerful distributed block storage system for Kubernetes. Created by Rancher Labs (now part of SUSE), it provides:- Persistent storage for your applications
- Built-in backup and restore capabilities
- Volume replication across nodes for high availability
- Snapshots for point-in-time recovery
- User-friendly web UI for management
- Disaster recovery with cross-cluster replication
Prerequisites
Before installing Longhorn, you need to:- Have a running Talos Kubernetes cluster (see the deployment guide)
- Rebuild your Talos nodes with required system extensions
- Have
kubectlconfigured to access your cluster
Required Extensions
You need two system extensions:-
siderolabs/iscsi-tools: Provides iSCSI (Internet Small Computer Systems Interface) support- iSCSI allows Longhorn to attach block storage volumes to pods
- This is how Kubernetes mounts persistent volumes to containers
-
siderolabs/util-linux-tools: Provides essential Linux utilities- Contains tools like
nsenter,lsblk, andfindmnt - Required for volume mounting and filesystem operations
- Contains tools like
Configure Namespace Security
Longhorn requires privileged access to manage storage at the system level. We need to configure the namespace with appropriate Pod Security Standards. What are Pod Security Standards? Kubernetes Pod Security Standards define three policies:- Privileged: Unrestricted policy (required for system-level operations)
- Baseline: Minimally restrictive policy
- Restricted: Heavily restricted policy (most secure)
- Manages block devices and filesystems
- Mounts volumes to nodes
- Performs low-level storage operations
- Interacts directly with the kernel
- enforce=privileged: Pods violating this policy will be rejected
- audit=privileged: Policy violations are logged to the audit log
- warn=privileged: Users receive warnings for policy violations
- version=latest: Use the latest version of the policy standard
Add Longhorn Helm Repository
Longhorn is distributed via Helm charts, which are packages for Kubernetes applications.Install Longhorn
Now we’ll install Longhorn with configuration optimized for a 2-worker-node cluster. Install command:persistence.defaultClassReplicaCount=2
- Sets the default number of replicas for the default StorageClass
- Replication means each volume is copied to multiple nodes
- With 2 replicas across 2 worker nodes:
- Your data exists on both workers
- If one worker fails, data remains accessible
- Provides high availability for your volumes
- Default is 3, but we only have 2 worker nodes
defaultSettings.defaultReplicaCount=2
- Sets the global default for all Longhorn volumes
- Ensures any volume created gets 2 replicas by default
- Applies to all StorageClasses, not just the default one
- 1 replica: No redundancy—if that node fails, data is lost
- 2 replicas: Can tolerate 1 node failure
- 3 replicas: Can tolerate 2 node failures (requires 3+ nodes)
- Create CustomResourceDefinitions (CRDs) for Longhorn objects
- Deploy the Longhorn manager (control plane)
- Deploy Longhorn engine (data plane)
- Create DaemonSets to run storage agents on each node
- Set up the Longhorn UI
- Create the default StorageClass
Step 5: Verify Installation
Check pod status:Running):
longhorn in your pvcs and it will schedule 2 replicas per volume
You now have production-ready persistent storage in your Kubernetes cluster! 🎉