本文說明如何在代管執行個體群組 (MIG) 中暫停及停止虛擬機器 (VM) 執行個體,以及如何恢復其運作。
事前準備
- 參閱MIG 中已暫停和已停止的 VM 相關介紹頁面。
-
如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 Google Cloud 服務和 API 的程序。如要在本機開發環境中執行程式碼或範例,您可以選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
暫停 MIG 中的特定 VM
您可以使用 Google Cloud 控制台、Google Cloud CLI 或 Compute Engine API,在 MIG 中暫停執行中的 VM。
主控台
- 前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
- 按一下要暫停 VM 的執行個體群組名稱。
- 在執行個體群組的「總覽」頁面中,選取「VM 執行個體」下方的所有 VM,即可暫停這些 VM。
- 按一下「停權」。
- 在隨即顯示的確認對話方塊中,按一下「Suspend」進行確認。
gcloud
使用 instance-groups managed suspend-instances
指令。
gcloud compute instance-groups managed suspend-instances MIG_NAME \ --instances=INSTANCE_NAME \ [--region=REGION | --zone=ZONE]
更改下列內容:
MIG_NAME
:要暫停執行個體的 MIG 名稱。INSTANCE_NAME
:要暫停的執行個體名稱。如要暫停多個執行個體,請提供以半形逗號分隔的名稱清單。REGION
:如果是區域 MIG,則為 MIG 所在的區域。ZONE
:如果是區域 MIG,則為 MIG 所在的可用區。
REST
請使用 instanceGroupManager.suspendInstances
方法,並在要求主體中指定執行個體。如果是區域 MIG,請使用 regionInstanceGroupManager.suspendInstances
方法。
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME/suspendInstances { "instances": [ "INSTANCE_NAME_URL" ] }
更改下列內容:
PROJECT_ID
:要求的專案 ID。ZONE
:如果是區域 MIG,則為 MIG 所在的區域。- 如果是區域 MIG,請將
zones/ZONE
替換為regions/REGION
,並指定 MIG 的區域。
- 如果是區域 MIG,請將
MIG_NAME
:要暫停執行個體的 MIG 名稱。INSTANCE_NAME_URL
:要暫停的執行個體網址,例如zones/us-central1-a/instances/example-instance-name1
。如要暫停多個執行個體,請提供以半形逗號分隔的網址清單,例如"zones/us-central1-a/instances/example-instance-name1","zones/us-central1-a/instances/example-instance-name2"
。
重新啟用 MIG 中的選取 VM
您可以使用 Google Cloud 主控台、gcloud CLI 或 Compute Engine API,在 MIG 中恢復已暫停的 VM。
主控台
- 前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
- 按一下要繼續執行 VM 的執行個體群組名稱。
- 在執行個體群組的「總覽」頁面中,點選「VM 執行個體」下方的「Start/Resume」,然後選取所有要繼續執行的已暫停 VM。
gcloud
使用 instance-groups managed resume-instances
指令。
gcloud compute instance-groups managed resume-instances MIG_NAME \ --instances=INSTANCE_NAME \ [--region=REGION | --zone=ZONE]
更改下列內容:
MIG_NAME
:要繼續執行的 MIG 名稱。INSTANCE_NAME
:要繼續執行的執行個體名稱。如要繼續執行多個例項,請提供以半形逗號分隔的名稱清單。REGION
:如果是區域 MIG,則為 MIG 所在的區域。ZONE
:如果是區域 MIG,則為 MIG 所在的可用區。
REST
請使用 instanceGroupManager.resumeInstances
方法,並在要求主體中指定執行個體。如果是區域 MIG,請使用 regionInstanceGroupManager.resumeInstances
方法。
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME/resumeInstances { "instances": [ "INSTANCE_NAME_URL" ] }
更改下列內容:
PROJECT_ID
:要求的專案 ID。ZONE
:如果是區域 MIG,則為 MIG 所在的區域。- 如果是區域 MIG,請將
zones/ZONE
替換為regions/REGION
,並指定 MIG 的區域。
- 如果是區域 MIG,請將
MIG_NAME
:要繼續執行的執行個體所在的 MIG 名稱。INSTANCE_NAME_URL
:要繼續執行的執行個體網址,例如zones/us-central1-a/instances/example-instance-name1
。如要繼續執行多個例項,請提供以半形逗號分隔的網址清單,例如"zones/us-central1-a/instances/example-instance-name1","zones/us-central1-a/instances/example-instance-name2"
。
停止 MIG 中的特定 VM
您可以使用 Google Cloud 控制台、Google Cloud CLI 或 Compute Engine API,停止 MIG 中執行中的 VM。
主控台
- 前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
- 按一下要停止 VM 的執行個體群組名稱。
- 在執行個體群組的「總覽」頁面中,點選「VM instances」下方的「VM instances」,選取要停止的所有 VM,然後按一下「Stop」。
- 在隨即顯示的確認對話方塊中,按一下「Stop」進行確認。
gcloud
使用 instance-groups managed stop-instances
指令。
gcloud compute instance-groups managed stop-instances MIG_NAME \ --instances=INSTANCE_NAME \ [--region=REGION | --zone=ZONE]
更改下列內容:
MIG_NAME
:要停止執行個體的 MIG 名稱。INSTANCE_NAME
:要停止的執行個體名稱。如要停止多個執行個體,請提供以半形逗號分隔的名稱清單。REGION
:如果是區域 MIG,則為 MIG 所在的區域。ZONE
:如果是區域 MIG,則為 MIG 所在的可用區。
REST
請使用 instanceGroupManager.stopInstances
方法,並在要求主體中指定執行個體。如果是區域 MIG,請使用 regionInstanceGroupManager.stopInstances
方法。
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME/stopInstances { "instances": [ "INSTANCE_NAME_URL" ] }
更改下列內容:
PROJECT_ID
:要求的專案 ID。ZONE
:如果是區域 MIG,則為 MIG 所在的區域。- 如果是區域 MIG,請將
zones/ZONE
替換為regions/REGION
,並指定 MIG 的區域。
- 如果是區域 MIG,請將
MIG_NAME
:要停止執行個體的 MIG 名稱。INSTANCE_NAME_URL
:要停止的執行個體網址,例如zones/us-central1-a/instances/example-instance-name1
。如要停止多個執行個體,請提供以半形逗號分隔的網址清單,例如"zones/us-central1-a/instances/example-instance-name1","zones/us-central1-a/instances/example-instance-name2"
。
在 MIG 中啟動所選 VM
您可以使用 Google Cloud 主控台、gcloud CLI 或 Compute Engine API,在 MIG 中啟動已停止的 VM。
主控台
- 前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
- 按一下要啟動 VM 的執行個體群組名稱。
- 在執行個體群組的「總覽」頁面中,點選「VM 執行個體」下方的「VM 執行個體」,選取所有要啟動的已停止 VM,然後按一下「Start/Resume」。
gcloud
使用 instance-groups managed start-instances
指令。
gcloud compute instance-groups managed start-instances MIG_NAME \ --instances=INSTANCE_NAME \ [--region=REGION | --zone=ZONE]
更改下列內容:
MIG_NAME
:要啟動執行個體的 MIG 名稱。INSTANCE_NAME
:要啟動的執行個體名稱。如要啟動多個執行個體,請提供以半形逗號分隔的名稱清單。REGION
:如果是區域 MIG,則為 MIG 所在的區域。ZONE
:如果是區域 MIG,則為 MIG 所在的可用區。
REST
請使用 instanceGroupManager.startInstances
方法,並在要求主體中指定執行個體。如果是區域 MIG,請使用 regionInstanceGroupManager.startInstances
方法。
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME/startInstances { "instances": [ "INSTANCE_NAME_URL" ] }
更改下列內容:
PROJECT_ID
:要求的專案 ID。ZONE
:如果是區域 MIG,則為 MIG 所在的區域。- 如果是區域 MIG,請將
zones/ZONE
替換為regions/REGION
,並指定 MIG 的區域。
- 如果是區域 MIG,請將
MIG_NAME
:要啟動執行個體的 MIG 名稱。INSTANCE_NAME_URL
:要啟動的執行個體網址,例如zones/us-central1-a/instances/example-instance-name1
。如要啟動多個執行個體,請提供以半形逗號分隔的網址清單,例如"zones/us-central1-a/instances/example-instance-name1","zones/us-central1-a/instances/example-instance-name2"
。
後續步驟
- 瞭解如何透過待命集區加速擴展規模。