10.5. 仮想マシンのエクスポート

仮想マシンを別のクラスターにインポートしたり、フォレンジック目的でボリュームを分析したりするために、仮想マシン (VM) とそれに関連付けられたディスクをエクスポートできます。

コマンドラインインターフェイスを使用して、VirtualMachineExport カスタムリソース (CR) を作成します。

または、virtctl vmexport コマンド を使用して VirtualMachineExport CR を作成し、エクスポートされたボリュームをダウンロードすることもできます。

10.5.1. VirtualMachineExport カスタムリソースの作成

VirtualMachineExport カスタムリソース (CR) を作成して、次のオブジェクトをエクスポートできます。

  • 仮想マシン (VM): 指定された仮想マシンの永続ボリューム要求 (PVC) をエクスポートします。
  • VM スナップショット: VirtualMachineSnapshot CR に含まれる PVC をエクスポートします。
  • PVC: PVC をエクスポートします。PVC が virt-launcher Pod などの別の Pod で使用されている場合、エクスポートは PVC が使用されなくなるまで Pending 状態のままになります。

VirtualMachineExport CR は、エクスポートされたボリュームの内部および外部リンクを作成します。内部リンクはクラスター内で有効です。外部リンクには、Ingress または Route を使用してアクセスできます。

エクスポートサーバーは、次のファイル形式をサポートしています。

  • raw: raw ディスクイメージファイル。
  • gzip: 圧縮されたディスクイメージファイル。
  • dir: PVC ディレクトリーとファイル。
  • tar.gz: 圧縮された PVC ファイル。

前提条件

  • 仮想マシンをエクスポートするには、仮想マシンをシャットダウンする必要があります。

手順

  1. 次の例に従って VirtualMachineExport マニフェストを作成し、VirtualMachineVirtualMachineSnapshot、または PersistentVolumeClaim CR からボリュームをエクスポートし、example-export.yaml として保存します。

    VirtualMachineExport の例

    apiVersion: export.kubevirt.io/v1alpha1
    kind: VirtualMachineExport
    metadata:
      name: example-export
    spec:
      source:
        apiGroup: "kubevirt.io" 1
        kind: VirtualMachine 2
        name: example-vm
      ttlDuration: 1h 3

    1
    適切な API グループを指定します。
    • VirtualMachine"kubevirt.io"
    • VirtualMachineSnapshot"snapshot.kubevirt.io"
    • PersistentVolumeClaim""
    2
    VirtualMachineVirtualMachineSnapshot、または PersistentVolumeClaim を指定します。
    3
    オプション: デフォルトの期間は 2 時間です。
  2. VirtualMachineExport CR を作成します。

    $ oc create -f example-export.yaml
  3. VirtualMachineExport CR を取得します。

    $ oc get vmexport example-export -o yaml

    エクスポートされたボリュームの内部および外部リンクは、status スタンザに表示されます。

    出力例

    apiVersion: export.kubevirt.io/v1alpha1
    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/v1alpha1/namespaces/example/virtualmachineexports/example-export/volumes/example-disk/disk.img
            - format: gzip
              url: https://vmexport-proxy.test.net/api/export.kubevirt.io/v1alpha1/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

    1
    外部リンクは、Ingress または Route を使用してクラスターの外部からアクセスできます。
    2
    内部リンクは、クラスター内でのみ有効です。