Set Backing Image for Longhorn Volumes
Longhorn natively supports backing images since v1.1.1.
A QCOW2 or RAW image can be set as the backing/base image of a Longhorn volume, which allows Longhorn to be integrated with a VM like Harvester.
There are 3 ways to create a backing image:
You can download a file or export an existing volume as a backing image via YAML. It’s better not to “upload” a file via YAML. Otherwise, you need to manually handle the data upload via HTTP requests.
Here are some examples:
apiVersion: longhorn.io/v1beta1
kind: BackingImage
metadata:
name: bi-download
namespace: longhorn-system
spec:
sourceType: download
sourceParameters:
url: https://longhorn-backing-image.s3-us-west-1.amazonaws.com/parrot.raw
checksum: 304f3ed30ca6878e9056ee6f1b02b328239f0d0c2c1272840998212f9734b196371560b3b939037e4f4c2884ce457c2cbc9f0621f4f5d1ca983983c8cdf8cd9a
apiVersion: longhorn.io/v1beta1
kind: BackingImage
metadata:
name: bi-export
namespace: longhorn-system
spec:
sourceType: export-from-volume
sourceParameters:
volume-name: vol-export-src
export-type: qcow2
backingImageName
means asking Longhorn to use this backing image during volume creation.backingImageDataSourceType
and backingImageDataSourceParameters
should be set as well. Similar to YAML, it’s better not to create a backing image via “upload” in StorageClass.
e.g.:kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: longhorn-backing-image-example
provisioner: driver.longhorn.io
allowVolumeExpansion: true
reclaimPolicy: Delete
volumeBindingMode: Immediate
parameters:
numberOfReplicas: "3"
staleReplicaTimeout: "2880"
backingImage: "bi-download"
backingImageDataSourceType: "download"
backingImageDataSourceParameters: '{"url": "https://backing-image-example.s3-region.amazonaws.com/test-backing-image"}'
backingImageChecksum: "SHA512 checksum of the backing image"
If all of these parameters are set and the backing image already exists, Longhorn will validate if the parameters matches the existing one before using it.
Backup
and pick up a backup volume for the restore.\
when you input a download URL in a StorageClass.Backing Image Cleanup Wait Interval
. But Longhorn will retain at least one file in a disk for each backing image anyway.<Backing image name>-<first 8 characters of the disk UUID>
handling the actual file for each backing image in each disk.failed
.running
until the pod becomes running
again.In brief, Longhorn will automatically recover the backing images after the node is back, users don’t need to worry about it.
The download URL of the backing image should be public. We will improve this part in the further.
© 2019-2024 Longhorn Authors | Documentation Distributed under CC-BY-4.0
© 2024 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.