本文档介绍如何删除不再需要的代管式实例组 (MIG),以便您可以停止为它使用的资源付费。
准备工作
-
如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 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.
在 Google Cloud 控制台中,前往实例群组页面。
在列表中选择一个或多个要删除的组。
点击删除,以删除该实例组以及托管式实例组内的所有虚拟机。
- 了解如何获取、列出和删除实例模板
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 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.
如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
删除 MIG
当您删除托管式实例组时,该实例组内的所有虚拟机也将随之删除。如果您想保留任何虚拟机,请先放弃这些虚拟机,从实例组中移除这些虚拟机。然后再删除代管式实例组。
仅当您在 MIG 的实例模板中定义磁盘时将磁盘的自动删除属性设置为 true 时,才会删除 MIG 中的磁盘。如果磁盘的自动删除属性设置为 false,您可以在不再需要磁盘时手动清理磁盘。
当您使用Google Cloud console 或 gcloud CLI 删除托管式实例组及其实例时,所有挂接的自动扩缩器也会自动一并删除。不过,如果您使用 REST,必须先发出单独请求,通过
autoscalers.delete
方法或regionAutoscalers.delete
方法删除挂接的所有自动扩缩器。如果您恰好先删除了托管式实例组,仍然可以使用 REST 删除挂接的自动扩缩器。对于每个磁盘,您还可以覆盖自动删除属性,以指定在删除其关联实例时是否应删除该磁盘。
控制台
gcloud
使用
delete
命令。gcloud compute instance-groups managed delete INSTANCE_GROUP_NAME \ --zone ZONE
REST
为可用区或区域 MIG 资源调用
delete
方法。如果 MIG 挂接了自动扩缩器,则必须先使用autoscalers.delete
方法或regionAutoscalers.delete
方法删除自动扩缩器。DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/INSTANCE_GROUP_NAME
如果实例组是区域级托管式实例组,请将
zones/ZONE
替换为regions/REGION
。后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-06-25。
-