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) 及其关联的磁盘,以便将虚拟机导入另一个集群或分析卷以进行取证。
您可以使用命令行界面创建VirtualMachineExport
自定义资源 (CR)。
或者,您可以使用virtctl vmexport
命令创建VirtualMachineExport
CR 并下载导出的卷。
您可以使用虚拟化迁移工具包在 OpenShift Virtualization 集群之间迁移虚拟机。 |
您可以创建一个VirtualMachineExport
自定义资源 (CR) 来导出以下对象:
虚拟机 (VM):导出指定虚拟机的持久卷声明 (PVC)。
虚拟机快照:导出VirtualMachineSnapshot
CR 中包含的 PVC。
PVC:导出 PVC。如果 PVC 被另一个 Pod(例如virt-launcher
Pod)使用,则导出将保持Pending
状态,直到不再使用 PVC。
VirtualMachineExport
CR 为导出的卷创建内部和外部链接。内部链接在集群内有效。外部链接可以使用Ingress
或Route
访问。
导出服务器支持以下文件格式:
raw
:原始磁盘映像文件。
gzip
:压缩的磁盘映像文件。
dir
:PVC 目录和文件。
tar.gz
:压缩的 PVC 文件。
对于虚拟机导出,虚拟机必须关闭。
创建一个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) 来导出虚拟机或虚拟机快照。
具有 |
要访问清单,您必须首先将证书从源集群复制到目标集群。
登录到源集群。
通过运行以下命令将证书保存到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入口或路由的公共证书的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
对象。