10.2. MTC 自定义资源清单

MTC 使用以下自定义资源(CR)清单来迁移应用程序。

10.2.1. DirectImageMigration

DirectImageMigration CR 直接将镜像从源集群复制到目标集群。

apiVersion: migration.openshift.io/v1alpha1
kind: DirectImageMigration
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: <direct_image_migration>
spec:
  srcMigClusterRef:
    name: <source_cluster>
    namespace: openshift-migration
  destMigClusterRef:
    name: <destination_cluster>
    namespace: openshift-migration
  namespaces: 1
    - <source_namespace_1>
    - <source_namespace_2>:<destination_namespace_3> 2
1
包含要迁移的镜像的一个或多个命名空间。默认情况下,目标命名空间的名称与源命名空间相同。
2
使用不同名称映射到目标命名空间的源命名空间。

10.2.2. DirectImageStreamMigration

DirectImageStreamMigration CR 直接将镜像流引用从源集群复制到目标集群。

apiVersion: migration.openshift.io/v1alpha1
kind: DirectImageStreamMigration
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: <direct_image_stream_migration>
spec:
  srcMigClusterRef:
    name: <source_cluster>
    namespace: openshift-migration
  destMigClusterRef:
    name: <destination_cluster>
    namespace: openshift-migration
  imageStreamRef:
    name: <image_stream>
    namespace: <source_image_stream_namespace>
  destNamespace: <destination_image_stream_namespace>

10.2.3. DirectVolumeMigration

DirectVolumeMigration CR 直接将持久性卷(PV)从源集群复制到目标集群。

apiVersion: migration.openshift.io/v1alpha1
kind: DirectVolumeMigration
metadata:
  name: <direct_volume_migration>
  namespace: openshift-migration
spec:
  createDestinationNamespaces: false 1
  deleteProgressReportingCRs: false 2
  destMigClusterRef:
    name: <host_cluster> 3
    namespace: openshift-migration
  persistentVolumeClaims:
  - name: <pvc> 4
    namespace: <pvc_namespace>
  srcMigClusterRef:
    name: <source_cluster>
    namespace: openshift-migration
1
设置为 true,为目标集群上的 PV 创建命名空间。
2
设置为 true,以在迁移后删除 DirectVolumeMigrationProgress CR。默认值为 false,保留 DirectVolumeMigrationProgress CR 以进行故障排除。
3
如果目标集群不是主机集群,请更新集群名称。
4
指定要迁移的一个或多个 PVC。

10.2.4. DirectVolumeMigrationProgress

DirectVolumeMigrationProgress CR 显示 DirectVolumeMigration CR 的进度。

apiVersion: migration.openshift.io/v1alpha1
kind: DirectVolumeMigrationProgress
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: <direct_volume_migration_progress>
spec:
  clusterRef:
    name: <source_cluster>
    namespace: openshift-migration
  podRef:
    name: <rsync_pod>
    namespace: openshift-migration

10.2.5. MigAnalytic

MigAnalytic CR 从关联的 MigPlan CR 收集镜像、Kubernetes 资源和持久性卷(PV)容量的数量。

您可以配置它收集的数据。

apiVersion: migration.openshift.io/v1alpha1
kind: MigAnalytic
metadata:
  annotations:
    migplan: <migplan>
  name: <miganalytic>
  namespace: openshift-migration
  labels:
    migplan: <migplan>
spec:
  analyzeImageCount: true 1
  analyzeK8SResources: true 2
  analyzePVCapacity: true 3
  listImages: false 4
  listImagesLimit: 50 5
  migPlanRef:
    name: <migplan>
    namespace: openshift-migration
1
可选:返回镜像数量。
2
可选:返回 Kubernetes 资源的数量、类型和 API 版本。
3
可选:返回 PV 容量。
4
返回镜像名称列表。默认为 false,因此输出不会过长。
5
可选:指定如果 listImagestrue 时要返回的最大镜像名称数。

10.2.6. MigCluster

MigCluster CR 定义一个主机、本地或远程集群。

