9.2.4. MTC API を使用したアプリケーションの移行

MTC (Migration Toolkit for Containers) API を使用してコマンドラインからアプリケーションを移行できます。

手順

  1. host クラスターの MigCluster CR マニフェストを作成します。

    $ cat << EOF | oc apply -f -
    apiVersion: migration.openshift.io/v1alpha1
    kind: MigCluster
    metadata:
      name: <host_cluster>
      namespace: openshift-migration
    spec:
      isHostCluster: true
    EOF
  2. それぞれのリモートクラスターに Secret CR マニフェストを作成します。

    $ cat << EOF | oc apply -f -
    apiVersion: v1
    kind: Secret
    metadata:
      name: <cluster_secret>
      namespace: openshift-config
    type: Opaque
    data:
      saToken: <sa_token> 1
    EOF
    1
    リモートクラスターの base64 でエンコードされた migration-controller サービスアカウント (SA) トークンを指定します。以下のコマンドを実行してトークンを取得できます。
    $ oc sa get-token migration-controller -n openshift-migration | base64 -w 0
  3. それぞれのリモートクラスターについて MigCluster CR マニフェストを作成します。

    $ cat << EOF | oc apply -f -
    apiVersion: migration.openshift.io/v1alpha1
    kind: MigCluster
    metadata:
      name: <remote_cluster> 1
      namespace: openshift-migration
    spec:
      exposedRegistryPath: <exposed_registry_route> 2
      insecure: false 3
      isHostCluster: false
      serviceAccountSecretRef:
        name: <remote_cluster_secret> 4
        namespace: openshift-config
      url: <remote_cluster_url> 5
    EOF
    1
    リモートクラスターの Cluster CR を指定します。
    2
    オプション: イメージの直接移行には、公開されるレジストリールートを指定します。
    3
    SSL 検証は、false の場合に有効になります。CA 証明書は、true の場合は必要ではなく、チェックされません。
    4
    リモートクラスターの Secret CR オブジェクトを指定します。
    5
    リモートクラスターの URL を指定します。
  4. すべてのクラスターが Ready 状態にあることを確認します。

    $ oc describe cluster <cluster>
  5. レプリケーションリポジトリーの Secret CR マニフェストを作成します。

    $ cat << EOF | oc apply -f -
    apiVersion: v1
    kind: Secret
    metadata:
      namespace: openshift-config
      name: <migstorage_creds>
    type: Opaque
    data:
      aws-access-key-id: <key_id_base64> 1
      aws-secret-access-key: <secret_key_base64> 2
    EOF
    1
    キー ID を base64 形式で指定します。
    2
    シークレットキーを base64 形式で指定します。

    AWS 認証情報はデフォルトで base64 でエンコードされます。それぞれのキーを使用して以下のコマンドを実行して、認証情報をエンコードする必要があります。

    $ echo -n "<key>" | base64 -w 0 1
    1
    キー ID またはシークレットキーを指定します。どちらの値も base64 でエンコードする必要があります。
  6. レプリケーションリポジトリーの MigStorage CR マニフェストを作成します。

    $ cat << EOF | oc apply -f -
    apiVersion: migration.openshift.io/v1alpha1
    kind: MigStorage
    metadata:
      name: <migstorage>
      namespace: openshift-migration
    spec:
      backupStorageConfig:
        awsBucketName: <bucket> 1
        credsSecretRef:
          name: <storage_secret> 2
          namespace: openshift-config
      backupStorageProvider: <storage_provider> 3
      volumeSnapshotConfig:
        credsSecretRef:
          name: <storage_secret> 4
          namespace: openshift-config
      volumeSnapshotProvider: <storage_provider> 5
    EOF
    1
    バケット名を指定します。
    2
    オブジェクトストレージの Secrets CR を指定します。オブジェクトストレージの Secrets CR に保存される認証情報が正しいことを確認する必要があります。
    3
    ストレージプロバイダーを指定します。
    4
    オプション: スナップショットを使用してデータをコピーする場合は、オブジェクトストレージの Secrets CR を指定します。オブジェクトストレージの Secrets CR に保存される認証情報が正しいことを確認する必要があります。
    5
    オプション: スナップショットを使用してデータをコピーする場合は、ストレージプロバイダーを指定します。
  7. MigStorage CR が Ready 状態にあることを確認します。

    $ oc describe migstorage <migstorage>
  8. MigPlan CR マニフェストを作成します。

    $ cat << EOF | oc apply -f -
    apiVersion: migration.openshift.io/v1alpha1
    kind: MigPlan
    metadata:
      name: <migplan>
      namespace: openshift-migration
    spec:
      destMigClusterRef:
        name: <host_cluster>
        namespace: openshift-migration
      indirectImageMigration: true 1
      indirectVolumeMigration: true 2
      migStorageRef:
        name: <migstorage> 3
        namespace: openshift-migration
      namespaces:
        - <application_namespace> 4
      srcMigClusterRef:
        name: <remote_cluster> 5
        namespace: openshift-migration
    EOF
    1
    false の場合、直接的なイメージ移行が有効にされます。
    2
    false の場合、直接的なボリューム移行が有効にされます。
    3
    MigStorage CR インスタンスの名前を指定します。
    4
    namespace を 1 つ以上指定します。デフォルトで、宛先 namespace の名前は同じです。
    5
    ソースクラスター MigCluster インスタンスの名前を指定します。
  9. MigPlan インスタンスが Ready 状態にあることを確認します。

    $ oc describe migplan <migplan> -n openshift-migration
  10. MigMigration CR マニフェストを作成し、MigPlan インスタンスに定義された移行を開始します。

    $ cat << EOF | oc apply -f -
    apiVersion: migration.openshift.io/v1alpha1
    kind: MigMigration
    metadata:
      name: <migmigration>
      namespace: openshift-migration
    spec:
      migPlanRef:
        name: <migplan> 1
        namespace: openshift-migration
      quiescePods: true 2
      stage: false 3
      rollback: false 4
    EOF
    1
    MigPlan CR 名を指定します。
    2
    true の場合、ソースクラスターの Pod は停止します。
    3
    true の場合、アプリケーションを停止せずにほとんどのデータをコピーする段階移行が実行されます。
    4
    true の場合、完了した移行がロールバックされます。
  11. MigMigration CR の進捗を監視して移行を確認します。

    $ oc watch migmigration <migmigration> -n openshift-migration

    出力は以下のようになります。

    出力例

    Name:         c8b034c0-6567-11eb-9a4f-0bc004db0fbc
    Namespace:    openshift-migration
    Labels:       migration.openshift.io/migplan-name=django
    Annotations:  openshift.io/touch: e99f9083-6567-11eb-8420-0a580a81020c
    API Version:  migration.openshift.io/v1alpha1
    Kind:         MigMigration
    ...
    Spec:
      Mig Plan Ref:
        Name:       migplan
        Namespace:  openshift-migration
      Stage:        false
    Status:
      Conditions:
        Category:              Advisory
        Last Transition Time:  2021-02-02T15:04:09Z
        Message:               Step: 19/47
        Reason:                InitialBackupCreated
        Status:                True
        Type:                  Running
        Category:              Required
        Last Transition Time:  2021-02-02T15:03:19Z
        Message:               The migration is ready.
        Status:                True
        Type:                  Ready
        Category:              Required
        Durable:               true
        Last Transition Time:  2021-02-02T15:04:05Z
        Message:               The migration registries are healthy.
        Status:                True
        Type:                  RegistriesHealthy
      Itinerary:               Final
      Observed Digest:         7fae9d21f15979c71ddc7dd075cb97061895caac5b936d92fae967019ab616d5
      Phase:                   InitialBackupCreated
      Pipeline:
        Completed:  2021-02-02T15:04:07Z
        Message:    Completed
        Name:       Prepare
        Started:    2021-02-02T15:03:18Z
        Message:    Waiting for initial Velero backup to complete.
        Name:       Backup
        Phase:      InitialBackupCreated
        Progress:
          Backup openshift-migration/c8b034c0-6567-11eb-9a4f-0bc004db0fbc-wpc44: 0 out of estimated total of 0 objects backed up (5s)
        Started:        2021-02-02T15:04:07Z
        Message:        Not started
        Name:           StageBackup
        Message:        Not started
        Name:           StageRestore
        Message:        Not started
        Name:           DirectImage
        Message:        Not started
        Name:           DirectVolume
        Message:        Not started
        Name:           Restore
        Message:        Not started
        Name:           Cleanup
      Start Timestamp:  2021-02-02T15:03:18Z
    Events:
      Type    Reason   Age                 From                     Message
      ----    ------   ----                ----                     -------
      Normal  Running  57s                 migmigration_controller  Step: 2/47
      Normal  Running  57s                 migmigration_controller  Step: 3/47
      Normal  Running  57s (x3 over 57s)   migmigration_controller  Step: 4/47
      Normal  Running  54s                 migmigration_controller  Step: 5/47
      Normal  Running  54s                 migmigration_controller  Step: 6/47
      Normal  Running  52s (x2 over 53s)   migmigration_controller  Step: 7/47
      Normal  Running  51s (x2 over 51s)   migmigration_controller  Step: 8/47
      Normal  Ready    50s (x12 over 57s)  migmigration_controller  The migration is ready.
      Normal  Running  50s                 migmigration_controller  Step: 9/47
      Normal  Running  50s                 migmigration_controller  Step: 10/47