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


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

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

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

注記

Migration Toolkit for Virtualization を使用して、OpenShift Virtualization クラスター間で仮想マシンを移行できます。

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

VirtualMachineExport カスタムリソース (CR) を作成して、VirtualMachineVirtualMachineSnapshot、または PersistentVolumeClaim CR から永続ボリューム要求 (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 ファイル。

前提条件

  • 仮想マシンをエクスポートするために、仮想マシンがシャットダウンされている。
  • OpenShift CLI (oc) がインストールされている。

手順

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

    VirtualMachineExport の例:

    apiVersion: export.kubevirt.io/v1beta1
    kind: VirtualMachineExport
    metadata:
      name: example-export
    spec:
      source:
        apiGroup: "kubevirt.io" 
    1
    
        kind: VirtualMachine 
    2
    
        name: example-vm
      ttlDuration: 1h 
    3
    Copy to Clipboard Toggle word wrap
    1
    適切な API グループを指定します。
    • VirtualMachine"kubevirt.io"
    • VirtualMachineSnapshot"snapshot.kubevirt.io"
    • PersistentVolumeClaim""
    2
    VirtualMachineVirtualMachineSnapshot、または PersistentVolumeClaim を指定します。
    3
    オプション: デフォルトの期間は 2 時間です。
  2. VirtualMachineExport CR を作成します。

    $ oc create -f example-export.yaml
    Copy to Clipboard Toggle word wrap
  3. VirtualMachineExport CR を取得します。

    $ oc get vmexport example-export -o yaml
    Copy to Clipboard Toggle word wrap

    エクスポートされたボリュームの内部および外部リンクは、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
    Copy to Clipboard Toggle word wrap
    1
    外部リンクは、Ingress または Route を使用してクラスターの外部からアクセスできます。
    2
    内部リンクは、クラスター内でのみ有効です。

8.8.2. エクスポートされた仮想マシンマニフェストへのアクセス

仮想マシン (VM) またはスナップショットをエクスポートすると、エクスポートサーバーから VirtualMachine マニフェストと関連情報を取得できます。

前提条件

  • OpenShift CLI (oc) がインストールされている。
  • VirtualMachineExport カスタムリソース (CR) を作成して、仮想マシンまたは VM スナップショットをエクスポートしている。

    注記

    spec.source.kind: PersistentVolumeClaim パラメーターを持つ VirtualMachineExport オブジェクトは、仮想マシンマニフェストを生成しません。

手順

  1. マニフェストにアクセスするには、まず証明書をソースクラスターからターゲットクラスターにコピーする必要があります。

    1. ソースクラスターにログインします。
    2. 次のコマンドを実行して、証明書を cacert.crt ファイルに保存します。

      $ oc get vmexport <export_name> -o jsonpath={.status.links.external.cert} > cacert.crt 
      1
      Copy to Clipboard Toggle word wrap
      1
      <export_name> を、VirtualMachineExport オブジェクトの metadata.name 値に置き換えます。
    3. cacert.crt ファイルをターゲットクラスターにコピーします。
  2. 次のコマンドを実行して、ソースクラスター内のトークンをデコードし、token_decode ファイルに保存します。

    $ oc get secret export-token-<export_name> -o jsonpath={.data.token} | base64 --decode > token_decode 
    1
    Copy to Clipboard Toggle word wrap
    1
    <export_name> を、VirtualMachineExport オブジェクトの metadata.name 値に置き換えます。
  3. token_decode ファイルをターゲットクラスターにコピーします。
  4. 次のコマンドを実行して、VirtualMachineExport カスタムリソースを取得します。

    $ oc get vmexport <export_name> -o yaml
    Copy to Clipboard Toggle word wrap
  5. status.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/all 
    1
    
          - type: auth-header-secret
            url: https://vmexport-proxy.test.net/api/export.kubevirt.io/v1beta1/namespaces/example/virtualmachineexports/example-export/external/manifests/secret 
    2
    
        internal:
    #...
          manifests:
          - type: all
            url: https://virt-export-export-pvc.default.svc/internal/manifests/all 
    3
    
          - type: auth-header-secret
            url: https://virt-export-export-pvc.default.svc/internal/manifests/secret
      phase: Ready
      serviceName: virt-export-example-export
    Copy to Clipboard Toggle word wrap
    1
    VirtualMachine マニフェスト、存在する場合は DataVolume マニフェスト、外部 URL の Ingress またはルートの公開証明書を含む ConfigMap マニフェストが含まれます。
    2
    Containerized Data Importer (CDI) と互換性のあるヘッダーを含むシークレットが含まれます。ヘッダーには、エクスポートトークンのテキストバージョンが含まれています。
    3
    VirtualMachine マニフェスト、存在する場合は DataVolume マニフェスト、および内部 URL のエクスポートサーバーの証明書を含む ConfigMap マニフェストが含まれます。
  6. ターゲットクラスターにログインします。
  7. 次のコマンドを実行して Secret マニフェストを取得します。

    $ curl --cacert cacert.crt <secret_manifest_url> -H \ 
    1
    
    "x-kubevirt-export-token:token_decode" -H \ 
    2
    
    "Accept:application/yaml"
    Copy to Clipboard Toggle word wrap
    1
    <secret_manifest_url> を、VirtualMachineExport YAML 出力の auth-header-secret URL に置き換えます。
    2
    前に作成した token_decode ファイルを参照します。

    以下に例を示します。

    $ 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"
    Copy to Clipboard Toggle word wrap
  8. 次のコマンドを実行して、ConfigMap マニフェストや VirtualMachine マニフェストなどの type: all マニフェストを取得します。

    $ curl --cacert cacert.crt <all_manifest_url> -H \ 
    1
    
    "x-kubevirt-export-token:token_decode" -H \ 
    2
    
    "Accept:application/yaml"
    Copy to Clipboard Toggle word wrap
    1
    <all_manifest_url> を、VirtualMachineExport YAML 出力の URL に置き換えます。
    2
    前に作成した token_decode ファイルを参照します。

    以下に例を示します。

    $ 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"
    Copy to Clipboard Toggle word wrap

次のステップ

  • エクスポートしたマニフェストを使用して、ターゲットクラスター上に ConfigMap オブジェクトと VirtualMachine オブジェクトを作成できます。
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat