Clone an existing VM's PVC into new data volumes, and then use the data volumes to create additional VMs.
Outcomes
Clone a VM.
Use DataVolume resources to clone VM disks.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that the cluster API is reachable.
It also creates the advanced-clone namespace and starts two virtual machines in that namespace: golden-rhel and vm1.
[student@workstation ~]$ lab start advanced-clone
Instructions
As the admin user, locate and then navigate to the Red Hat OpenShift web console.
Confirm that the two VMs are running.
From a command line, log in to your Red Hat OpenShift cluster as the admin user.
[student@workstation ~]$oc login -u admin -p redhatocp \https://api.ocp4.example.com:6443Login Successful ...output omitted...
Identify the URL for the OpenShift web console.
[student@workstation ~]$ oc whoami --show-console
https://console-openshift-console.apps.ocp4.example.comOpen a web browser and navigate to https://console-openshift-console.apps.ocp4.example.com.
Select and log in as the admin user with redhatocp as the password.
Navigate to → and select the advanced-clone project from the list.
Confirm that the golden-rhel and vm1 VMs are running.
Clone the golden-rhel VM to a new VM named web1.
The cloning process requires that you stop the source machine.
Select the golden-rhel VM and then click → .
Wait for the machine to stop.
Click → .
Set the VM name to web1, select , and then click .
Navigate to → and confirm that the new web1 VM is running.
List the data volumes that are associated with the web1 VM.
Delete the VM and then confirm that Red Hat OpenShift Virtualization also deletes the data volumes and the underlying PVCs.
From the command line on the workstation machine, use the oc command to select the advanced-clone project.
[student@workstation ~]$ oc project advanced-clone
Now using project "advanced-clone" on server "https://api.ocp4.example.com:6443".List the data volumes in the advanced-clone project.
[student@workstation ~]$oc get datavolumeNAME PHASE PROGRESS RESTARTS AGE golden-rhel Succeeded 100.0% 1 16mgolden-rhel-9uo0ySucceeded 100.0% 6m17s vm1 Succeeded 100.0% 1 12m webroot Succeeded 100.0% 16mwebroot-9uo0ySucceeded 100.0% 6m17s
The cloning process appends the name of the source data volumes with the random characters, in the preceding output.
List the PVCs in the project. PVCs have the same name as the associated data volumes.
[student@workstation ~]$oc get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES ... golden-rhel Bound pvc-ccb7...3667 10Gi RWX ...golden-rhel-9uo0yBound pvc-0bd3...684f 11362347344 RWX ... vm1 Bound pvc-9ae1...459a 10Gi RWX ... webroot Bound pvc-c1de...2358 1Gi RWX ...webroot-9uo0yBound pvc-8690...95d6 1136234735 RWX ...
Use the OpenShift web console to delete the web1 VM.
Navigate to → , select the web1 VM, and then click → .
Select and then click .
From the command line, use the oc command to list the data volume and the PVC resources.
Notice that the data volumes and PVC resources for the web1 VM no longer exist.
[student@workstation ~]$ oc get datavolume
NAME PHASE PROGRESS RESTARTS AGE
golden-rhel Succeeded 100.0% 1 22m
vm1 Succeeded 100.0% 1 18m
webroot Succeeded 100.0% 22m[student@workstation ~]$ oc get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES ...
golden-rhel Bound pvc-ccb7...3667 10Gi RWX ...
vm1 Bound pvc-9ae1...459a 10Gi RWX ...
webroot Bound pvc-c1de...2358 1Gi RWX ...Clone the webroot PVC.
The golden-rhel VM uses that PVC as an additional disk to store contents for the web server that is running inside the VM.
From the command line, edit the /home/student/DO316/labs/advanced-clone/dv.yaml file that the lab command prepares.
The file defines a DataVolume resource named documentroot-clone1.
In the .spec.source.pvc section, update the name parameter to specify the source PVC.
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataVolume
metadata:
name: documentroot-clone1
namespace: advanced-clone
spec:
storage:
resources:
requests:
storage: 1Gi
storageClassName: ocs-external-storagecluster-ceph-rbd-virtualization
source:
pvc:
name: webroot
namespace: advanced-cloneUse the oc apply command to create the resource.
[student@workstation ~]$ oc apply -f ~/DO316/labs/advanced-clone/dv.yaml
datavolume.cdi.kubevirt.io/documentroot-clone1 createdUse the oc command to confirm that OpenShift Virtualization creates the data volume and the PVC resources.
[student@workstation ~]$oc get datavolumeNAME PHASE PROGRESS RESTARTS AGEdocumentroot-clone1 Succeeded30s ...output omitted... [student@workstation ~]$oc get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES ...documentroot-clone1Bound pvc-7bc3...f58d 1Gi RWX ... ...output omitted...
Attach the documentroot-clone1 PVC to the vm1 VM.
From the OpenShift web console, navigate to → .
Select the vm1 VM, and then click → .
Wait for the machine to stop.
Navigate to → and then click . Complete the form by using the following information:
If the field is set to scsi and virtio is not available, then click and start over.
The web interface takes a few seconds to detect that the VM is stopped.
| Field | Value |
|---|---|
| Name |
docroot
|
| Source |
Use an existing PVC
|
| PVC project |
advanced-clone
|
| PVC name |
documentroot-clone1
|
| Type |
Disk
|
| Interface |
VirtIO
|
Click to attach the disk to the VM.
Click → to start the VM.
Log in to the VM console and confirm that a new 1 GiB device is available.
Navigate to the tab and then log in as the root user with redhat as the password.
Run the lsblk command to list the block devices.
Notice the 1 GiB vdb block device.
[root@vm1 ~]#lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 10G 0 disk ├─vda1 252:1 0 1M 0 part ├─vda2 252:2 0 100M 0 part /boot/efi └─vda3 252:3 0 9.9G 0 part /vdb252:16 01G0 disk
Log out of the VM console.
[root@vm1 ~]# logoutDelete the vm1 VM to verify that OpenShift Virtualization does not delete DataVolume resources that you create independently of a VM.
Confirm that the documentroot-clone1 data volume and the underlying PVC still exist.
Click → . Select and then click .
From the command line, use the oc command to list the data volume and PVC resources.
Notice that the documentroot-clone1 data volume and the PVC still exist.
[student@workstation ~]$oc get datavolumeNAME PHASE PROGRESS RESTARTS AGEdocumentroot-clone1Succeeded 59s ...output omitted... [student@workstation ~]$oc get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES ...documentroot-clone1Bound pvc-7bc3...f58d 1Gi RWX ... ...output omitted...
Delete the documentroot-clone1 data volume and then confirm that OpenShift Virtualization automatically deletes the underlying PVC.
[student@workstation ~]$oc delete datavolume documentroot-clone1datavolume.cdi.kubevirt.io "documentroot-clone1" deleted [student@workstation ~]$oc get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES ... golden-rhel Bound pvc-f874...367d 10Gi RWX ... webroot Bound pvc-2588...9f7d 1Gi RWX ...