管理服务生命周期

本页面介绍如何使用 Google Cloud CLI gcloud endpoints services 命令管理代管式服务的生命周期。

对于高级用例,您可以使用 Service Management API 以编程方式管理服务。如需了解详情,请参阅 Service Management API 使用入门

简介

托管式服务是一种简单的资源,用于以逻辑方式表示与 Service Infrastructure 集成的服务,例如 Gmail API 和 Spanner API。托管式服务本身只有两个不可变属性(服务名称生产者项目),但托管式服务的实现可以提供范围广泛的各种功能。例如,Cloud Storage API 可为数百万开发者和企业提供全球级对象存储。

托管式服务具有一组服务使用方、不可变服务配置历史记录以及不可变服务发布历史记录。最新服务发布引用的服务配置表示服务的当前状态,其中包括服务所有方面的内容(如显示名称、指标定义、速率限制等)。如需了解相关规范,请参阅 google.api.Service

我们将在此页面中介绍如何创建和管理您的服务生命周期。如需详细了解服务管理,请参阅方法指南

创建服务

要创建服务,您需要完成以下步骤。

  1. 在计算机上安装并初始化 gcloud CLI

  2. 创建一个专用生产者项目以托管您的服务。专用项目可为您的服务提供最佳安全性和隔离性。您还可以将服务的所有权转让给其他团队,甚至是其他公司。

  3. 为您的项目启用 Service Management API 和 Service Control API。

  4. 为您的项目启用 Cloud Billing。要将您的服务与 Service Infrastructure 集成,您需要依赖于几种付费 Google Cloud 产品,包括 Service Control API、Cloud Logging API 和 Cloud Monitoring API。

  5. 为您的服务准备简单的服务配置 yaml 文件,如下所示:

    # Filename: endpointsapis.yaml
    type: google.api.Service
    config_version: 3
    # Update the next line to use your own service name.
    name: endpointsapis.appspot.com
    # Update the next line to use your own producer project id.
    producer_project_id: endpointsapis
    
  6. 运行 gcloud 命令以通过部署空白服务配置来创建服务:

    gcloud endpoints services deploy endpointsapis.yaml
    

服务创建过程大约需要一分钟。之后,您应该就能在 Google Cloud 控制台的 端点页面上看到您的服务了。

列出服务

要列出项目中的服务,您可以使用以下命令:

gcloud endpoints services list --project endpointsapis

描述服务

要描述服务及其配置,您可以使用以下命令:

gcloud endpoints services describe endpointsapis.appspot.com

删除服务

如果您不再需要某项服务,可以使用以下命令将其删除:

gcloud endpoints services delete endpointsapis.appspot.com

注意:每项服务都具有 30 天的删除保留期。

取消删除服务

您可以使用以下命令在服务保留期限内取消删除服务:

gcloud endpoints services undelete endpointsapis.appspot.com

后续步骤

Service Management API 使用声明式模型进行服务管理。创建服务后,您需要推送不可变服务配置和服务发布,以实现所需的服务状态。您的服务配置用于配置 Google Cloud 基础架构服务以为您的服务提供支持,这些基础架构服务包括 Cloud Billing、Cloud Logging、Cloud Monitoring 和 Identity and Access Management。

如需详细了解服务配置,请参阅管理服务配置。如需详细了解服务发布,请参阅管理服务发布