11.5. 导出虚拟机
您可以导出虚拟机 (VM) 及其关联的磁盘,以将虚拟机导入到另一个集群或分析卷以备备目的。
您可以使用命令行界面创建一个 VirtualMachineExport 自定义资源 (CR)。
另外,您可以使用 virtctl vmexport 命令创建一个 VirtualMachineExport CR 并下载导出的卷。
11.5.1. 创建 VirtualMachineExport 自定义资源 复制链接链接已复制到粘贴板!
您可以创建一个 VirtualMachineExport 自定义资源 (CR) 来导出以下对象:
- 虚拟机 (VM):导出指定虚拟机的持久性卷声明 (PVC)。
-
VM 快照:导出
VirtualMachineSnapshotCR 中包含的 PVC。 -
PVC :导出 PVC。如果 PVC 被另一个 pod (如
virt-launcherpod)使用,则导出会一直处于Pending状态,直到 PVC 不再使用为止。
VirtualMachineExport CR 为导出的卷创建内部和外部链接。内部链接在集群中有效。可以使用 Ingress 或 Route 访问外部链接。
导出服务器支持以下文件格式:
-
raw: 原始磁盘镜像文件。 -
gzip:压缩的磁盘镜像文件. -
dir:PVC 目录和文件。 -
tar.gz:压缩的 PVC 文件。
先决条件
- 必须为虚拟机导出关闭虚拟机。
流程
创建一个
VirtualMachineExport清单,根据以下示例从VirtualMachine、VirtualMachineSnapshot或PersistentVolumeClaimCR 导出卷,并将其保存为example-export.yaml:VirtualMachineExport示例apiVersion: export.kubevirt.io/v1alpha1 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.yaml获取
VirtualMachineExportCR:$ 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