OpenShift Virtualization
Red Hat® OpenShift® Virtualization は Red Hat OpenShift に含まれる機能であり、組織が新規および既存の仮想マシン (VM) ワークロードを実行およびデプロイするための先進的なプラットフォームを提供します。このソリューションにより、従来の仮想マシンを、信頼できる、一貫した包括的なハイブリッドクラウド・アプリケーション・プラットフォームに簡単に移行できます。
OpenShift Virtualization は、VM の移行を単純化するとともに、クラウドネイティブ・アプリケーション・プラットフォームのシンプルさと速度を利用してインフラストラクチャのモダナイゼーションの道筋を提供します。また、先進的な管理の原則を取り入れつつ既存の仮想化への投資を維持することを目指しており、Red Hat の包括的な仮想化ソリューションの基盤となります。
Edit VM
OCP 4.17 Bare Metal 環境 OpenShift Virtualization (OCP-V) で Virtual Machine (VM) を編集してみます。ここでは以下の手順を参考に、作成済み VM を編集します。
Editing virtual machines
Disk
OCP Console から Disk を追加することが出来ます。編集の反映には VM の再起動が必要です。
Adding a disk to a virtual machine
Hot-plugging VM disks
OCP Console
以下の VM を編集してみます。この VM は worker02
で稼働しています。
$ oc get pod,vmi,vm,pvc -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/virt-launcher-rhel9-custom01-upload-zq8cl 1/1 Running 0 62s 10.130.3.106 worker02 <none> 1/1
NAME AGE PHASE IP NODENAME READY LIVE-MIGRATABLE PAUSED
virtualmachineinstance.kubevirt.io/rhel9-custom01-upload 62s Running 10.130.3.106 worker02 True True
NAME AGE STATUS READY
virtualmachine.kubevirt.io/rhel9-custom01-upload 18d Running True
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE VOLUMEMODE
persistentvolumeclaim/rhel9-custom01-upload Bound pvc-94f07b59-5200-4474-88be-05912a12e36a 30Gi RWX ocs-storagecluster-ceph-rbd-virtualization <unset> 18d Block
なお、現在の Disk 設定は、画面表示の他に VirtualMachineInstance を参照する事もできます。
$ oc -o json get vmi rhel9-custom01-upload | jq -r '.status.volumeStatus[]'
{
"name": "cloudinitdisk",
"size": 1048576,
"target": "vdb"
}
{
"name": "rootdisk",
"persistentVolumeClaimInfo": {
"accessModes": [
"ReadWriteMany"
],
"capacity": {
"storage": "30Gi"
},
"claimName": "rhel9-custom01-upload",
"filesystemOverhead": "0",
"requests": {
"storage": "32212254720"
},
"volumeMode": "Block"
},
"target": "vda"
}
Add Disk
Configuration
Tab の Storage
から 'Add disk` を操作すると、以下のような選択肢が表示されます。
Empty disk (blank)
を選択すると、以下のような画面が表示されます。
画面に Adding hot plugged disk
の表示があり、Type
は Disk
と LUN
のみ選択可能で、Use this disk as a boot source
と Interface
は Gray Out されています。
なお、VM を停止した状態では、Type
の全て (CD-ROM
Disk
LUN
)、Interface
の全て (SATA
SCSI
VirtIO
) が選択可能です。
ここでは、Name を rhel9-custom01-upload-empty-disk-5g
、Disk size を 5 GiB
、Type を Disk
に設定します。
Save
ボタンを押すと Disk が即時に追加され、操作として Edit
Detach
Make persistent
がある事が分かります。
CLI で確認すると、VirtualMachine CR に dataVolume
が hotpluggable=true
で追加された事が分かります。
$ oc -o json get vm rhel9-custom01-upload | jq -r '.spec.template.spec.volumes[]'
{
"cloudInitNoCloud": {
"userData": "*****"
},
"name": "cloudinitdisk"
}
{
"name": "rootdisk",
"persistentVolumeClaim": {
"claimName": "rhel9-custom01-upload"
}
}
{
"dataVolume": {
"hotpluggable": true,
"name": "dv-rhel9-custom01-upload-beige-tarantula-60"
},
"name": "rhel9-custom01-upload-empty-disk-5g"
}
$ oc explain VirtualMachine.spec.template.spec.volumes.dataVolume
GROUP: kubevirt.io
KIND: VirtualMachine
VERSION: v1
FIELD: dataVolume <Object>
DESCRIPTION:
DataVolume represents the dynamic creation a PVC for this volume as well as
the process of populating that PVC with a disk image.
FIELDS:
hotpluggable <boolean>
Hotpluggable indicates whether the volume can be hotplugged and
hotunplugged.
name <string> -required-
Name of both the DataVolume and the PVC in the same namespace.
After PVC population the DataVolume is garbage collected by default.
上記に対応する Hot Plug 用 DataVolume と PVC が追加されます。
$ oc get dv dv-rhel9-custom01-upload-beige-tarantula-60
NAME PHASE PROGRESS RESTARTS AGE
dv-rhel9-custom01-upload-beige-tarantula-60 Succeeded 100.0% 74m
$ oc -o json get dv dv-rhel9-custom01-upload-beige-tarantula-60 | jq -r '.spec'
{
"source": {
"blank": {}
},
"storage": {
"resources": {
"requests": {
"storage": "5Gi"
}
},
"storageClassName": "ocs-storagecluster-ceph-rbd"
}
}
$ oc get pvc dv-rhel9-custom01-upload-beige-tarantula-60
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE
dv-rhel9-custom01-upload-beige-tarantula-60 Bound pvc-337b8a9b-a4b1-4ca7-8451-cbfda3906416 5Gi RWX ocs-storagecluster-ceph-rbd <unset> 12m
Hot Plug 用 Pod が VM Pod と同じ Node 上で起動され、以下のように PVC が使用されている事が分かります。
$ oc get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
hp-volume-z9dtw 1/1 Running 0 14m 10.129.2.208 worker02 <none> <none>
virt-launcher-rhel9-custom01-upload-zq8cl 1/1 Running 0 36m 10.129.2.207 worker02 <none> 1/1
$ oc get pod hp-volume-z9dtw -o json | jq -r '.metadata.ownerReferences[], (.spec| .containers[].volumeDevices[], ( .volumes[] | select(.name == "rhel9-custom01-upload-empty-disk-5g")))'
{
"apiVersion": "v1",
"blockOwnerDeletion": true,
"controller": true,
"kind": "Pod",
"name": "virt-launcher-rhel9-custom01-upload-zq8cl",
}
{
"devicePath": "/path/rhel9-custom01-upload-empty-disk-5g/eef0efcc-c064-4953-ac42-5629e2ba53af",
"name": "rhel9-custom01-upload-empty-disk-5g"
}
{
"name": "rhel9-custom01-upload-empty-disk-5g",
"persistentVolumeClaim": {
"claimName": "dv-rhel9-custom01-upload-beige-tarantula-60"
}
}
Hot Plug 用 Pod の Disk を Mount propagation
で VM Pod と共有しています。VM Pod の hotplug-disks emptyDir
はデフォルトで用意されており、今回の Disk 追加に際しての VM Pod 再起動 / Live Migration は発生しません。
Mount propagation
Caution:
Mount propagation is a low-level feature that does not work consistently on all volume types. The Kubernetes project recommends only using mount propagation with hostPath or memory-backed emptyDir volumes. See Kubernetes issue #95049 for more context.
Mount propagation allows for sharing volumes mounted by a container to other containers in the same pod, or even to other pods on the same node.
HostToContainer
This volume mount will receive all subsequent mounts that are mounted to this volume or any of its subdirectories.
In other words, if the host mounts anything inside the volume mount, the container will see it mounted there.
Similarly, if any Pod with Bidirectional mount propagation to the same volume mounts anything there, the container with HostToContainer mount propagation will see it.
This mode is equal to rslave mount propagation as described in the mount(8)
$ oc get pod -o json | jq --arg D "hotplug-disks" -r '.items[] | .metadata.name, (.spec| (.containers[].volumeMounts[] | select(.name == $D)), .volumes[] | select(.name == $D))'
hp-volume-z9dtw
{
"mountPath": "/path",
"mountPropagation": "HostToContainer",
"name": "hotplug-disks"
}
{
"emptyDir": {},
"name": "hotplug-disks"
}
virt-launcher-rhel9-custom01-upload-zq8cl
{
"mountPath": "/var/run/kubevirt/hotplug-disks",
"mountPropagation": "HostToContainer",
"name": "hotplug-disks"
}
{
"emptyDir": {},
"name": "hotplug-disks"
}
VM 内部では Disk が sda
に割り当てられている事が分かります。
$ virtctl console rhel9-custom01-upload
~中略~
[cloud-user@rhel9-custom01-upload ~]$ uname -n
rhel9-custom01-upload
[cloud-user@rhel9-custom01-upload ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 5G 0 disk
vda 252:0 0 30G 0 disk
tqvda1 252:1 0 1M 0 part
tqvda2 252:2 0 200M 0 part /boot/efi
tqvda3 252:3 0 1G 0 part /boot
mqvda4 252:4 0 28.8G 0 part /
vdb 252:16 0 1M 0 disk
Hot Plug 状態の Disk は以下のように使用する事ができます。
-
VM の停止を行うと Hot Plug 用 Pod は停止しますが PVC / PV はそのままになり、VM 再起動時に新しい Hot Plug 用 Pod が起動され、継続して Disk が使用可能になります。
-
Live Migration を行うと VM Pod 移動先 Node に新しい Hot Plug 用 Pod が起動され、継続して Disk が使用可能になります。
-
Disk の Detach を行うと VirtualMachine CR から Disk の設定が削除され VM から使用できなくなりますが、PVC / PV はそのままになります。
-
Detach された Disk を再度使用する場合は、
Add disk
のVolume
から該当の PVC を選択して Hot Plug の状態で Attach する事ができます。
Make persistent
以下の画面から Make persistent
を選択します。
Pop Up が表示され Save
ボタンを押すことで処理が実行されます。
以下のような画面が表示され、VM の再起動が必要である事が分かります。
この時点では、Pod の状態は変更されません。
$ oc get pod
NAME READY STATUS RESTARTS AGE
hp-volume-z9dtw 1/1 Running 0 132m
virt-launcher-rhel9-custom01-upload-zq8cl 1/1 Running 0 154m
$ oc get pod hp-volume-z9dtw -o json | jq -r '.metadata.ownerReferences[], (.spec| .containers[].volumeDevices[], ( .volumes[] | select(.name == "rhel9-custom01-upload-empty-disk-5g")))'
{
"apiVersion": "v1",
"blockOwnerDeletion": true,
"controller": true,
"kind": "Pod",
"name": "virt-launcher-rhel9-custom01-upload-zq8cl",
"uid": "b9cce7f1-373b-40ec-9c84-9e4140f8977d"
}
{
"devicePath": "/path/rhel9-custom01-upload-empty-disk-5g/eef0efcc-c064-4953-ac42-5629e2ba53af",
"name": "rhel9-custom01-upload-empty-disk-5g"
}
{
"name": "rhel9-custom01-upload-empty-disk-5g",
"persistentVolumeClaim": {
"claimName": "dv-rhel9-custom01-upload-beige-tarantula-60"
}
}
$ oc get pod -o json | jq --arg D "hotplug-disks" -r '.items[] | .metadata.name, (.spec| (.containers[].volumeMounts[] | select(.name == $D)), .volumes[] | select(.name == $D))'
hp-volume-z9dtw
{
"mountPath": "/path",
"mountPropagation": "HostToContainer",
"name": "hotplug-disks"
}
{
"emptyDir": {},
"name": "hotplug-disks"
}
virt-launcher-rhel9-custom01-upload-zq8cl
{
"mountPath": "/var/run/kubevirt/hotplug-disks",
"mountPropagation": "HostToContainer",
"name": "hotplug-disks"
}
{
"emptyDir": {},
"name": "hotplug-disks"
}
VM を再起動する事で、更新を反映させます。操作として Edit
Detach
のみ可能となり、Make persistent
がない事が分かります。
Hot Plug 用 Pod は終了し、Hot Plug 用 Pod で実装されていた devicePath
の設定が、VM Pod への実装に変更されます。
$ oc get pod
NAME READY STATUS RESTARTS AGE
virt-launcher-rhel9-custom01-upload-7dhb6 1/1 Running 0 7m30s
$ oc get pod virt-launcher-rhel9-custom01-upload-7dhb6 -o json | jq -r '.metadata.ownerReferences[], (.spec| .containers[].volumeDevices[], ( .volumes[] | select(.name == "rhel9-custom01-upload-empty-disk-5g")))'
{
"apiVersion": "kubevirt.io/v1",
"blockOwnerDeletion": true,
"controller": true,
"kind": "VirtualMachineInstance",
"name": "rhel9-custom01-upload",
"uid": "f9a290e6-8c4a-4f24-bc61-e015ef10590c"
}
{
"devicePath": "/dev/rootdisk",
"name": "rootdisk"
}
{
"devicePath": "/dev/rhel9-custom01-upload-empty-disk-5g",
"name": "rhel9-custom01-upload-empty-disk-5g"
}
{
"name": "rhel9-custom01-upload-empty-disk-5g",
"persistentVolumeClaim": {
"claimName": "dv-rhel9-custom01-upload-beige-tarantula-60"
}
}
$ virtctl console rhel9-custom01-upload
~中略~
[cloud-user@rhel9-custom01-upload ~]$ uname -n
rhel9-custom01-upload
[cloud-user@rhel9-custom01-upload ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 5G 0 disk
vda 252:0 0 30G 0 disk
tqvda1 252:1 0 1M 0 part
tqvda2 252:2 0 200M 0 part /boot/efi
tqvda3 252:3 0 1G 0 part /boot
mqvda4 252:4 0 28.8G 0 part /
vdb 252:16 0 1M 0 disk
oc -o json get vm rhel9-custom01-upload | jq -r '.spec.template.spec.volumes[]'
{
"cloudInitNoCloud": {
"userData": "*****"
},
"name": "cloudinitdisk"
}
{
"name": "rootdisk",
"persistentVolumeClaim": {
"claimName": "rhel9-custom01-upload"
}
}
{
"dataVolume": {
"name": "dv-rhel9-custom01-upload-beige-tarantula-60"
},
"name": "rhel9-custom01-upload-empty-disk-5g"
}
Detach Disk
Detach
をしてみます。
メッセージが表示され、VM 再起動が必要な事が分かります。
この時点で、該当 Disk は VirtualMachine
の構成から削除されますが、稼働中 Pod に対応する VirtualMachineInstance
の構成は変更されないままです。
$ oc -o json get vm rhel9-custom01-upload | jq -r '.spec.template.spec.volumes[]'
{
"cloudInitNoCloud": {
"userData": "#cloud-config\nuser: cloud-user\npassword: 8sgr-cvj1-cl02\nchpasswd: { expire: False }"
},
"name": "cloudinitdisk"
}
{
"name": "rootdisk",
"persistentVolumeClaim": {
"claimName": "rhel9-custom01-upload"
}
}
$ oc -o json get vmi rhel9-custom01-upload | jq -r '.status.volumeStatus[]'
{
"name": "cloudinitdisk",
"size": 1048576,
"target": "vdb"
}
{
"name": "rhel9-custom01-upload-empty-disk-5g",
"persistentVolumeClaimInfo": {
"accessModes": [
"ReadWriteMany"
],
"capacity": {
"storage": "5Gi"
},
"claimName": "dv-rhel9-custom01-upload-beige-tarantula-60",
"filesystemOverhead": "0",
"requests": {
"storage": "5368709120"
},
"volumeMode": "Block"
},
"target": "sda"
}
{
"name": "rootdisk",
"persistentVolumeClaimInfo": {
"accessModes": [
"ReadWriteMany"
],
"capacity": {
"storage": "30Gi"
},
"claimName": "rhel9-custom01-upload",
"filesystemOverhead": "0",
"requests": {
"storage": "32212254720"
},
"volumeMode": "Block"
},
"target": "vda"
}
VM を再起動すると、該当 Disk の構成を削除した VirtualMachineInstance
が作成されます。
$ oc -o json get vmi rhel9-custom01-upload | jq -r '.status.volumeStatus[]'
{
"name": "cloudinitdisk",
"size": 1048576,
"target": "vdb"
}
{
"name": "rootdisk",
"persistentVolumeClaimInfo": {
"accessModes": [
"ReadWriteMany"
],
"capacity": {
"storage": "30Gi"
},
"claimName": "rhel9-custom01-upload",
"filesystemOverhead": "0",
"requests": {
"storage": "32212254720"
},
"volumeMode": "Block"
},
"target": "vda"
}
CLI
virtctl addvolume
/ virtctl removevolume
を使用する事で、OCP Console 同等の操作を行う事が出来ます。追加した Disk の編集は VirtualMachine CR, DataVolume CR を直接修正します。
$ virtctl addvolume --help
add a volume to a running VM
Usage:
virtctl addvolume VMI [flags]
Examples:
#Dynamically attach a volume to a running VM.
virtctl addvolume fedora-dv --volume-name=example-dv
#Dynamically attach a volume to a running VM giving it a serial number to identify the volume inside the guest.
virtctl addvolume fedora-dv --volume-name=example-dv --serial=1234567890
#Dynamically attach a volume to a running VM and persisting it in the VM spec. At next VM restart the volume will be attached like any other volume.
virtctl addvolume fedora-dv --volume-name=example-dv --persist
#Dynamically attach a volume with 'none' cache attribute to a running VM.
virtctl addvolume fedora-dv --volume-name=example-dv --cache=none
Flags:
--cache string caching options attribute control the cache mechanism
--disk-type string specifies disk type to be hotplugged (disk/lun). Disk by default. (default "disk")
--dry-run --dry-run=false: Flag used to set whether to perform a dry run or not. If true the command will be executed without performing any changes.
-h, --help help for addvolume
--persist if set, the added volume will be persisted in the VM spec (if it exists)
--serial string serial number you want to assign to the disk
--volume-name string name used in volumes section of spec
Use "virtctl options" for a list of global command-line options (applies to all commands).
$ virtctl removevolume --help
remove a volume from a running VM
Usage:
virtctl removevolume VMI [flags]
Examples:
#Remove volume that was dynamically attached to a running VM.
virtctl removevolume fedora-dv --volume-name=example-dv
#Remove volume dynamically attached to a running VM and persisting it in the VM spec.
virtctl removevolume fedora-dv --volume-name=example-dv --persist
Flags:
--dry-run --dry-run=false: Flag used to set whether to perform a dry run or not. If true the command will be executed without performing any changes.
-h, --help help for removevolume
--persist if set, the added volume will be persisted in the VM spec (if it exists)
--volume-name string name used in volumes section of spec
Use "virtctl options" for a list of global command-line options (applies to all commands).
Others
Resize Disk
- PVC / PV で使用する StorageClass がサポートしている場合は、PVC / PV を修正する事でリサイズを行います。
- リサイズをサポートしていない場合は、Diskの追加で対応します。
Expanding a VM disk PVC
You can increase the size of a virtual machine (VM) disk by expanding the persistent volume claim (PVC) of the disk.
If your storage provider does not support volume expansion, you can expand the available virtual storage of a VM by adding blank data volumes.
You cannot reduce the size of a VM disk.
Shared Volume
複数 VM 間で使用する共有ディスクを設定する事ができます。
Configuring shared volumes for virtual machines
You can configure shared disks to allow multiple virtual machines (VMs) to share the same underlying storage. A shared disk’s volume must be block mode.
You configure disk sharing by exposing the storage as either of these types:
- An ordinary VM disk
- A logical unit number (LUN) disk with an SCSI connection and raw device mapping, as required for Windows Failover Clustering for shared volumes
In addition to configuring disk sharing, you can also set an error policy for each ordinary VM disk or LUN disk. The error policy controls how the hypervisor behaves when an input/output error occurs on a disk Read or Write.