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)
您可以导出虚拟机 (VM) 及其关联的磁盘,以便将 VM 导入另一个集群或分析卷以进行取证。
您可以使用命令行界面创建VirtualMachineExport 自定义资源 (CR)。
或者,您可以使用virtctl vmexport 命令创建VirtualMachineExport CR 并下载导出的卷。
|
您可以使用虚拟化迁移工具包在 OpenShift Virtualization 集群之间迁移虚拟机。 |
您可以创建一个VirtualMachineExport自定义资源 (CR) 来导出以下对象:
虚拟机 (VM):导出指定 VM 的持久卷声明 (PVC)。
VM 快照:导出包含在VirtualMachineSnapshot CR 中的 PVC。
PVC:导出 PVC。如果 PVC 被其他 Pod(例如virt-launcher Pod)使用,则导出将保持Pending状态,直到 PVC 不再使用。
VirtualMachineExport CR 为导出的卷创建内部和外部链接。内部链接在集群内有效。外部链接可以使用Ingress或Route访问。
导出服务器支持以下文件格式:
raw:原始磁盘镜像文件。
gzip:压缩的磁盘镜像文件。
dir:PVC 目录和文件。
tar.gz:压缩的 PVC 文件。
导出 VM 之前必须关闭 VM。
根据以下示例创建一个VirtualMachineExport清单以从VirtualMachine、VirtualMachineSnapshot或PersistentVolumeClaim CR 导出卷,并将其保存为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)
| 1 | 指定相应的 API 组:
|
| 2 | 指定VirtualMachine、VirtualMachineSnapshot或PersistentVolumeClaim。 |
| 3 | 可选。默认持续时间为 2 小时。 |
创建VirtualMachineExport CR
$ oc create -f example-export.yaml
获取VirtualMachineExport CR
$ 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
| 1 | 外部链接可以使用Ingress或Route从集群外部访问。 |
| 2 | 内部链接仅在集群内有效。 |
导出虚拟机 (VM) 或快照后,您可以从导出服务器获取VirtualMachine清单和相关信息。
您通过创建VirtualMachineExport自定义资源 (CR) 来导出虚拟机或 VM 快照。
|
具有 |
要访问清单,您必须先将证书从源集群复制到目标集群。
登录到源集群。
通过运行以下命令将证书保存到cacert.crt文件:
$ oc get vmexport <export_name> -o jsonpath={.status.links.external.cert} > cacert.crt (1)
| 1 | 将<export_name>替换为VirtualMachineExport对象的metadata.name值。 |
将cacert.crt文件复制到目标集群。
在源集群中解码令牌,并将其保存到token_decode文件,运行以下命令:
$ oc get secret export-token-<export_name> -o jsonpath={.data.token} | base64 --decode > token_decode (1)
| 1 | 将<export_name>替换为VirtualMachineExport对象的metadata.name值。 |
将token_decode文件复制到目标集群。
运行以下命令获取VirtualMachineExport自定义资源:
$ oc get vmexport <export_name> -o yaml
查看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
| 1 | 包含VirtualMachine清单、DataVolume清单(如果存在)以及包含外部 URL 的 Ingress 或 Route 的公共证书的ConfigMap清单。 |
| 2 | 包含一个包含与容器化数据导入器 (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"
| 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"
运行以下命令获取type: all的清单,例如ConfigMap和VirtualMachine清单:
$ curl --cacert cacert.crt <all_manifest_url> -H \ (1)
"x-kubevirt-export-token:token_decode" -H \ (2)
"Accept:application/yaml"
| 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"
您现在可以使用导出的清单在目标集群上创建ConfigMap和VirtualMachine对象。