apiVersion: migration.openshift.io/v1alpha1
kind: MigCluster
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: <host_cluster> 1
  namespace: openshift-migration
spec:
  isHostCluster: true 2
# The 'azureResourceGroup' parameter is relevant only for Microsoft Azure.
  azureResourceGroup: <azure_resource_group> 3
  caBundle: <ca_bundle_base64> 4
  insecure: false 5
  refresh: false 6
# The 'restartRestic' parameter is relevant for a source cluster.
  restartRestic: true 7
# The following parameters are relevant for a remote cluster.
  exposedRegistryPath: <registry_route> 8
  url: <destination_cluster_url> 9
  serviceAccountSecretRef:
    name: <source_secret> 10
    namespace: openshift-config
1
如果 migration-controller pod 没有在这个集群中运行,请更新集群名称。
2
如果为 true,则 migration-controller pod 在此集群中运行。
3
仅 Microsoft Azure:指定资源组。
4
可选:如果您为自签名 CA 证书创建了一个证书捆绑包,且 insecure 参数值为 false,请指定 base64 编码的证书捆绑包。
5
设置为 true 以禁用 SSL 验证。
6
设置为 true 以验证集群。
7
设置为 true,以在创建 Stage pod 后重启源集群中的 Restic pod。
8
远程集群和直接镜像迁移:指定公开的安全 registry 路径。
9
仅远程集群:指定 URL。
10
仅远程集群:指定 Secret 对象的名称。

10.2.7. MigHook

MigHook CR 定义一个迁移 hook,它在迁移的指定阶段运行自定义代码。您可以创建最多四个迁移 hook。每个 hook 在迁移的不同阶段运行。

您可以配置 hook 名称、运行时持续时间、自定义镜像,以及 hook 将运行的集群。

hook 的迁移阶段和命名空间在 MigPlan CR 中配置。

apiVersion: migration.openshift.io/v1alpha1
kind: MigHook
metadata:
  generateName: <hook_name_prefix> 1
  name: <mighook> 2
  namespace: openshift-migration
spec:
  activeDeadlineSeconds: 1800 3
  custom: false 4
  image: <hook_image> 5
  playbook: <ansible_playbook_base64> 6
  targetCluster: source 7
1
可选:此参数的值后附加一个唯一的哈希值,以便每个迁移 hook 都有一个唯一的名称。您不需要指定 name 参数的值。
2
指定迁移 hook 名称,除非指定了 generateName 参数的值。
3
可选:指定 hook 可运行的最大秒数。默认值为 1800
4
如果为 true,则 hook 是一个自定义镜像。自定义镜像可以包括 Ansible,也可以使用不同的编程语言编写。
5
指定自定义镜像,例如 quay.io/konveyor/hook-runner:latest。如果 customtrue,则需要此项。
6
base64 编码的 Ansible playbook.如果 customfalse,则必需。
7
指定要运行 hook 的集群。有效值为 sourcedestination

10.2.8. MigMigration

MigMigration CR 运行一个 MigPlan CR。

您可以配置 Migmigration CR,以运行一个阶段或增量迁移,取消正在进行中的迁移,或回滚已完成的迁移。

apiVersion: migration.openshift.io/v1alpha1
kind: MigMigration
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: <migmigration>
  namespace: openshift-migration
spec:
  canceled: false 1
  rollback: false 2
  stage: false 3
  quiescePods: true 4
  keepAnnotations: true 5
  verify: false 6
  migPlanRef:
    name: <migplan>
    namespace: openshift-migration
1
设置为 true 可取消正在进行中的迁移。
2
设置为 true 以回滚已完成的迁移。
3
设置为 true 以运行暂存迁移。数据会被递增复制,pod 不会在源集群中停止。
4
设置为 true 可在迁移期间停止应用程序。在备份阶段后,源集群中的 pod 被缩减为 0
5
设置为 true 以保留迁移过程中应用的标签和注解。
6
设置为 true,以检查目标集群中迁移的 pod 的状态,并返回处于 Running 状态的 pod 名称。

10.2.9. MigPlan

MigPlan CR 定义迁移计划的参数。

