设置工作站

了解如何设置和使用工作站集群、工作站配置和工作站。在开始之前,请查看本快速入门的前提条件,然后按以下步骤操作:

  1. 创建工作站集群
  2. 创建工作站配置
  3. 创建并启动工作站

如果您不再需要本快速入门中创建的资源,请务必进行清理,以免产生额外费用。


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

操作演示


准备工作

本指南介绍了管理员设置 Cloud Workstations 的步骤,以及开发者使用工作站的步骤。

如需设置 Cloud Workstations,请完成以下步骤:

  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. Enable the Cloud Workstations API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  9. 所需的角色

    如需获得管理和使用工作站所需的权限,请让您的管理员为您授予以下 IAM 角色:

    • 创建和管理工作站集群和配置:项目的 Cloud Workstations Admin (roles/workstations.admin) 角色
    • 使用配置创建工作站: 项目或工作站配置的 Cloud Workstations Creator (roles/workstations.workstationCreator) 角色
    • 使用工作站: 工作站上的 Cloud Workstations User (roles/workstations.user)。系统会自动在您创建的工作站上授予此权限。

    如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

    您也可以通过自定义角色或其他预定义角色来获取所需的权限。

    如需详细了解所有 Cloud Workstations 角色,请参阅使用 IAM 进行访问权限控制

创建工作站集群

第一步是创建工作站集群。工作站集群定义了特定区域中的一组工作站,在其生命周期内管理工作站,并提供可配置的网络连接。

工作站集群与 Google Kubernetes Engine (GKE) 集群无关。 如需创建工作站集群,请按照以下步骤操作:

  1. 在控制台中,进入 Cloud Workstations > 集群管理页面。

    前往集群管理

  2. 在工作站的集群管理页面中,点击 add_box创建

  3. 名称字段中,输入 test-cluster 作为工作站集群的名称。

  4. 选择距离您最近的区域

  5. 跳过网络设置

  6. 点击创建,以开始创建集群过程。

创建工作站集群最多可能需要 20 分钟,但在大多数情况下只需执行一次。

创建工作站配置

本快速入门将引导您完成最基本的工作站配置。如需快速开始,请接受用于定义机器设置、自定义环境和添加用户的默认设置。

如需配置工作站配置的基本信息,请按以下步骤操作:

  1. 在控制台中,进入 Cloud Workstations > 工作站配置

    前往工作站配置

  2. 工作站配置页面中,点击 add_box创建

  3. 名称字段中,输入 test-configuration 作为工作站配置的名称。

  4. 从可用的工作站集群列表中选择 test-cluster,然后点击继续。 如果没有可用的工作站集群,请确保您已完成创建工作站集群的步骤。

  5. Quick start workstations(快速启动工作站)部分,选择已停用,以降低费用。

  6. 如果您要为团队自定义工作站配置,可以定义机器设置、自定义环境设置,并将用户添加到 IAM 政策。在本练习中,您可以跳过这些步骤。

  7. 如需创建工作站配置,请点击创建

如需详细了解如何使用本快速入门中跳过的选项创建工作站配置,请参阅有关工作站配置的详细部分。

创建和启动工作站

工作站是管理员或平台团队在工作站配置中定义的预配置开发环境。 如需创建工作站,请按照以下步骤操作:

  1. 在 Google Cloud 控制台中,前往 Cloud Workstations > 工作站页面。

    进入“工作站”

  2. 点击 add_box创建

    如果项目中没有任何工作站配置,或者您无权查看配置,则创建链接可能被停用。请让贵组织的 Cloud Workstations Admin 为您创建工作站配置。

  3. 接受默认的工作站名称

  4. 点击配置字段中的 arrow_drop_down 展开箭头,然后选择工作站配置来定义工作站。例如,如果您在上一步中将工作站配置命名为 test-configuration,请从列表中选择该配置。

  5. 点击创建以创建工作站。

现在,您已经创建了工作站,接下来可以启动工作站,然后发布工作站以开始开发:

  1. 点击工作站
  2. 在可用工作站列表中找到您创建的工作站,选中旁边的复选框,然后点击启动。这会启动您的工作站,并将其与父工作站配置匹配。
  3. 如果系统提示您启动工作站,请点击启动进行确认。 状态变为正在启动,并且在启动操作正在进行时,状态图标 refresh 会旋转。启动工作站可能需要几分钟时间。
  4. 工作站准备就绪后,状态将变为正在运行,并且状态图标会变为 check_circle 对勾标记。
  5. 点击启动。 工作站默认连接到端口 80

  6. 以下示例展示了 Cloud Workstations 基本编辑器的欢迎页面。 您的网页可能会因工作站配置的定义方式而异:

    Cloud Workstations 基本编辑器

    如需详细了解如何通过 SSH 进行连接,请参阅 SSH 支持

    如需详细了解如何连接到工作站上运行的网络应用,请参阅访问工作站上运行的 HTTP 服务器

清理

为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请务必删除不再需要的资源。

如需从 Google Cloud 控制台或 gcloud CLI 中删除 Google Cloud 项目,请执行以下操作:

控制台

  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.

gcloud

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

    Go to Manage resources

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

如需详细了解如何删除其他资源(例如工作站集群、工作站配置和工作站),请参阅删除资源

后续步骤