Skip to content

Operating Longhorn on a 3-node cluster — replicas, disk failure recovery, S3 backups

Run Longhorn safely on a 3-node Kubernetes cluster — replica scheduling, anti-affinity, disk failure recovery procedure, and S3-backed off-cluster backups.

You run a 3-node Kubernetes cluster with Longhorn as the CSI. It works fine until a node disk fails — and then you discover that two of the three replicas were on the same node because nobody set up node-level anti-affinity, the rebuild storm during recovery doubles the IOPS on the remaining nodes, and the off-cluster backup destination “configured at install time” is pointing at a bucket whose credentials rotated six months ago. Longhorn is excellent storage software with reasonable defaults — and “reasonable defaults” on a 3-node cluster is not the same as “configured correctly for production.” The work is in the operational details that don’t show up until something breaks.

What’s happening

Longhorn replicates volumes across nodes by creating N replica copies (default 3) and synchronously writing to all of them. Each replica is a sparse file on a node’s local disk, managed by a per-node longhorn-manager pod. The longhorn-csi-plugin exposes those replicas to Kubernetes as PVCs. When a replica’s node dies, Longhorn detects the failure, marks the replica as failed, and (if replicaAutoBalance is enabled and another suitable node exists) starts rebuilding a new replica on a healthy node.

The 3-node cluster is the smallest reasonable Longhorn deployment. It is also the most fragile: with numberOfReplicas: 3 and 3 nodes, losing one node means the volume drops to 2 replicas and has nowhere to rebuild. With numberOfReplicas: 2, the storage system tolerates one node failure but reads/writes are degraded until rebuild completes. With numberOfReplicas: 1, you have no replication and the next disk failure is data loss. The right setting is numberOfReplicas: 3 for stateful primaries, with the explicit understanding that the cluster cannot tolerate two simultaneous node failures.

Backups are the second pillar. Longhorn supports backing up volumes to S3-compatible object storage as a separate, off-cluster artifact. A Longhorn backup is not a snapshot — it’s an incremental backup with its own retention policy, and it survives the cluster being destroyed.

How to verify

Cluster-level Longhorn health:

kubectl get nodes.longhorn.io -n longhorn-system
# NAME    READY   ALLOWSCHEDULING   SCHEDULABLE   AGE
# node1   True    true              true          180d
# node2   True    true              true          180d
# node3   True    true              true          180d

kubectl get engineimages.longhorn.io -n longhorn-system
# Should show the engine image as Ready

Per-volume replica placement — the critical 3-node check:

for vol in $(kubectl get volumes.longhorn.io -n longhorn-system -o jsonpath='{.items[*].metadata.name}'); do
  echo "=== ${vol} ==="
  kubectl get replicas.longhorn.io -n longhorn-system \
    -l longhornvolume=${vol} \
    -o jsonpath='{range .items[*]}{.spec.nodeID}{"\t"}{.status.currentState}{"\n"}{end}'
done

If a volume has two replicas on the same node, the cluster is one disk failure away from a degraded volume. That is the bug to fix.

Backup target configuration:

kubectl get -n longhorn-system settings backup-target
kubectl get -n longhorn-system settings backup-target-credential-secret

If the backup target is blank, no backups are happening — verify by listing backups:

kubectl get backups.longhorn.io -n longhorn-system
# No resources found is the symptom

The fix

Three configuration changes, applied in order: enforce replica anti-affinity at the node level, configure the S3 backup target with a tested credential, and schedule recurring backups via RecurringJob. Each step is verified before the next.

1. Replica node-level anti-affinity

The default replicaSoftAntiAffinity setting is true, which means Longhorn will allow two replicas on the same node if no other node has space. Change it to false — better to have a Pending volume than a volume with no node-level diversity:

kubectl -n longhorn-system patch settings.longhorn.io replica-soft-anti-affinity \
  --type=merge -p '{"value":"false"}'

kubectl -n longhorn-system patch settings.longhorn.io replica-zone-soft-anti-affinity \
  --type=merge -p '{"value":"false"}'

