9.9. 仮想マシンのエクスポート
仮想マシンを別のクラスターにインポートしたり、フォレンジック目的でボリュームを分析したりするために、仮想マシン (VM) とそれに関連付けられたディスクをエクスポートできます。
コマンドラインインターフェイスを使用して、VirtualMachineExport カスタムリソース (CR) を作成します。
または、virtctl vmexport コマンド を使用して VirtualMachineExport CR を作成し、エクスポートされたボリュームをダウンロードすることもできます。
Migration Toolkit for Virtualization を使用して、OpenShift Virtualization クラスター間で仮想マシンを移行できます。
9.9.1. VirtualMachineExport カスタムリソースの作成 リンクのコピーリンクがクリップボードにコピーされました!
VirtualMachineExport カスタムリソース (CR) を作成して、VirtualMachine、VirtualMachineSnapshot、または PersistentVolumeClaim CR から永続ボリューム要求 (PVC) をエクスポートできます。
エクスポートできるオブジェクトは次のとおりです。
- 仮想マシン: 指定した仮想マシンの永続ボリューム要求をエクスポートします。
-
仮想マシンスナップショット:
VirtualMachineSnapshotCR に含まれる PVC をエクスポートします。 -
PVC: PVC をエクスポートします。PVC が
virt-launcherPod などの別の Pod で使用されている場合、エクスポートは PVC が使用されなくなるまでPending状態のままになります。
VirtualMachineExport CR は、エクスポートされたボリュームの内部および外部リンクを作成します。内部リンクはクラスター内で有効です。外部リンクには、Ingress または Route を使用してアクセスできます。
エクスポートサーバーは、次のファイル形式をサポートしています。
-
raw: raw ディスクイメージファイル。 -
gzip: 圧縮されたディスクイメージファイル。 -
dir: PVC ディレクトリーとファイル。 -
tar.gz: 圧縮された PVC ファイル。
前提条件
- 仮想マシンをエクスポートするために、仮想マシンがシャットダウンされている。
-
OpenShift CLI (
oc) がインストールされている。
手順
次の例に従って、
VirtualMachine、VirtualMachineSnapshot、またはPersistentVolumeClaimCR からボリュームをエクスポートするためのVirtualMachineExportマニフェストを作成し、example-export.yamlとして保存します。VirtualMachineExportの例:apiVersion: export.kubevirt.io/v1beta1 kind: VirtualMachineExport metadata: name: example-export spec: source: apiGroup: "kubevirt.io"1 kind: VirtualMachine2 name: example-vm ttlDuration: 1h3 VirtualMachineExportCR を作成します。$ oc create -f example-export.yamlVirtualMachineExportCR を取得します。$ oc get vmexport example-export -o yamlエクスポートされたボリュームの内部および外部リンクは、
statusスタンザに表示されます。出力例:
apiVersion: export.kubevirt.io/v1beta1 kind: VirtualMachineExport metadata: name: example-export namespace: example spec: source: apiGroup: "" kind: PersistentVolumeClaim name: example-pvc tokenSecretRef: example-token status: conditions: - lastProbeTime: null lastTransitionTime: "2022-06-21T14:10:09Z" reason: podReady status: "True" type: Ready - lastProbeTime: null lastTransitionTime: "2022-06-21T14:09:02Z" reason: pvcBound status: "True" type: PVCReady links: external:1 cert: |- -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE----- volumes: - formats: - format: raw url: https://vmexport-proxy.test.net/api/export.kubevirt.io/v1beta1/namespaces/example/virtualmachineexports/example-export/volumes/example-disk/disk.img - format: gzip url: https://vmexport-proxy.test.net/api/export.kubevirt.io/v1beta1/namespaces/example/virtualmachineexports/example-export/volumes/example-disk/disk.img.gz name: example-disk internal:2 cert: |- -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE----- volumes: - formats: - format: raw url: https://virt-export-example-export.example.svc/volumes/example-disk/disk.img - format: gzip url: https://virt-export-example-export.example.svc/volumes/example-disk/disk.img.gz name: example-disk phase: Ready serviceName: virt-export-example-export
9.9.2. エクスポートされた仮想マシンマニフェストへのアクセス リンクのコピーリンクがクリップボードにコピーされました!
仮想マシン (VM) またはスナップショットをエクスポートすると、エクスポートサーバーから VirtualMachine マニフェストと関連情報を取得できます。
前提条件
-
OpenShift CLI (
oc) がインストールされている。 VirtualMachineExportカスタムリソース (CR) を作成して、仮想マシンまたは VM スナップショットをエクスポートしている。注記spec.source.kind: PersistentVolumeClaimパラメーターを持つVirtualMachineExportオブジェクトは、仮想マシンマニフェストを生成しません。
手順
マニフェストにアクセスするには、まず証明書をソースクラスターからターゲットクラスターにコピーする必要があります。
- ソースクラスターにログインします。
次のコマンドを実行して、証明書を
cacert.crtファイルに保存します。$ oc get vmexport <export_name> -o jsonpath={.status.links.external.cert} > cacert.crt1 - 1
<export_name>を、VirtualMachineExportオブジェクトのmetadata.name値に置き換えます。
-
cacert.crtファイルをターゲットクラスターにコピーします。
次のコマンドを実行して、ソースクラスター内のトークンをデコードし、
token_decodeファイルに保存します。$ oc get secret export-token-<export_name> -o jsonpath={.data.token} | base64 --decode > token_decode1 - 1
<export_name>を、VirtualMachineExportオブジェクトのmetadata.name値に置き換えます。
-
token_decodeファイルをターゲットクラスターにコピーします。 次のコマンドを実行して、
VirtualMachineExportカスタムリソースを取得します。$ oc get vmexport <export_name> -o yamlstatus.linksスタンザを確認します。このスタンザはexternalセクションとinternalセクションに分かれています。各セクション内のmanifests.urlフィールドに注意してください。以下に例を示します。apiVersion: export.kubevirt.io/v1beta1 kind: VirtualMachineExport metadata: name: example-export spec: source: apiGroup: "kubevirt.io" kind: VirtualMachine name: example-vm tokenSecretRef: example-token status: #... links: external: #... manifests: - type: all url: https://vmexport-proxy.test.net/api/export.kubevirt.io/v1beta1/namespaces/example/virtualmachineexports/example-export/external/manifests/all1 - type: auth-header-secret url: https://vmexport-proxy.test.net/api/export.kubevirt.io/v1beta1/namespaces/example/virtualmachineexports/example-export/external/manifests/secret2 internal: #... manifests: - type: all url: https://virt-export-export-pvc.default.svc/internal/manifests/all3 - type: auth-header-secret url: https://virt-export-export-pvc.default.svc/internal/manifests/secret phase: Ready serviceName: virt-export-example-export- 1
VirtualMachineマニフェスト、存在する場合はDataVolumeマニフェスト、外部 URL の Ingress またはルートの公開証明書を含むConfigMapマニフェストが含まれます。- 2
- Containerized Data Importer (CDI) と互換性のあるヘッダーを含むシークレットが含まれます。ヘッダーには、エクスポートトークンのテキストバージョンが含まれています。
- 3
VirtualMachineマニフェスト、存在する場合はDataVolumeマニフェスト、および内部 URL のエクスポートサーバーの証明書を含むConfigMapマニフェストが含まれます。
- ターゲットクラスターにログインします。
次のコマンドを実行して
Secretマニフェストを取得します。$ curl --cacert cacert.crt <secret_manifest_url> -H \1 "x-kubevirt-export-token:token_decode" -H \2 "Accept:application/yaml"以下に例を示します。
$ curl --cacert cacert.crt https://vmexport-proxy.test.net/api/export.kubevirt.io/v1beta1/namespaces/example/virtualmachineexports/example-export/external/manifests/secret -H "x-kubevirt-export-token:token_decode" -H "Accept:application/yaml"次のコマンドを実行して、
ConfigMapマニフェストやVirtualMachineマニフェストなどのtype: allマニフェストを取得します。$ curl --cacert cacert.crt <all_manifest_url> -H \1 "x-kubevirt-export-token:token_decode" -H \2 "Accept:application/yaml"以下に例を示します。
$ curl --cacert cacert.crt https://vmexport-proxy.test.net/api/export.kubevirt.io/v1beta1/namespaces/example/virtualmachineexports/example-export/external/manifests/all -H "x-kubevirt-export-token:token_decode" -H "Accept:application/yaml"
次のステップ
-
エクスポートしたマニフェストを使用して、ターゲットクラスター上に
ConfigMapオブジェクトとVirtualMachineオブジェクトを作成できます。