0b
cypress
+
hugging
vault
ada
+
+
symfony
+
+
+
+
objc
+
vite
+
+
+
bbedit
+
hapi
+
fedora
+
react
+=
+
bbedit
strapi
+
+
+
backbone
+
oauth
puppet
matplotlib
+
+
+
rest
+
sql
swift
+
haskell
+
+
+
soap
+
+
express
+
ada
dns
+
+
elasticsearch
sql
+
+
+
+
+
+
c
mvn
py
+
mocha
tf
vscode
+
koa
+
--
+
mocha
+
cobol
+
+
html
neo4j
+
clion
+
+
Back to Blog
๐Ÿ’พ Longhorn Distributed Storage on AlmaLinux 9: Complete Guide
almalinux longhorn kubernetes

๐Ÿ’พ Longhorn Distributed Storage on AlmaLinux 9: Complete Guide

Published Sep 6, 2025

Build resilient Kubernetes storage with Longhorn on AlmaLinux 9! Learn distributed block storage, automatic backups, disaster recovery, and volume management with practical examples.

5 min read
0 views
Table of Contents

๐Ÿ’พ Longhorn Distributed Storage on AlmaLinux 9: Complete Guide

Ready to revolutionize your Kubernetes storage? ๐Ÿš€ Today weโ€™ll set up Longhorn on AlmaLinux 9, creating bulletproof distributed storage that never loses data! Letโ€™s build something amazing! โœจ๐Ÿ’ช

๐Ÿค” Why is Longhorn Important?

Imagine storage that heals itself and never fails! ๐ŸŽฏ Thatโ€™s Longhornโ€™s superpower! Hereโ€™s why itโ€™s game-changing:

  • ๐Ÿ”„ Self-Healing Storage - Automatically recovers from node failures!
  • ๐Ÿ“ฆ Distributed Replicas - Your data lives on multiple nodes safely
  • ๐Ÿ›ก๏ธ Automatic Backups - Schedule backups to S3 or NFS automatically
  • ๐Ÿ“ธ Instant Snapshots - Create point-in-time copies instantly
  • ๐ŸŽจ Beautiful UI - Manage everything through an intuitive dashboard
  • ๐Ÿš€ Zero Downtime Upgrades - Upgrade storage without stopping apps
  • ๐ŸŒ Disaster Recovery - Restore data across clusters easily
  • ๐Ÿ’ก Simple Management - No PhD required to manage storage!

๐ŸŽฏ What You Need

Before we start this storage adventure, gather these:

  • โœ… AlmaLinux 9 server (8GB RAM minimum, 16GB recommended)
  • โœ… Kubernetes cluster running (K3s or K8s)
  • โœ… At least 3 nodes for production (1 for testing)
  • โœ… 50GB+ free disk space per node
  • โœ… kubectl configured and working
  • โœ… iSCSI client installed
  • โœ… Open ports 9500-9504
  • โœ… Excitement for bulletproof storage! ๐ŸŽ‰

๐Ÿ“ Step 1: Prepare AlmaLinux for Longhorn

Letโ€™s prepare your system for distributed storage! ๐Ÿ› ๏ธ

Install Required Packages

# Update system packages
sudo dnf update -y  # Get latest updates

# Install iSCSI initiator (required for Longhorn)
sudo dnf install -y iscsi-initiator-utils

# Install NFS utilities (for backup support)
sudo dnf install -y nfs-utils

# Install other dependencies
sudo dnf install -y util-linux e2fsprogs xfsprogs

# Enable and start iSCSI service
sudo systemctl enable --now iscsid

# Verify iSCSI is running
sudo systemctl status iscsid  # Should show active

Configure Kernel Modules

# Load required kernel modules
sudo modprobe iscsi_tcp
sudo modprobe dm_snapshot
sudo modprobe dm_thin_pool

# Make modules persistent
cat <<EOF | sudo tee /etc/modules-load.d/longhorn.conf
iscsi_tcp
dm_snapshot
dm_thin_pool
EOF

# Verify modules are loaded
lsmod | grep iscsi  # Should show iscsi_tcp

Create Longhorn Data Directory

# Create dedicated partition mount point
sudo mkdir -p /var/lib/longhorn

# If you have a dedicated disk (recommended)
# Replace /dev/sdb with your disk
sudo mkfs.ext4 /dev/sdb  # Format disk
sudo mount /dev/sdb /var/lib/longhorn  # Mount it

# Add to /etc/fstab for persistent mount
echo "/dev/sdb /var/lib/longhorn ext4 defaults 0 0" | sudo tee -a /etc/fstab

# Set permissions
sudo chmod 755 /var/lib/longhorn

# Verify mount
df -h /var/lib/longhorn  # Should show your disk

๐Ÿ”ง Step 2: Check Environment Compatibility

Letโ€™s verify everything is ready! ๐Ÿ”

Run Longhorn Environment Check

# Download and run environment check script
curl -sSfL https://raw.githubusercontent.com/longhorn/longhorn/v1.6.0/scripts/environment_check.sh | bash

