Creating data volumes
You can create a data volume by using either the PVC or storage API.
When using OKD Virtualization with OKD Container Storage, specify RBD block mode persistent volume claims (PVCs) when creating virtual machine disks. With virtual machine disks, RBD block mode volumes are more efficient and provide better performance than Ceph FS or RBD filesystem-mode PVCs. To specify RBD block mode PVCs, use the ‘ocs-storagecluster-ceph-rbd’ storage class and |
Whenever possible, use the storage API to optimize space allocation and maximize performance. |
A storage profile is a custom resource that the CDI manages. It provides recommended storage settings based on the associated storage class. A storage profile is allocated for each storage class.
Storage profiles enable you to create data volumes quickly while reducing coding and minimizing potential errors.
For recognized storage types, the CDI provides values that optimize the creation of PVCs. However, you can configure automatic settings for a storage class if you customize the storage profile.
About data volumes
DataVolume
objects are custom resources that are provided by the Containerized Data Importer (CDI) project. Data volumes orchestrate import, clone, and upload operations that are associated with an underlying persistent volume claim (PVC). You can create a data volume as either a standalone resource or by using the dataVolumeTemplate
field in the virtual machine (VM) specification.
|
After a PVC is populated, the data volume that you used to create the PVC is no longer needed. OKD Virtualization enables automatic garbage collection of completed data volumes by default. Standalone data volumes, and data volumes created by using the dataVolumeTemplate
resource, are automatically garbage collected after completion.
Creating data volumes using the storage API
When you create a data volume using the storage API, the Containerized Data Interface (CDI) optimizes your persistent volume claim (PVC) allocation based on the type of storage supported by your selected storage class. You only have to specify the data volume name, namespace, and the amount of storage that you want to allocate.
For example:
When using Ceph RBD,
accessModes
is automatically set toReadWriteMany
, which enables live migration.volumeMode
is set toBlock
to maximize performance.When you are using
volumeMode: Filesystem
, more space will automatically be requested by the CDI, if required to accommodate file system overhead.
In the following YAML, using the storage API requests a data volume with two gigabytes of usable space. The user does not need to know the volumeMode
in order to correctly estimate the required persistent volume claim (PVC) size. The CDI chooses the optimal combination of accessModes
and volumeMode
attributes automatically. These optimal values are based on the type of storage or the defaults that you define in your storage profile. If you want to provide custom values, they override the system-calculated values.
Example DataVolume definition
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataVolume
metadata:
name: <datavolume> (1)
spec:
source:
pvc: (2)
namespace: "<source_namespace>" (3)
name: "<my_vm_disk>" (4)
storage: (5)
resources:
requests:
storage: 2Gi (6)
storageClassName: <storage_class> (7)
1 | The name of the new data volume. |
2 | Indicate that the source of the import is an existing persistent volume claim (PVC). |
3 | The namespace where the source PVC exists. |
4 | The name of the source PVC. |
5 | Indicates allocation using the storage API. |
6 | Specifies the amount of available space that you request for the PVC. |
7 | Optional: The name of the storage class. If the storage class is not specified, the system default storage class is used. |
Creating data volumes using the PVC API
When you create a data volume using the PVC API, the Containerized Data Interface (CDI) creates the data volume based on what you specify for the following fields:
accessModes
(ReadWriteOnce
,ReadWriteMany
, orReadOnlyMany
)volumeMode
(Filesystem
orBlock
)capacity
ofstorage
(5Gi
, for example)
In the following YAML, using the PVC API allocates a data volume with a storage capacity of two gigabytes. You specify an access mode of ReadWriteMany
to enable live migration. Because you know the values your system can support, you specify Block
storage instead of the default, Filesystem
.
Example DataVolume definition
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataVolume
metadata:
name: <datavolume> (1)
spec:
source:
pvc: (2)
namespace: "<source_namespace>" (3)
name: "<my_vm_disk>" (4)
pvc: (5)
accessModes: (6)
- ReadWriteMany
resources:
requests:
storage: 2Gi (7)
volumeMode: Block (8)
storageClassName: <storage_class> (9)
1 | The name of the new data volume. |
2 | In the source section, pvc indicates that the source of the import is an existing persistent volume claim (PVC). |
3 | The namespace where the source PVC exists. |
4 | The name of the source PVC. |
5 | Indicates allocation using the PVC API. |
6 | accessModes is required when using the PVC API. |
7 | Specifies the amount of space you are requesting for your data volume. |
8 | Specifies that the destination is a block PVC. |
9 | Optionally, specify the storage class. If the storage class is not specified, the system default storage class is used. |
When you explicitly allocate a data volume by using the PVC API and you are not using File system overhead is the amount of space required by the file system to maintain its metadata. The amount of space required for file system metadata is file system dependent. Failing to account for file system overhead in your storage capacity request can result in an underlying persistent volume claim (PVC) that is not large enough to accommodate your virtual machine disk. If you use the storage API, the CDI will factor in file system overhead and request a larger persistent volume claim (PVC) to ensure that your allocation request is successful. |
Customizing the storage profile
You can specify default parameters by editing the StorageProfile
object for the provisioner’s storage class. These default parameters only apply to the persistent volume claim (PVC) if they are not configured in the DataVolume
object.
An empty status
section in a storage profile indicates that a storage provisioner is not recognized by the Containerized Data Interface (CDI). Customizing a storage profile is necessary if you have a storage provisioner that is not recognized by the CDI. In this case, the administrator sets appropriate values in the storage profile to ensure successful allocations.
If you create a data volume and omit YAML attributes and these attributes are not defined in the storage profile, then the requested storage will not be allocated and the underlying persistent volume claim (PVC) will not be created. |
Prerequisites
- Ensure that your planned configuration is supported by the storage class and its provider. Specifying an incompatible configuration in a storage profile causes volume provisioning to fail.
Procedure
Edit the storage profile. In this example, the provisioner is not recognized by CDI:
$ oc edit -n openshift-cnv storageprofile <storage_class>
Example storage profile
apiVersion: cdi.kubevirt.io/v1beta1
kind: StorageProfile
metadata:
name: <unknown_provisioner_class>
# ...
spec: {}
status:
provisioner: <unknown_provisioner>
storageClass: <unknown_provisioner_class>
Provide the needed attribute values in the storage profile:
Example storage profile
apiVersion: cdi.kubevirt.io/v1beta1
kind: StorageProfile
metadata:
name: <unknown_provisioner_class>
# ...
spec:
claimPropertySets:
- accessModes:
- ReadWriteOnce (1)
volumeMode:
Filesystem (2)
status:
provisioner: <unknown_provisioner>
storageClass: <unknown_provisioner_class>
1 The accessModes
that you select.2 The volumeMode
that you select.After you save your changes, the selected values appear in the storage profile
status
element.
Setting a default cloning strategy using a storage profile
You can use storage profiles to set a default cloning method for a storage class, creating a cloning strategy. Setting cloning strategies can be helpful, for example, if your storage vendor only supports certain cloning methods. It also allows you to select a method that limits resource usage or maximizes performance.
Cloning strategies can be specified by setting the cloneStrategy
attribute in a storage profile to one of these values:
snapshot
is used by default when snapshots are configured. This cloning strategy uses a temporary volume snapshot to clone the volume. The storage provisioner must support Container Storage Interface (CSI) snapshots.copy
uses a source pod and a target pod to copy data from the source volume to the target volume. Host-assisted cloning is the least efficient method of cloning.csi-clone
uses the CSI clone API to efficiently clone an existing volume without using an interim volume snapshot. Unlikesnapshot
orcopy
, which are used by default if no storage profile is defined, CSI volume cloning is only used when you specify it in theStorageProfile
object for the provisioner’s storage class.
You can also set clone strategies using the CLI without modifying the default |
Example storage profile
apiVersion: cdi.kubevirt.io/v1beta1
kind: StorageProfile
metadata:
name: <provisioner_class>
# ...
spec:
claimPropertySets:
- accessModes:
- ReadWriteOnce (1)
volumeMode:
Filesystem (2)
cloneStrategy: csi-clone (3)
status:
provisioner: <provisioner>
storageClass: <provisioner_class>
1 | Specify the access mode. |
2 | Specify the volume mode. |
3 | Specify the default cloning strategy. |