You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Deployment Manager中Cloud Endpoints资源类型缺失问题咨询

解决Google Deployment Manager集成Cloud Endpoints的方案

我之前在编排Google Cloud资源时也碰到过完全一样的问题——Google Deployment Manager目前确实没有原生的Cloud Endpoints资源类型,不过别担心,有两种实用方案能帮你实现需求:既完成所有资源(VM、网络、防火墙、Endpoints、Cloud SQL)的部署,又能把Endpoints生成的config_id自动传到虚拟机元数据里。

方案一:用自定义Type Provider包装Cloud Endpoints API

Deployment Manager支持通过Type Provider来调用Google Cloud的REST API,咱们可以用它来创建Cloud Endpoints服务,这样就能直接获取到config_id作为输出值,方便后续引用。

具体步骤示例:

  1. 先创建指向Endpoints API的Type Provider
    这个资源相当于给Deployment Manager提供操作Endpoints的能力:

    resources:
    - name: endpoints-type-provider
      type: gcp-types/deploymentmanager-v2:deploymentmanager.typeProvider
      properties:
        options:
          validationOptions:
            schemaValidation: IGNORE
        descriptorUrl: https://cloudendpoints.googleapis.com/$discovery/rest?version=v1
    
  2. 通过Type Provider创建你的Endpoints服务
    假设你已经准备好OpenAPI配置文件(比如openapi.yaml),可以这样定义Endpoints资源:

    - name: my-endpoints-service
      type: $(ref.endpoints-type-provider.projects.services)
      properties:
        parent: projects/[你的项目ID]
        service: [你的服务名].endpoints.[你的项目ID].cloud.goog
        openapiConfig: $(cat openapi.yaml)
    
  3. 把config_id引用到VM元数据
    在虚拟机资源的元数据里,直接用模板引用Endpoints资源的configId输出即可:

    - name: my-vm
      type: compute.v1.instance
      properties:
        # 这里填你的VM其他配置(机器类型、镜像等)
        metadata:
          items:
          - key: endpoints-config-id
            value: $(ref.my-endpoints-service.configId)
    

方案二:用Action资源执行gcloud命令部署Endpoints

如果觉得自定义Type Provider有点复杂,也可以用Deployment Manager的action类型,直接调用gcloud endpoints services deploy命令来部署Endpoints,再提取出config_id。

具体步骤示例:

  1. 定义Action资源部署Endpoints
    这里借助Cloud Shell环境来执行gcloud命令,同时提取输出里的config_id:

    - name: deploy-endpoints
      type: gcp-types/cloud-shell-v1:users.environments
      properties:
        userId: me
        environmentId: default
        publicKeys: []
      actions:
        - name: deploy-endpoints-service
          action: gcloud endpoints services deploy openapi.yaml --project [你的项目ID]
          outputs:
            - name: config-id
              # 用grep提取输出里的config_id,你可以根据实际输出调整正则
              valueFrom: $(action.deploy-endpoints-service.stdout | grep -oP 'config_id:\s*\K\S+')
    
  2. 传递config_id到VM元数据
    同样在VM资源里引用这个输出值:

    - name: my-vm
      type: compute.v1.instance
      properties:
        # 你的VM其他配置
        metadata:
          items:
          - key: endpoints-config-id
            value: $(ref.deploy-endpoints.config-id)
    

额外提醒

  • 不管用哪种方案,都要确保Deployment Manager的服务账号拥有endpoints.services.create、endpoints.services.update权限,以及部署VM、Cloud SQL等其他资源的对应权限。
  • 如果你的OpenAPI配置文件很大,建议先把它上传到Cloud Storage,然后在命令里用gsutil cp下载到执行环境后再部署。

内容的提问来源于stack exchange,提问作者Aicos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:33:10