Harvester replicates volumes data across disks in a cluster. Before removing a disk, the user needs to evict replicas on the disk to other disks to preserve the volumes' configured availability. For more information about eviction in Longhorn, please check Evicting Replicas on Disabled Disks or Nodes.
Preparation
This document describes how to evict Longhorn disks using the kubectl command. Before that, users must ensure the environment is set up correctly.
There are two recommended ways to do this:
- Log in to any management node and switch to root (
sudo -i). - Download Kubeconfig file and use it locally
- Install
kubectlandyqprogram manually. - Open Harvester GUI, click
supportat the bottom left of the page and clickDownload KubeConfigto download the Kubeconfig file. - Set the Kubeconfig file's path to
KUBECONFIGenvironment variable. For example,export KUBECONFIG=/path/to/kubeconfig.
- Install
Evicting replicas from a disk
List Longhorn nodes (names are identical to Kubernetes nodes):
kubectl get -n longhorn-system nodes.longhorn.ioSample output:
NAME READY ALLOWSCHEDULING SCHEDULABLE AGE
node1 True true True 24d
node2 True true True 24d
node3 True true True 24dList disks on a node. Assume we want to evict replicas of a disk on
node1:kubectl get -n longhorn-system nodes.longhorn.io node1 -o yaml | yq e '.spec.disks'Sample output:
default-disk-ed7af10f5b8356be:
allowScheduling: true
evictionRequested: false
path: /var/lib/harvester/defaultdisk
storageReserved: 36900254515
tags: []Assume disk
default-disk-ed7af10f5b8356beis the target we want to evict replicas out of.Edit the node:
kubectl edit -n longhorn-system nodes.longhorn.io node1Update these two fields and save:
spec.disks.<disk_name>.allowSchedulingtofalsespec.disks.<disk_name>.evictionRequestedtotrue
Sample editing:
default-disk-ed7af10f5b8356be:
allowScheduling: false
evictionRequested: true
path: /var/lib/harvester/defaultdisk
storageReserved: 36900254515
tags: []Wait for all replicas on the disk to be evicted.
Get current scheduled replicas on the disk:
kubectl get -n longhorn-system nodes.longhorn.io node1 -o yaml | yq e '.status.diskStatus.default-disk-ed7af10f5b8356be.scheduledReplica'Sample output:
pvc-86d3d212-d674-4c64-b69b-4a2eb1df2272-r-7b422db7: 5368709120
pvc-b06f0b09-f30c-4936-8a2a-425b993dd6cb-r-bb0fa6b3: 2147483648
pvc-b844bcc6-3b06-4367-a136-3909251cb560-r-08d1ab3c: 53687091200
pvc-ea6e0dff-f446-4a38-916a-b3bea522f51c-r-193ca5c6: 10737418240Run the command repeatedly, and the output should eventually become an empty map:
{}This means Longhorn evicts replicas on the disk to other disks.
note
If a replica always stays in a disk, please open the Longhorn GUI and check if there is free space on other disks.