您可以配置目标命名空间、hook 阶段以及直接或间接迁移。

注意

默认情况下,目标命名空间的名称与源命名空间相同。如果配置了一个不同的目标命名空间,您必须确保不会在源或目标集群上重复命名空间,因为在迁移过程中复制了 UID 和 GID 范围。

apiVersion: migration.openshift.io/v1alpha1
kind: MigPlan
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: <migplan>
  namespace: openshift-migration
spec:
  closed: false 1
  srcMigClusterRef:
    name: <source_cluster>
    namespace: openshift-migration
  destMigClusterRef:
    name: <destination_cluster>
    namespace: openshift-migration
  hooks: 2
    - executionNamespace: <namespace> 3
      phase: <migration_phase> 4
      reference:
        name: <hook> 5
        namespace: <hook_namespace> 6
      serviceAccount: <service_account> 7
  indirectImageMigration: true 8
  indirectVolumeMigration: false 9
  migStorageRef:
    name: <migstorage>
    namespace: openshift-migration
  namespaces:
    - <source_namespace_1> 10
    - <source_namespace_2>
    - <source_namespace_3>:<destination_namespace_4> 11
  refresh: false  12
1
如果为 true,则迁移已完成。您不能为此 MigPlan CR 创建另一个 MigMigration CR。
2
可选:最多可指定四个迁移 hook。每个 hook 必须在不同的迁移阶段运行。
3
可选:指定运行 hook 的命名空间。
4
可选:指定 hook 运行期间的迁移阶段。一个 hook 可以分配给一个阶段。有效值为 PreBackupPostBackupPreRestorePostRestore
5
可选:指定 MigHook CR 的名称。
6
可选:指定 MigHook CR 的命名空间。
7
可选:指定一个具有 cluster-admin 权限的服务帐户。
8
如果为 true,则禁用直接镜像迁移。镜像从源集群复制到复制存储库,并从复制存储库复制到目标集群。
9
如果为 true,则禁用直接卷迁移。PV 从源集群复制到复制存储库,再从复制存储库复制到目标集群。
10
指定一个或多个源命名空间。如果只指定源命名空间,则目标命名空间是相同的。
11
如果目标命名空间与源命名空间不同,请指定它。
12
如果为 trueMigPlan CR 会被验证。

10.2.10. MigStorage

MigStorage CR 描述了复制存储库的对象存储。

支持 Amazon Web Services(AWS)、Microsoft Azure、Google Cloud Storage、Multi-Cloud Object Gateway 和通用 S3 兼容云存储。

AWS 和快照复制方法具有额外的参数。

apiVersion: migration.openshift.io/v1alpha1
kind: MigStorage
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: <migstorage>
  namespace: openshift-migration
spec:
  backupStorageProvider: <backup_storage_provider> 1
  volumeSnapshotProvider: <snapshot_storage_provider> 2
  backupStorageConfig:
    awsBucketName: <bucket> 3
    awsRegion: <region> 4
    credsSecretRef:
      namespace: openshift-config
      name: <storage_secret> 5
    awsKmsKeyId: <key_id> 6
    awsPublicUrl: <public_url> 7
    awsSignatureVersion: <signature_version> 8
  volumeSnapshotConfig:
    awsRegion: <region> 9
    credsSecretRef:
      namespace: openshift-config
      name: <storage_secret> 10
  refresh: false 11
1
指定存储供应商。
2
仅快照复制方法:指定存储供应商。
3
仅 AWS:指定存储桶名称。
4
仅 AWS:指定存储桶区域,如 us-east-1
5
指定您为存储创建的 Secret 对象的名称。
6
仅 AWS:如果您使用 AWS 密钥管理服务,请指定该密钥的唯一标识符。
7
仅 AWS:如果授予 AWS 存储桶的公共访问权限,请指定存储桶 URL。
8
仅 AWS:指定向存储桶验证请求的 AWS 签名版本,例如 4
9
仅快照复制方法:指定集群的地理位置。
10
仅快照复制方法:指定您为存储创建的 Secret 对象的名称。
11
设置为 true 以验证集群。