8.3.2.4. CLI を使用してコンテナーディスクから仮想マシンを作成する
コマンドラインを使用して、コンテナーディスクから仮想マシンを作成できます。
前提条件
- コンテナーディスクを含むコンテナーレジストリーへのアクセス認証情報が必要です。
-
virtctlCLI がインストールされている。 -
OpenShift CLI (
oc) がインストールされている。
手順
仮想マシンの
VirtualMachineマニフェストを作成し、YAML ファイルとして保存します。たとえば、コンテナーディスクから最小限の Red Hat Enterprise Linux (RHEL) 仮想マシンを作成するには、次のコマンドを実行します。$ virtctl create vm --name vm-rhel-9 --instancetype u1.small --preference rhel.9 --volume-containerdisk src:registry.redhat.io/rhel9/rhel-guest-image:9.5仮想マシンの
VirtualMachineマニフェストを確認します。apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata: name: vm-rhel-91 spec: instancetype: name: u1.small2 preference: name: rhel.93 runStrategy: Always template: metadata: creationTimestamp: null spec: domain: devices: {} resources: {} terminationGracePeriodSeconds: 180 volumes: - containerDisk: image: registry.redhat.io/rhel9/rhel-guest-image:9.54 name: vm-rhel-9-containerdisk-0次のコマンドを実行して VM を作成します。
$ oc create -f <vm_manifest_file>.yaml
検証
仮想マシンのステータスを監視します。
$ oc get vm <vm_name>プロビジョニングが成功すると、仮想マシンのステータスが
Runningになります。出力例
NAME AGE STATUS READY vm-rhel-9 18s Running Trueプロビジョニングが完了し、シリアルコンソールにアクセスして仮想マシンが起動したことを確認します。
$ virtctl console <vm_name>仮想マシンが実行中でシリアルコンソールにアクセスできる場合、出力は次のようになります。
出力例
Successfully connected to vm-rhel-9 console. The escape sequence is ^]