
Google CloudのMigrate for Anthos and GKEは、オンプレミス環境や他のクラウド環境からGoogle Kubernetes Engine(GKE)へのアプリケーション移行を簡単に実現するためのサービスです。
この記事ではMigrate for Anthos and GKEの概要や実際に利用検証をした内容をご紹介します。(全4回)
- ・1:概要編
- ・2:「評価」
- ・3:「計画」前半 ★本記事
- ・4:「計画」後半~「デプロイ」
計画(Plan)- 前半
移行先GKEクラスタの作成





「作成」ボタンを押して作成を待ちます(5~10分)。



Migrate to Virtual Machinesの準備
APIの有効化
移行先プロジェクトでMigrate to Virtual Machinesに必要なAPIを有効化します。(参考:Migrate to Virtual Machines サービスの有効化 > ホスト プロジェクトで必要なサービスの有効化)
gcloud CLI 等で足りていないAPIを確認し、有効化します。
vCenterユーザーの作成
Migrate to Virtual Machines向けのvCenterユーザーを作成します。 ドキュメントにしたがい、次の通りのロールを作成して付与しました。
SSH 公開鍵 / 秘密鍵のペアを作成する
(参考:Migrate Connector のインストール > 2. SSH 公開鍵 / 秘密鍵のペアを作成する)題の通りですね。SSHのキーペアを作成します。
今回はPuTTYで生成しました。
puttykeygen.exe
を実行して、Parametersで RSA
を選択してGenerateします。 生成したキーペアは後のために保存しておきます。
ユーザーアカウントの構成
Migrate Connectorの登録に使用するユーザー アカウントを決め、必要な権限を与えます。 このユーザーアカウントを使ってサービスアカウントが作成されます。使われるのは初回のMigrate Connector設定時だけです。gcloud projects add-iam-policy-binding bs-gcp-dev --member=user:'{今回対象のユーザーアカウント}' --role='roles/iam.serviceAccountKeyAdmin'
gcloud projects add-iam-policy-binding bs-gcp-dev --member=user:'{今回対象のユーザーアカウント}' --role='roles/iam.serviceAccountCreator'
gcloud projects add-iam-policy-binding bs-gcp-dev --member=user:'{今回対象のユーザーアカウント}' --role='roles/vmmigration.admin'
Migrate Connector のインストール
(参考:Migrate Connector のインストール > Migrate Connector のインストール)Migrate ConnectorのOVAファイルを準備して、vSphere Clientの操作でMigrate Connector VMを準備します。 OVFテンプレートのデプロイをします。