# You should see all checks passing!
# If any fail, fix them before continuing

Check Kubernetes Cluster

# Verify nodes are ready
kubectl get nodes  # All should be Ready

# Check available storage on nodes
kubectl get nodes -o json | jq '.items[].status.allocatable.storage'

# Verify default storage class
kubectl get storageclass  # Note current default

๐ŸŒŸ Step 3: Install Longhorn

Time to install the magic! ๐ŸŽŠ Choose your favorite method!

Method 1: Install with kubectl (Simple)

# Install Longhorn with single command!
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v1.6.0/deploy/longhorn.yaml

# Watch the installation progress
kubectl get pods -n longhorn-system -w  # Ctrl+C when all Running

# This creates namespace and all resources
kubectl get all -n longhorn-system  # See everything!

Method 2: Install with Helm (Flexible)

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

# Install Longhorn with custom values
cat <<EOF > longhorn-values.yaml
persistence:
  defaultClass: true
  defaultClassReplicaCount: 3
  reclaimPolicy: Retain
defaultSettings:
  defaultDataPath: /var/lib/longhorn
  replicaSoftAntiAffinity: true
  storageMinimalAvailablePercentage: 10
  upgradeChecker: true
  defaultReplicaCount: 3
  backupTarget: s3://your-bucket@us-east-1/longhorn-backups
  backupTargetCredentialSecret: backup-secret
ingress:
  enabled: true
  host: longhorn.yourdomain.com
  tls: true
EOF

# Install with Helm
helm install longhorn longhorn/longhorn \
  --namespace longhorn-system \
  --create-namespace \
  --values longhorn-values.yaml

# Check installation
helm list -n longhorn-system

Verify Installation

# Check all pods are running
kubectl get pods -n longhorn-system

# Check Longhorn components
kubectl get daemonset -n longhorn-system  # Should show nodes
kubectl get deployment -n longhorn-system  # Should be ready
kubectl get service -n longhorn-system  # Should show services

โœ… Step 4: Access Longhorn UI

Letโ€™s explore the beautiful dashboard! ๐ŸŽจ

Method 1: Port Forwarding

# Forward Longhorn UI port
kubectl port-forward -n longhorn-system svc/longhorn-frontend 8080:80 &

# Access UI at http://localhost:8080
echo "๐ŸŽ‰ Longhorn UI is ready at http://localhost:8080"

Method 2: NodePort Service

# Create NodePort for external access
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
  name: longhorn-frontend-nodeport
  namespace: longhorn-system
spec:
  type: NodePort
  selector:
    app: longhorn-ui
  ports:
  - port: 80
    targetPort: 8000
    nodePort: 30080
EOF

# Access at http://YOUR_NODE_IP:30080

Method 3: Ingress (Production)

# Create Ingress for Longhorn UI
cat <<EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: longhorn-ingress
  namespace: longhorn-system
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - host: longhorn.yourdomain.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: longhorn-frontend
            port:
              number: 80
EOF

# Access at http://longhorn.yourdomain.com

๐ŸŽฎ Quick Examples

Letโ€™s create some persistent storage! ๐Ÿš€

Example 1: Create Your First Volume

# Create a PersistentVolumeClaim
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-first-longhorn-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 5Gi
EOF

# Check PVC status
kubectl get pvc my-first-longhorn-pvc  # Should be Bound

# See the volume in Longhorn UI!

Example 2: Deploy Application with Persistent Storage

# Deploy PostgreSQL with Longhorn storage
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 10Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:15
        env:
        - name: POSTGRES_PASSWORD
          value: "mysecretpassword"
        - name: PGDATA
          value: /var/lib/postgresql/data/pgdata
        ports:
        - containerPort: 5432
        volumeMounts:
        - name: postgres-storage
          mountPath: /var/lib/postgresql/data
      volumes:
      - name: postgres-storage
        persistentVolumeClaim:
          claimName: postgres-pvc
EOF

# Check deployment
kubectl get pods | grep postgres  # Should be Running
kubectl exec -it deploy/postgres -- df -h  # See mounted volume!

Example 3: Create Snapshot and Backup

# Create a snapshot using kubectl
cat <<EOF | kubectl apply -f -
apiVersion: longhorn.io/v1beta2
kind: Snapshot
metadata:
  name: postgres-snapshot-1
  namespace: longhorn-system
spec:
  volume: pvc-xxxxx  # Replace with your volume name
EOF

# Configure S3 backup target
kubectl create secret generic backup-secret \
  -n longhorn-system \
  --from-literal=AWS_ACCESS_KEY_ID=your-key \
  --from-literal=AWS_SECRET_ACCESS_KEY=your-secret

# Create backup from UI or CLI
# The backup will be stored in S3!

๐Ÿšจ Fix Common Problems

Donโ€™t panic! Here are solutions! ๐Ÿ’ช

Problem 1: Pods Stuck in Pending