kubectl -n longhorn-system patch settings.longhorn.io replica-disk-soft-anti-affinity \
  --type=merge -p '{"value":"false"}'

Enable automatic rebalancing when a node comes back online:

kubectl -n longhorn-system patch settings.longhorn.io replica-auto-balance \
  --type=merge -p '{"value":"best-effort"}'

Apply to existing volumes — the setting above governs new volumes; existing volumes need the per-volume setting updated:

for vol in $(kubectl get volumes.longhorn.io -n longhorn-system -o jsonpath='{.items[*].metadata.name}'); do
  kubectl patch volumes.longhorn.io -n longhorn-system "${vol}" \
    --type=merge -p '{"spec":{"replicaAutoBalance":"best-effort"}}'
done

Now verify that each volume’s replicas are on distinct nodes:

for vol in $(kubectl get volumes.longhorn.io -n longhorn-system -o jsonpath='{.items[*].metadata.name}'); do
  count=$(kubectl get replicas.longhorn.io -n longhorn-system -l longhornvolume=${vol} \
          -o jsonpath='{.items[*].spec.nodeID}' | tr ' ' '\n' | sort -u | wc -l)
  total=$(kubectl get replicas.longhorn.io -n longhorn-system -l longhornvolume=${vol} \
          -o jsonpath='{.items[*].metadata.name}' | wc -w)
  if [ "${count}" -lt "${total}" ]; then
    echo "WARN ${vol}: ${total} replicas on ${count} distinct nodes"
  else
    echo "OK   ${vol}: ${total} replicas on ${count} distinct nodes"
  fi
done

Any WARN line means Longhorn has not yet rebalanced. Trigger a rebuild on the offending volume manually via the Longhorn UI or by deleting the misplaced replica and letting Longhorn create a new one elsewhere.

2. S3-compatible backup target

Create the secret with the S3 credentials. Works for AWS S3, MinIO, Garage, Backblaze B2 (S3-compatible mode), or any other S3-compatible store:

kubectl -n longhorn-system create secret generic backup-target-credential \
  --from-literal=AWS_ACCESS_KEY_ID="CHANGE_ME_KEY" \
  --from-literal=AWS_SECRET_ACCESS_KEY="CHANGE_ME_SECRET" \
  --from-literal=AWS_ENDPOINTS="https://s3.us-east-1.amazonaws.com"  # omit for AWS, set for MinIO/Garage/etc

# Configure the target
kubectl -n longhorn-system patch settings.longhorn.io backup-target \
  --type=merge -p '{"value":"s3://my-longhorn-backups@us-east-1/"}'

kubectl -n longhorn-system patch settings.longhorn.io backup-target-credential-secret \
  --type=merge -p '{"value":"backup-target-credential"}'

Verify the target is reachable:

# Force a backup target sync
kubectl -n longhorn-system patch settings.longhorn.io backupstore-poll-interval \
  --type=merge -p '{"value":"60"}'

# Check for errors in the manager logs
kubectl -n longhorn-system logs -l app=longhorn-manager --tail=50 | grep -i "backup target"

If you see cannot connect to S3 or invalid credentials, fix the secret before continuing. Take a manual test backup of a small volume to confirm end-to-end:

cat <<EOF | kubectl apply -f -
apiVersion: longhorn.io/v1beta2
kind: Backup
metadata:
  name: manual-test-$(date +%s)
  namespace: longhorn-system
  labels:
    backup-volume: <volume-name>
spec:
  snapshotName: <existing-snapshot-name>
  labels:
    purpose: backup-target-test
EOF

kubectl get backups.longhorn.io -n longhorn-system -w
# Wait for state: Completed

3. Recurring backup schedule

Use Longhorn’s RecurringJob CRD for daily backups with a defined retention. Apply per-PVC by labeling the PVC:

---
apiVersion: longhorn.io/v1beta2
kind: RecurringJob
metadata:
  name: daily-backup
  namespace: longhorn-system
