本文說明在代管執行個體群組 (MIG) 中建立調整大小要求後,如何執行下列操作:
在 MIG 中建立調整大小要求後,您可以執行下列一或多項操作:
查看大小調整要求,監控或排解相關問題。
取消大小調整要求,停止 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 中查看、取消或刪除調整大小要求所需的權限,請要求管理員為您授予專案的 Compute Instance 管理員 (v1) (roles/compute.instanceAdmin.v1
) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
這個預先定義的角色包含在 MIG 中查看、取消或刪除調整大小要求所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
如要在 MIG 中查看、取消或刪除大小調整要求,您必須具備下列權限:
-
如要在 MIG 中取消或刪除大小調整要求,請按照下列步驟操作:
compute.instanceGroupManagers.update
-
如何查看 MIG 中的大小調整要求清單:
compute.instanceGroupManagers.list
-
如要查看大小調整要求的詳細資料,請按照下列步驟操作:
compute.instanceGroupManagers.get
查看大小調整要求
如要查看 MIG 中的調整大小要求相關資訊,請使用下列任一方法:
如需 MIG 中所有要求的概略說明,請查看 MIG 中的縮放要求清單。
如需特定要求的完整詳細資料,請查看調整大小要求的詳細資料。
查看 MIG 中的大小調整要求清單
如要查看 MIG 中的所有調整大小要求清單,請選取下列任一選項:
如要查看區域 MIG 中的所有調整大小要求清單,請使用 gcloud CLI 或 REST API。如要查看區域 MIG 中的所有調整大小要求清單,請選取下列任一選項:
主控台
前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
在「Name」欄中,按一下包含調整大小要求的 MIG 名稱。
MIG 的總覽頁面隨即開啟。
在「大小調整要求」列中,按一下
「編輯大小調整要求」。系統會顯示「Resize requests」窗格。如果大小調整要求的「Details」欄顯示「Quota exceeded」或「ETA: indefinite」值,表示要求發生錯誤。您可以點選這些值來瞭解詳情。
如要進一步瞭解如何排解錯誤,請參閱本文件的「查看調整大小要求的詳細資料」一節。
gcloud
如要查看區域 MIG 中的縮放要求清單,請使用
instance-groups managed resize-requests list
指令。gcloud compute instance-groups managed resize-requests list INSTANCE_GROUP_NAME \ --zone=ZONE
如要查看區域 MIG 中的大小調整要求清單,請使用
beta instance-groups managed resize-requests list
指令。gcloud beta compute instance-groups managed resize-requests list INSTANCE_GROUP_NAME \ --region=REGION
更改下列內容:
INSTANCE_GROUP_NAME
:包含已接受、成功、已取消或失敗的大小調整要求的 MIG 名稱。ZONE
:MIG 所在的可用區。REGION
:MIG 所在的地區。
區域 MIG 的輸出內容會與下列內容類似:
NAME: rr-01
LOCATION: us-central1-a
SCOPE: zone
RESIZE_BY: 5
STATE: SUCCEEDED
REQUESTED_RUN_DURATION: P1D
NAME: rr-02
LOCATION: us-central1-a
SCOPE: zone
RESIZE_BY: 10
STATE: ACCEPTED
REQUESTED_RUN_DURATION: P3D
REST
如要查看區域 MIG 中的規模調整要求清單,請使用
instanceGroupManagerResizeRequests.list
方法傳送GET
要求。GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/INSTANCE_GROUP_NAME/resizeRequests
如要查看區域 MIG 中的縮放要求清單,請使用
beta.regionInstanceGroupManagerResizeRequests.list
方法傳送GET
要求。GET https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/regions/REGION/regionInstanceGroupManagers/INSTANCE_GROUP_NAME/resizeRequests
更改下列內容:
PROJECT_ID
:包含已接受、成功、已取消或失敗的大小調整要求的 MIG 所在專案 ID。ZONE
:MIG 所在的可用區。REGION
:MIG 所在的地區。INSTANCE_GROUP_NAME
:已接受、成功、已取消或失敗的大小調整要求,以及現有 MIG 的名稱。
區域 MIG 的輸出內容會與下列內容類似:
{
"kind": "compute#instanceGroupManagerResizeRequestList",
"id": "projects/example-project/zones/us-central1-a/instanceGroupManagers/example-mig/resizeRequests",
"items": [
{
"kind": "compute#instanceGroupManagerResizeRequest",
"id": "4247139565532196982",
"creationTimestamp": "2024-01-08T07:51:53.034-08:00",
"name": "rr-01",
"zone": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a",
"count": 5,
"resizeBy": 5,
"requestedRunDuration": {
"seconds": "86400",
"nanos": 0
},
"state": "SUCCEEDED",
"status": {},
"selfLink": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instanceGroupManagers/example-mig/resizeRequests/rr-01",
"selfLinkWithId": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instanceGroupManagers/example-mig/resizeRequests/4247139565532196982"
},
{
"kind": "compute#instanceGroupManagerResizeRequest",
"id": "8095866098849525652",
"creationTimestamp": "2024-01-11T08:04:11.851-08:00",
"name": "rr-02",
"zone": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a",
"count": 10,
"resizeBy": 10,
"requestedRunDuration": {
"seconds": "259200",
"nanos": 0
},
"state": "ACCEPTED",
"status": {},
"selfLink": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instanceGroupManagers/example-mig/resizeRequests/rr-02",
"selfLinkWithId": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instanceGroupManagers/example-mig/resizeRequests/8095866098849525652"
}
],
"selfLink": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instanceGroupManagers/example-mig/resizeRequests"
}
查看大小調整要求的詳細資料
您可以查看縮放要求的詳細資料,查看相關設定,並視需要針對未成功的縮放要求進行疑難排解。
如果已接受的調整大小要求無法成功,您可以查看要求詳細資料中的 status.lastAttempt.error.errors.code
欄位,藉此排除問題。可能的錯誤代碼如下:
QUOTA_EXCEEDED
:您的專案缺少所要求資源的配額。如要增加專案配額,請參閱「要求增加配額」一文。ZONE_RESOURCE_POOL_EXHAUSTED_WITH_DETAILS
:要求的資源暫時無法使用。Compute Engine 已排定建立要求的資源,並計劃在資源可用時建立。如果message
欄位包含Expected time is indefinite
,Google 建議您取消要求,並嘗試下列一或多個操作:建立新的調整大小要求,要求的 VM 數量較少。
在 MIG 中使用不同的機器類型,然後建立新的調整大小要求。如要使用其他機器類型,請建立新的執行個體範本,然後使用該範本建立或更新 MIG。
在位於不同區域或可用區的 MIG 中建立調整大小要求。
如要查看調整大小要求的詳細資料,請選取下列任一選項:
gcloud
如要查看區域 MIG 中的大小調整要求詳細資料,請使用
instance-groups managed resize-requests describe
指令。gcloud compute instance-groups managed resize-requests describe INSTANCE_GROUP_NAME \ --resize-request=RESIZE_REQUEST_NAME \ --zone=ZONE
如要查看區域 MIG 中的大小調整要求詳細資料,請使用
beta instance-groups managed resize-requests describe
指令。gcloud beta compute instance-groups managed resize-requests describe INSTANCE_GROUP_NAME \ --resize-request=RESIZE_REQUEST_NAME \ --region=REGION
更改下列內容:
INSTANCE_GROUP_NAME
:MIG 的名稱。RESIZE_REQUEST_NAME
:您要查看詳細資料的調整大小要求名稱。ZONE
:MIG 所在的可用區。REGION
:MIG 所在的地區。
區域 MIG 的輸出內容會與下列內容類似:
creationTimestamp: '2024-09-23T02:27:09.575-07:00'
id: '6386622402379156098'
kind: compute#instanceGroupManagerResizeRequest
name: example-request
requestedRunDuration:
nanos: 0
seconds: '86400'
resizeBy: 10
selfLink: https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instanceGroupManagers/example-mig/resizeRequests/example-request
selfLinkWithId: https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instanceGroupManagers/example-mig/resizeRequests/6386622402379156098
state: ACCEPTED
status:
lastAttempt:
error:
errors:
- code: QUOTA_EXCEEDED
message: Quota 'NVIDIA_A100_GPUS' exceeded. Limit: 1500 in region us-central1.
- code: ZONE_RESOURCE_POOL_EXHAUSTED_WITH_DETAILS
message: There are currently not enough resources available to fulfill the request. Expected time is indefinite.
- errorDetails:
- errorInfo:
- metadatas:
- estimatedAvailabilityTime: '9999-12-31T23:59:59.999999999Z'
zone: https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a
REST
如要查看區域 MIG 中的大小調整要求詳細資料,請使用
instanceGroupManagerResizeRequests.get
方法傳送GET
要求。GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/INSTANCE_GROUP_NAME/resizeRequests/RESIZE_REQUEST_NAME
如要查看區域 MIG 中的調整大小要求詳細資料,請使用
beta.regionInstanceGroupManagerResizeRequests.get
方法傳送GET
要求。GET https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/regions/REGION/regionInstanceGroupManagers/INSTANCE_GROUP_NAME/resizeRequests/RESIZE_REQUEST_NAME
更改下列內容:
PROJECT_ID
:區域 MIG 所在專案的 ID。ZONE
:MIG 所在的可用區。REGION
:MIG 所在的地區。INSTANCE_GROUP_NAME
:縮放要求所在的 MIG 名稱。RESIZE_REQUEST_NAME
:您要查看詳細資料的現有調整大小要求名稱。
輸出結果會與下列內容相似:
{
"kind": "compute#instanceGroupManagerResizeRequest",
"id": "6386622402379156098",
"creationTimestamp": "2024-09-23T02:27:09.575-07:00",
"name": "example-request",
"zone": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a",
"resizeBy": 10,
"requestedRunDuration": {
"seconds": "86400",
"nanos": 0
},
"state": "SUCCEEDED",
"status": {
"lastAttempt": {
"error": {
"errors": [
{
"code": "QUOTA_EXCEEDED",
"message": "Quota 'NVIDIA_A100_GPUS' exceeded. Limit: 1500 in region us-central1."
},
{
"code": "ZONE_RESOURCE_POOL_EXHAUSTED_WITH_DETAILS",
"message": "There are currently not enough resources available to fulfill the request. Expected time is indefinite.",
"errorDetails": [
{
"errorInfo":{
"metadatas":{
"estimatedAvailabilityTime": "9999-12-31T23:59:59.999999999Z"
}
}
}
]
}
]
}
}
},
"selfLink": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instanceGroupManagers/example-mig/resizeRequests/example-request",
"selfLinkWithId": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instanceGroupManagers/example-mig/resizeRequests/6386622402379156098"
}
取消 MIG 中的大小調整要求
您可以在 MIG 中取消重新調整大小要求,停止 MIG 嘗試建立所要求的 VM 數量。您只能取消已接受 (ACCEPTED
) 的大小調整要求。取消大小調整要求後,您可以刪除該要求,也可以讓 Compute Engine 在 14 天後自動刪除。
如要同時取消多個調整大小要求,請使用 Google Cloud 控制台或 Google Cloud CLI。如要取消單一調整大小要求,請選取下列任一選項:
主控台
前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
在「Name」欄中,按一下包含調整大小要求的 MIG 名稱。
MIG 的總覽頁面隨即開啟。
在「大小調整要求」列中,按一下
「編輯大小調整要求」。系統會顯示「Resize requests」窗格。
選取要取消的大小調整要求。
依序按一下
「取消」和「確認」。
gcloud
如要在區域 MIG 中取消規模調整要求,請使用
instance-groups managed resize-requests cancel
指令。gcloud compute instance-groups managed resize-requests cancel INSTANCE_GROUP_NAME \ --resize-requests=RESIZE_REQUEST_NAMES \ --zone=ZONE
如要在區域 MIG 中取消規模調整要求,請使用
beta instance-groups managed resize-requests cancel
指令。gcloud beta compute instance-groups managed resize-requests cancel INSTANCE_GROUP_NAME \ --resize-requests=RESIZE_REQUEST_NAMES \ --region=REGION
更改下列內容:
INSTANCE_GROUP_NAME
:已接受大小調整要求的 MIG 名稱。RESIZE_REQUEST_NAMES
:以半形逗號分隔的清單,列出指定區域 MIG 中已接受的調整大小要求名稱。例如,請指定request-1,request-2
。ZONE
:MIG 所在的可用區。REGION
:MIG 所在的地區。
REST
如要在區域 MIG 中取消調整大小要求,請使用
instanceGroupManagerResizeRequests.cancel
方法傳送POST
要求。POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/INSTANCE_GROUP_NAME/resizeRequests/RESIZE_REQUEST_NAME/cancel
如要在地區 MIG 中取消大小調整要求,請使用
beta.regionInstanceGroupManagerResizeRequests.cancel
方法傳送POST
要求。POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/regions/REGION/regionInstanceGroupManagers/INSTANCE_GROUP_NAME/resizeRequests/RESIZE_REQUEST_NAME/cancel
更改下列內容:
PROJECT_ID
:含有已接受的調整大小要求的現有區域 MIG 所在專案 ID。ZONE
:MIG 所在的可用區。REGION
:MIG 所在的地區。INSTANCE_GROUP_NAME
:MIG 名稱。RESIZE_REQUEST_NAME
:要取消的大小調整要求名稱。
刪除 MIG 中的大小調整要求
根據預設,Compute Engine 會在將要求狀態設為下列其中一種狀態後,在 14 天內自動刪除大小調整要求:
成功 (
SUCCEEDED
)失敗 (
FAILED
)已取消 (
CANCELLED
)
不過,您可以在期限前立即刪除重新調整大小要求,如本節所述。
刪除成功的大小調整要求不會刪除透過要求建立的 VM。MIG 會在 VM 要求的執行時間結束時自動刪除這些 VM。不過,如果工作已完成執行,且您不再需要 VM,請刪除 VM。
如要同時刪除多個調整大小要求,請使用 Google Cloud 控制台或 gcloud CLI。否則,如要刪除單一調整大小要求,請選取下列任一選項:
主控台
前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
在「Name」欄中,按一下包含調整大小要求的 MIG 名稱。
MIG 的總覽頁面隨即開啟。
在「大小調整要求」列中,按一下
「編輯大小調整要求」。系統會顯示「Resize requests」窗格。
選取要刪除的大小調整要求。
依序按一下
「Delete」和「Confirm」。
gcloud
如要刪除區域 MIG 中的大小調整要求,請使用
instance-groups managed resize-requests delete
指令。gcloud compute instance-groups managed resize-requests delete INSTANCE_GROUP_NAME \ --resize-requests=RESIZE_REQUEST_NAMES \ --zone=ZONE
如要刪除地區 MIG 中的大小調整要求,請使用
beta instance-groups managed resize-requests delete
指令。gcloud beta compute instance-groups managed resize-requests delete INSTANCE_GROUP_NAME \ --resize-requests=RESIZE_REQUEST_NAMES \ --region=REGION
更改下列內容:
INSTANCE_GROUP_NAME
:包含成功、失敗或已取消的大小調整要求的 MIG 名稱。RESIZE_REQUEST_NAMES
:以半形逗號分隔的清單,列出要從 MIG 中刪除的大小調整要求名稱。例如,指定request-1,request-2
。ZONE
:MIG 所在的可用區。REGION
:MIG 所在的地區。
REST
如要在區域 MIG 中刪除大小調整要求,請使用
instanceGroupManagerResizeRequests.delete
方法傳送DELETE
要求。DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/INSTANCE_GROUP_NAME/resizeRequests/RESIZE_REQUEST_NAME
如要刪除地區 MIG 中的大小調整要求,請使用
beta.regionInstanceGroupManagerResizeRequests.delete
方法傳送DELETE
要求。DELETE https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/regions/REGION/regionInstanceGroupManagers/INSTANCE_GROUP_NAME/resizeRequests/RESIZE_REQUEST_NAME
更改下列內容:
PROJECT_ID
:專案 ID,其中包含成功、失敗或已取消的縮放要求的現有區域 MIG。ZONE
:MIG 所在的可用區。REGION
:MIG 所在的地區。INSTANCE_GROUP_NAME
:MIG 名稱。RESIZE_REQUEST_NAME
:要刪除的調整大小要求名稱。
後續步驟
- 瞭解如何查看 MIG 中代管 VM 的相關資訊。