Auto Balance Replicas

When replicas are scheduled unevenly on nodes or zones, Longhorn Replica Auto Balance setting enables the replicas for automatic balancing when a new node is available to the cluster.

Replica Auto Balance Settings

Global setting

Longhorn supports 3 options for global replica auto-balance setting:

  • disabled. This is the default option, no replica auto-balance will be done.

  • least-effort. This option instructs Longhorn to balance replicas for minimal redundancy. For example, after adding node-2, a volume with 4 off-balanced replicas will only rebalance 1 replica.

    1. node-1
    2. +-- replica-a
    3. +-- replica-b
    4. +-- replica-c
    5. node-2
    6. +-- replica-d
  • best-effort. This option instructs Longhorn to try balancing replicas for even redundancy. For example, after adding node-2, a volume with 4 off-balanced replicas will rebalance 2 replicas.

    1. node-1
    2. +-- replica-a
    3. +-- replica-b
    4. node-2
    5. +-- replica-c
    6. +-- replica-d

    Longhorn does not forcefully re-schedule the replicas to a zone that does not have enough nodes to support even balance. Instead, Longhorn will re-schedule to balance at the node level.

Volume specific setting

Longhorn also supports setting individual volume for Replica Auto Balance. The setting can be specified in volume.spec.replicaAutoBalance, this overrules the global setting.

There are 4 options available for individual volume setting:

  • Ignored. This is the default option that instructs Longhorn to inherit from the global setting.

  • disabled. This option instructs Longhorn no replica auto-balance should be done.

  • least-effort. This option instructs Longhorn to balance replicas for minimal redundancy. For example, after adding node-2, a volume with 4 off-balanced replicas will only rebalance 1 replica.

    1. node-1
    2. +-- replica-a
    3. +-- replica-b
    4. +-- replica-c
    5. node-2
    6. +-- replica-d
  • best-effort. This option instructs Longhorn to try balancing replicas for even redundancy. For example, after adding node-2, a volume with 4 off-balanced replicas will rebalance 2 replicas.

    1. node-1
    2. +-- replica-a
    3. +-- replica-b
    4. node-2
    5. +-- replica-c
    6. +-- replica-d

    Longhorn does not forcefully re-schedule the replicas to a zone that does not have enough nodes to support even balance. Instead, Longhorn will re-schedule to balance at the node level.

How to Set Replica Auto Balance For Volumes

There are 3 ways to set Replica Auto Balance for Longhorn volumes:

Change the global setting

You can change the global default setting for Replica Auto Balance inside Longhorn UI settings. The global setting only functions as a default value, similar to the replica count. It doesn’t change any existing volume settings. When a volume is created without specifying Replica Auto Balance, Longhorn will automatically set to ignored to inherit from the global setting.

Set individual volumes to auto-balance replicas using the Longhorn UI

You can change the Replica Auto Balance setting for individual volume after creation on the volume detail page, or do multiple updates on the listed volume page.

Set individual volumes to auto-balance replicas using a StorageClass

Longhorn also exposes the Replica Auto Balance setting as a parameter in a StorageClass. You can create a StorageClass with a specified Replica Auto Balance setting, then create PVCs using this StorageClass.

For example, the below YAML file defines a StorageClass which tells the Longhorn CSI driver to set the Replica Auto Balance to least-effort:

  1. kind: StorageClass
  2. apiVersion: storage.k8s.io/v1
  3. metadata:
  4. name: hyper-converged
  5. provisioner: driver.longhorn.io
  6. allowVolumeExpansion: true
  7. parameters:
  8. numberOfReplicas: "3"
  9. replicaAutoBalance: "least-effort"
  10. staleReplicaTimeout: "2880" # 48 hours in minutes
  11. fromBackup: ""

© 2019-2023 Longhorn Authors | Documentation Distributed under CC-BY-4.0

© 2023 The Linux Foundation. All rights reserved. The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.

Auto Balance Replicas - 图1 Auto Balance Replicas - 图2 Auto Balance Replicas - 图3 Auto Balance Replicas - 图4 Auto Balance Replicas - 图5