Migrate ConnectorのGoogle Cloudへの登録
(参考:Migrate Connector のインストール > Migrate Connector を Google Cloud ソースとして登録する)Migrate ConnectorからGoogle Cloudにデータを渡せるようにGoogle Cloudソースとして登録します。 「Migrate Connector のインストール」で作成したVMに接続し、
m4c status
コマンドを実行します。
Appliance connectivity and health:
Migrate Connector appliance health: Healthy
Appliance version: 2.3.2077
Proxy setting: not enabled
DNS: 192.168.128.11
Gateway: 192.168.128.254
Google API connection type: Private
Cloud APIs network connection: Reachable
VM Migration service:
Registered with VM Migration service: False
Please use the "register" command to register the appliance
Cloud APIs network connection: Reachable
となっているので大丈夫そうです。Please use the "register" command to register the appliance
の案内に従って登録を進めます。
m4c register
を実行し、求められる情報を入力していきます。
※ 「Migrate Connector のインストール」で作成したVMの時間はデフォルトでUTCになっています。そのままだとm4c register
実行時にM4CからGoogle
Cloudへの認証が失敗する可能性があるので、事前に時刻を確認し、必要に応じて合わせておきます。
Please enter vCenter host address: 192.168.128.35
vCenter server SSL certificate fingerprint is d60b5a1403e6cbb33388695116e86a29b3a61fec. Do you approve? [Y/n]yes
Please enter vCenter account name to be used by this appliance: m4c@vsphere.internal
Please enter vCenter account password:
vSphere credentials verified
Please provide your Google Cloud User Account access token to register Migrate Connector
(Note: The token is valid for 60 minutes):
1. Open Cloud Console (https://console.cloud.google.com)
2. Activate Cloud Shell Terminal (located in the top right of the Cloud Console)
3. Run in Cloud Shell Terminal the following command: 'gcloud auth print-access-token'
4. Copy the access token from Cloud Shell
Cloud Consoleを開き、Cloud
Shellでgcloud auth print-access-token
を実行して得たアクセストークンを入力しなければならないとのことですので、その通り作業して進めます。
Enter access token:ya29.a0Ael9sCPpmkuyssrti6kXmpKQE6bdTZ_TFOLPGvJ2rdmNuFT8_o2neSwyFbI3NPvGDRGt_eKZXnKRBTpwvdkl9pCkil-_w36uHOUYWBdqZY5iooStGiT3r1fFHwJCOfGt1MNiEgdUKz6H-7IGKIKWIYhLrlq1_pdaXpUWa3dY67GcSoZTD2Xa1svS1zQm0Uvi3z4zrh7E3Y09KkaEpN970GNtcnmqzQ16HT8AcK0aCgYKAaESARESFQF4udJhKrhPzLNYD_L3bQJrEDekTQ0238
対象のGoogle
Cloudプロジェクト、リージョン、移行元、サービスアカウント(今回は事前に作成したサービスアカウントユーザー:newm4c58@bs-gcp-dev.iam.gserviceaccount.com
)指定します。
Please select project:
1. bs-gcp-dev
1
Please select region:
1. asia-east1
2. asia-east2
3. asia-northeast1
4. asia-northeast2
5. asia-northeast3
6. asia-south1
7. asia-south2
8. asia-southeast1
9. asia-southeast2
10. australia-southeast1
List is longer than 10, truncating list. Please select or type region.
3
Please select source: ("new" to create)
1. new
2. newm4c58
3. anthos02
4. anthos03
5. anthos01
6. vcenter
6
Please select service account: ("new" to create)
1. new
2. monitoring-test@bs-gcp-dev.iam.gserviceaccount.com
3. dwh-tst-lakeel-sa@bs-gcp-dev.iam.gserviceaccount.com
4. iriedemo@bs-gcp-dev.iam.gserviceaccount.com
5. nakamura01@bs-gcp-dev.iam.gserviceaccount.com
6. mado-test-cloudrun@bs-gcp-dev.iam.gserviceaccount.com
7. taka-satou-gcs-sa@bs-gcp-dev.iam.gserviceaccount.com
8. mado-test-gcs-sa@bs-gcp-dev.iam.gserviceaccount.com
9. m4cconnect@bs-gcp-dev.iam.gserviceaccount.com
10. sa-test-irita@bs-gcp-dev.iam.gserviceaccount.com
List is longer than 10, truncating list. Please select or type service account.
newm4c58@bs-gcp-dev.iam.gserviceaccount.com
You have an old connector connected to this source. Would you like to delete it and create a new one? Note that we won't be able to continue without it [y/N]yes
Waiting for the Migrate Connector to become active. This may take several minutes...
Registration completed
これでMigrate for Virtual Machinesの実行準備が整いました。
Migrate to Vitual Machinesの実行(GCEへの移行)
Migrate to Virtual MachinesでVMをGCEに移行します。今回は次のステップで行います。
- 移行対象の追加
- レプリケーション
- ターゲットの詳細の確認
- カットオーバー
- 動作確認
移行対象の追加
まず、Cloud Consoleで対象のプロジェクトにアクセスしてCompute Engine > Migrate to Virtual Machinesのページを開きます。 「ソース」タブでソースVMのリストが表示されますので、対象を選択して「移行を追加」します。


レプリケーション
「移行」タブで対象VMを確認し、「レプリケーションを開始」します。



ターゲットの詳細の確認
「ターゲットの詳細」では、テストクローンまたはカットオーバーの実行時に作成される Compute Engine インスタンスの環境と構成について記載されています。内容を確認してみます。



カットオーバー
「移行」タブで「カットオーバー」します。これが終わると、GCEへのVMの移行が完了します。




動作確認
移行したVMの動作確認を行います。 移行先のGCEインスタンスに接続して、サービス(httpd)を起動します。[root@anthos01 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:httpd(8)
man:apachectl(8)
4月 03 16:27:54 anthos01 systemd[1]: Collecting httpd.service
[root@anthos01 ~]# systemctl start httpd
[root@anthos01 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since 月 2023-04-03 16:28:28 JST; 4s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 2548 (httpd)
Status: "Processing requests..."
CGroup: /system.slice/httpd.service
├─2548 /usr/sbin/httpd -DFOREGROUND
├─2551 /usr/sbin/httpd -DFOREGROUND
├─2552 /usr/sbin/httpd -DFOREGROUND
├─2553 /usr/sbin/httpd -DFOREGROUND
├─2554 /usr/sbin/httpd -DFOREGROUND
└─2555 /usr/sbin/httpd -DFOREGROUND
4月 03 16:28:28 anthos01 systemd[1]: httpd.service changed dead -> start
4月 03 16:28:28 anthos01 systemd[1]: Starting The Apache HTTP Server...
4月 03 16:28:28 anthos01 systemd[2548]: Executing: /usr/sbin/httpd -DFOREG...D
4月 03 16:28:28 anthos01 systemd[1]: Got notification message for unit ht...ce
4月 03 16:28:28 anthos01 systemd[1]: Got notification message from PID 25...8)
4月 03 16:28:28 anthos01 systemd[1]: httpd.service: got READY=1
4月 03 16:28:28 anthos01 systemd[1]: httpd.service changed start -> running
4月 03 16:28:28 anthos01 systemd[1]: Job httpd.service/start finished, re...ne
4月 03 16:28:28 anthos01 systemd[1]: Started The Apache HTTP Server.
4月 03 16:28:28 anthos01 systemd[1]: httpd.service: got STATUS=Processing.....
Hint: Some lines were ellipsized, use -l to show in full.
ブラウザからアクセスすると、ページが正常に表示されました。

まとめ
今回は移行プロセスの「計画」の前半として、移行先GKEクラスタの作成とMigrate to Vitual Machinesの実行(GCEへの移行)を行いました。
次回は最終回、実際にGKEにアプリをデプロイするところまで検証します。ぜひ次回もご覧ください。
- ・4:「計画」後半~「デプロイ」 ★次回