spec:
  cron: "0 3 * * *"           # 03:00 UTC daily
  task: backup
  groups:
    - daily-backup
  retain: 14                  # keep 14 daily backups (~2 weeks)
  concurrency: 2
  labels:
    purpose: scheduled
---
apiVersion: longhorn.io/v1beta2
kind: RecurringJob
metadata:
  name: weekly-backup
  namespace: longhorn-system
spec:
  cron: "0 4 * * 0"           # 04:00 UTC every Sunday
  task: backup
  groups:
    - weekly-backup
  retain: 8                   # 8 weeks of retention
  concurrency: 1
  labels:
    purpose: scheduled-weekly

Apply and label the volumes to be included. The label maps to a RecurringJob group:

kubectl apply -f recurring-jobs.yaml

# Pick a volume and opt it into daily + weekly groups
kubectl label volumes.longhorn.io -n longhorn-system <volume-name> \
  recurring-job-group.longhorn.io/daily-backup=enabled \
  recurring-job-group.longhorn.io/weekly-backup=enabled

Disk failure recovery procedure

When a node disk fails, the symptoms are: replicas on that node go to Failed state, volumes report Degraded, and the Longhorn UI shows the node with a red status. The recovery procedure:

# 1. Confirm which node has the failed disk
FAILED_NODE=node2

kubectl get nodes.longhorn.io ${FAILED_NODE} -n longhorn-system -o yaml | \
  yq '.spec.disks, .status.diskStatus'

# 2. Stop scheduling new replicas to the failed node
kubectl -n longhorn-system patch nodes.longhorn.io ${FAILED_NODE} \
  --type=merge -p '{"spec":{"allowScheduling":false}}'

# 3. Find affected volumes (replicas in Failed state on that node)
kubectl get replicas.longhorn.io -n longhorn-system \
  -o jsonpath='{range .items[*]}{.spec.nodeID}{"\t"}{.metadata.labels.longhornvolume}{"\t"}{.status.currentState}{"\n"}{end}' \
  | awk -v n="${FAILED_NODE}" '$1==n && $3=="failed"'

# 4. Delete the failed replicas — Longhorn will rebuild on a healthy node
kubectl get replicas.longhorn.io -n longhorn-system \
  -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.nodeID}{"\t"}{.status.currentState}{"\n"}{end}' \
  | awk -v n="${FAILED_NODE}" '$2==n && $3=="failed" {print $1}' \
  | xargs -r kubectl delete replicas.longhorn.io -n longhorn-system

# 5. Watch rebuilds
kubectl get volumes.longhorn.io -n longhorn-system -w
# Wait for state: Healthy

# 6. Once the disk is replaced and the node is back, re-enable scheduling
kubectl -n longhorn-system patch nodes.longhorn.io ${FAILED_NODE} \
  --type=merge -p '{"spec":{"allowScheduling":true}}'

The rebuild storm: every Failed replica triggers a full re-replication. On a 3-node cluster losing one node, the two surviving nodes do double IOPS for the duration of the rebuild — which for a 500 GiB volume on a 10 Gbps internal network is roughly 8-15 minutes. During the rebuild, application IOPS will tail-spike. Communicate the maintenance window to consumers if the storage backs latency-sensitive workloads.

Operational checklist for a 3-node Longhorn cluster: (1) replica anti-affinity is false (strict), not true (permissive); (2) backup target is configured AND a test backup completes; (3) RecurringJob is in place and a backup has run in the last 24 hours; (4) the cluster is monitored on at least three signals — degraded volumes, failed backups, free space per node disk; (5) a documented disk-failure recovery procedure that an on-call engineer can follow.

Stack Harbor runs production Longhorn under Managed Cloud Ops — replica audits, backup target monitoring, disk-failure runbooks, and quarterly restore drills as part of the standard scope. If you’ve inherited a Longhorn cluster and you’re not sure where the replicas actually live, request a storage health check.