Create a Volume

Create an Empty Volume

  • UI
  • API
  • Terraform

Header Section

  1. Set the Volume Name.
  2. (Optional) Provide a Description for the Volume.

Basics Tab

  1. Choose New in Source.
  2. Select an existing StorageClass.
  3. Configure the Size of the volume.

create-empty-volume

  1. apiVersion: v1
  2. kind: PersistentVolumeClaim
  3. metadata:
  4. annotations:
  5. volume.beta.kubernetes.io/storage-provisioner: driver.longhorn.io
  6. volume.kubernetes.io/storage-provisioner: driver.longhorn.io
  7. name: my-vol
  8. namespace: default
  9. spec:
  10. accessModes:
  11. - ReadWriteMany
  12. resources:
  13. requests:
  14. storage: 10Gi
  15. volumeMode: Block
  16. volumeName: pvc-my-vol

To create an empty volume on Harvester with Terraform using the Harvester Terraform Provider, define a harvester_volume resource block:

  1. resource "harvester_volume" "empty-volume" {
  2. name = "empty-volume"
  3. namespace = "default"
  4. size = "10Gi"
  5. }

Create an Image Volume

  • UI
  • API
  • Terraform

Header Section

  1. Set the Volume Name.
  2. (Optional) Provide a Description for the Volume.

Basics Tab

  1. Choose VM Image in Source.
  2. Select an existing Image.
  3. Configure the Size of the volume.

Create a Volume - 图2important

When creating volumes from a VM image, ensure that the volume size is greater than or equal to the image size. The volume may become corrupted if the configured volume size is less than the size of the underlying image. This is particularly important for qcow2 images because the virtual size is typically greater than the physical size.

By default, Harvester will set the volume size to the virtual size of the image.

create-image-volume

Create a volume, initialized with the contents of the image image-8rb2z from the namespace default:

  1. apiVersion: v1
  2. kind: PersistentVolumeClaim
  3. metadata:
  4. annotations:
  5. harvesterhci.io/imageId: default/image-8rb2z
  6. volume.beta.kubernetes.io/storage-provisioner: driver.longhorn.io
  7. volume.kubernetes.io/storage-provisioner: driver.longhorn.io
  8. name: foobar
  9. namespace: default
  10. spec:
  11. accessModes:
  12. - ReadWriteMany
  13. resources:
  14. requests:
  15. storage: 5Gi
  16. storageClassName: longhorn-image-8rb2z
  17. volumeMode: Block
  18. volumeName: pvc-foobar

To create a volume on Harvester using Terraform and initialize it with the contents of an image, define a harvester_volume resource block and set the image property:

  1. resource "harvester_volume" "opensuse154-image-disk" {
  2. name = "opensuse154-image-disk"
  3. namespace = "default"
  4. size = "10Gi"
  5. image = harvester_image.opensuse154.id
  6. }