# Check PVC status
kubectl describe pvc <pvc-name>

# Check Longhorn nodes
kubectl get nodes.longhorn.io -n longhorn-system

# Check available disk space
kubectl get nodes.longhorn.io -n longhorn-system -o yaml | grep -A5 disk

# Fix: Add more disk space or adjust settings
kubectl edit settings.longhorn.io -n longhorn-system
# Change storageMinimalAvailablePercentage to 5

Problem 2: Volume Attachment Failed

# Check volume status
kubectl get volumes.longhorn.io -n longhorn-system

# Check engine and replica
kubectl get engines.longhorn.io -n longhorn-system
kubectl get replicas.longhorn.io -n longhorn-system

# Force detach and reattach
kubectl delete volumeattachment <attachment-name>

# Restart Longhorn manager
kubectl rollout restart deployment/longhorn-manager -n longhorn-system

Problem 3: Backup Not Working

# Check backup target settings
kubectl get settings.longhorn.io backup-target -n longhorn-system -o yaml

# Verify credentials
kubectl get secret backup-secret -n longhorn-system -o yaml

# Test S3 connection manually
aws s3 ls s3://your-bucket/longhorn-backups/ --endpoint-url=https://s3.amazonaws.com

# Check backup jobs
kubectl get backups.longhorn.io -n longhorn-system

๐Ÿ“‹ Simple Commands Summary

Your Longhorn command toolkit! ๐Ÿ“š

CommandWhat It DoesWhen to Use
kubectl apply -f longhorn.yamlInstall LonghornInitial setup
kubectl get pvcList volume claimsCheck storage
kubectl get volumes.longhorn.io -n longhorn-systemList Longhorn volumesVolume management
kubectl port-forward svc/longhorn-frontendAccess UIView dashboard
kubectl create pvcCreate new volumeNeed storage
kubectl get nodes.longhorn.io -n longhorn-systemCheck node statusTroubleshooting
kubectl logs -n longhorn-system -l app=longhorn-managerView manager logsDebug issues
kubectl edit settings.longhorn.io -n longhorn-systemChange settingsConfiguration
kubectl get snapshots.longhorn.io -n longhorn-systemList snapshotsBackup check
kubectl scale deployment <app> --replicas=0Stop appMaintenance

๐Ÿ’ก Tips for Success

Become a storage expert with these tips! ๐Ÿ†

Storage Best Practices

  • ๐Ÿ”ข Use 3 replicas for production data
  • ๐Ÿ’พ Keep 20% disk space free for operations
  • ๐Ÿ“ธ Schedule daily snapshots for important data
  • ๐ŸŒ Configure S3 backups for disaster recovery
  • ๐Ÿ”„ Test restore procedures regularly

Performance Optimization

  • โšก Use SSDs for better performance
  • ๐ŸŽฏ Set node affinity for critical workloads
  • ๐Ÿ“Š Monitor disk I/O with Longhorn UI
  • ๐Ÿš€ Adjust replica counts based on importance
  • ๐Ÿ’ก Use separate disks for OS and Longhorn

Monitoring Tips

  • ๐Ÿ“ˆ Watch volume health in UI dashboard
  • ๐Ÿ” Set up alerts for low disk space
  • ๐Ÿ“Š Monitor replica rebuild progress
  • โš ๏ธ Check for degraded volumes daily
  • ๐Ÿ“ Keep backup logs for audit

๐Ÿ† What You Learned

Amazing job! Youโ€™re now a storage wizard! ๐ŸŽ‰ You can:

  • โœ… Install Longhorn on AlmaLinux 9
  • โœ… Create persistent volumes for applications
  • โœ… Access and navigate Longhorn UI
  • โœ… Deploy applications with distributed storage
  • โœ… Create snapshots and backups
  • โœ… Troubleshoot common storage issues
  • โœ… Configure disaster recovery
  • โœ… Optimize storage performance

๐ŸŽฏ Why This Matters

Youโ€™ve just built enterprise-grade storage! ๐Ÿš€ With Longhorn:

  • No More Data Loss - Multiple replicas protect your data
  • Automatic Recovery - Self-healing from node failures
  • Easy Backups - Automated backups to cloud storage
  • Simple Management - Beautiful UI for all operations
  • Cost Effective - Use commodity hardware for enterprise storage
  • Cloud Native - Perfect for Kubernetes workloads
  • Peace of Mind - Your data is always safe and available

Your Kubernetes cluster now has bulletproof storage that rivals expensive SAN solutions! Data persistence is no longer a worry - Longhorn handles everything automatically.

Keep exploring advanced features like recurring backups, disaster recovery volumes, and storage network isolation. Your storage game is now top-tier! ๐ŸŒŸ

Remember: Your data is your treasure - Longhorn is your vault! Happy storing! ๐ŸŽŠ๐Ÿ’พ


P.S. - Explore Longhornโ€™s advanced features like encryption, RAID configurations, and multi-cluster replication. Join the community and share your storage success stories! โญ๐Ÿ™Œ