安装和设置

本教程使用 gcloud 命令行工具逐步演示了 Deployment Manager 的用法。请按照设置步骤准备本地环境以使用 Deployment Manager。

创建项目

  1. In the Google Cloud console, go to the project selector page.

    Go to project selector

  2. 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.

为您要管理的 Google Cloud 资源启用 API

Deployment Manager 使用其他 Google Cloud 服务的 API 来创建和管理您的资源。要创建这些资源,您必须先为您的项目启用服务 API。

在本演示中,您将部署 Compute Engine 资源,因此需要启用 Compute Engine API。

启用 Compute Engine API

接下来,启用 Deployment Manager:

启用 Deployment Manager API

安装 Google Cloud CLI

Google Cloud CLI 提供一个命令行工具 (gcloud),利用该工具,您可以轻松地与 Deployment Manager 进行交互。

如需安装 gcloud CLI,请执行以下操作:

  1. 下载 gcloud 并对其进行身份验证

    或者,您也可以使用 Cloud Shell,该工具安装有 gcloud

  2. 设置项目 ID。

    每个命令都需要一个项目 ID。设置默认项目 ID,这样您就不必每次都提供此信息。请记住将 myproject 替换为您自己的项目 ID

    gcloud config set project myproject
    
  3. 设置默认地区和区域。某些 Google Cloud 资源要求提供地区或区域。您可以设置默认地区或区域,类似于默认项目。如需设置默认可用区或区域,请使用 gcloud config set。 在本使用场景中,使用 us-central1 作为地区,使用 us-central1-f 作为区域:

    gcloud config set compute/region us-central1
    gcloud config set compute/zone us-central1-f
    

克隆 Deployment Manager GitHub 代码库

Deployment Manager GitHub 代码库包含由 Google 和 Deployment Manager 社区创建的示例,包括本演示中使用的示例。

git clone https://github.com/GoogleCloudPlatform/deploymentmanager-samples

# open the samples folder
cd deploymentmanager-samples/examples/v2/step_by_step_guide

您现在已经设置了环境,可以开始创建部署了。