创建一个托管式实例组 (MIG)

了解如何使用 Google Cloud 控制台在 Compute Engine 中创建托管式实例组 (MIG)

MIG 是可以作为单个实体进行管理的虚拟机 (VM) 实例的集合。MIG 支持自动修复、自动扩缩、负载均衡、多可用区覆盖和有状态工作负载等功能。

MIG 中的每个虚拟机都基于实例模板。您需要先创建实例模板,然后才能创建 MIG。


如需在 Google Cloud 控制台中直接遵循有关此任务的分步指导,请点击操作演示

操作演示


准备工作

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. 如果您要使用现有项目来完成本指南,请验证您是否拥有完成本指南所需的权限。如果您创建了新项目,则您已拥有所需的权限。

  4. Verify that billing is enabled for your Google Cloud project.

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. 如果您要使用现有项目来完成本指南,请验证您是否拥有完成本指南所需的权限。如果您创建了新项目,则您已拥有所需的权限。

  7. Verify that billing is enabled for your Google Cloud project.

  8. 启用 Compute Engine API。

    启用 API

  9. 所需的角色

    如需获得创建实例模板和 MIG 所需的权限,请让您的管理员为您授予项目的 Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1) IAM 角色。如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

    此预定义角色包含创建实例模板和 MIG 所需的权限。如需查看所需的确切权限,请展开所需权限部分:

    所需权限

    如需创建实例模板和 MIG,需要具备以下权限:

    • 创建实例模板: compute.instanceTemplates.create
    • 创建 MIG: compute.instanceGroupManagers.create
    • 删除 MIG: compute.instanceGroupManagers.delete

    您也可以使用自定义角色或其他预定义角色来获取这些权限。

创建实例模板

  1. 在 Google Cloud 控制台中,转到实例模板页面。

    转到“实例模板”

  2. 点击创建实例模板

  3. 如需创建使用 Ubuntu 操作系统的模板,请执行以下步骤:

    1. 启动磁盘部分,点击更改

    2. 操作系统列表中,选择 Ubuntu

    3. 点击选择

    使用此模板创建的所有虚拟机都会采用这些设置。记下模板的名称,本教程稍后会用到。

  4. 如需创建实例模板,请点击创建

Compute Engine 需要几分钟来创建模板。模板准备就绪后,就会列在实例模板页面上。

使用实例模板创建 MIG

  1. 前往实例组页面。

    转到“实例组”

  2. 点击创建实例组,然后执行以下步骤:

    1. 名称字段中,接受默认名称或输入 quickstart-instance-group-1

    2. 实例模板列表中,选择您之前创建的实例模板。

    3. 位置部分中,确保选中单个可用区

    4. 区域字段中,选择要创建 MIG 的区域。

    5. 自动扩缩部分,接受默认设置或者修改这些设置。

  3. 要创建 MIG,请点击创建

等待几分钟,让 Compute Engine 创建实例组及虚拟机。 实例组准备就绪后,就会显示在实例组页面上。

您已成功创建托管式实例组。

清理

为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。

删除资源

如果您使用的是现有 Google Cloud 项目,请删除您创建的资源,以避免您的账号产生费用:

  1. 前往实例组页面。

    转到“实例组”

  2. 选择要删除的实例组。

  3. 点击删除

  4. 出现提示时,输入所需的值,然后点击删除

删除项目

为了避免产生费用,最简单的方法是删除您为本教程创建的项目。

要删除项目,请执行以下操作:

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

后续步骤