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

Cloud Endpoints+ESPv2+Cloud Run配置gRPC-web可行性问询

问题描述

我正在创建一个供Web端访问的gRPC服务,参考Google官方Cloud Run+ESPv2的Cloud Endpoints部署指南完成搭建,希望适配gRPC-web。目前可通过grpcurl直接调用gRPC服务,但向网关发起curl请求时出现503错误。我想确认:无需部署自定义Envoy容器作为网关的情况下,该配置是否可行?我不想丢失Cloud Endpoints的功能优势,据我理解若无法修改ESPv2的Envoy过滤器则无法实现。以下是我的相关配置,可提供更多文件协助排查。

ESPv2参数

ESPv2_ARGS: ^++^--cors_preset=basic++--cors_allow_methods=GET,POST,OPTIONS++--cors_allow_headers=Authorization,Content-Type,x-api-key,x-grpc-web,grpc-timeout++--cors_expose_headers=grpc-encoding,grpc-message,grpc-status++--enable_debug

Proto中的GetHealth方法

// Health check endpoint.
rpc GetHealth(HealthRequest) returns (HealthResponse);

端点配置

type: google.api.Service
config_version: 3

name: transcription-grpc-vtwpa1.endpoints.vtwpa1.cloud.goog
title: Endpoint for My Service

apis:
  - name: transcription.v1.TranscriptionService
    source_context:
      file_name: ./transcription.pb

backend:
  rules:
    - selector: "*"
      address: grpc://<location of service>
      protocol: h2
      deadline: 900.0

authentication:
  providers:
    - id: google_id_token
      issuer: https://accounts.google.com
      jwks_uri: https://www.googleapis.com/oauth2/v3/certs
      audiences: <AN-AUDIENCE>
  rules:
    - selector: transcription.v1.TranscriptionService.GetHealth
      requirements: []

usage:
  rules:
    - selector: transcription.v1.TranscriptionService.GetHealth
      allow_unregistered_calls: true
解答

可行性确认

无需部署自定义Envoy容器,仅用ESPv2搭配Cloud Endpoints就能实现gRPC-web适配。ESPv2本身内置了对gRPC-web的支持,不需要手动修改Envoy过滤器——它的默认配置已经包含处理gRPC-web请求的必要组件,只需确保相关参数和配置正确即可。

503错误排查方向

  • 后端服务可达性:检查ESPv2配置中backend.rules.address的服务地址是否正确,确保Cloud Run服务在ESPv2所在网络环境中可访问(比如同VPC、服务已正确暴露端口)。可在ESPv2容器内尝试用grpcurl直接调用后端服务,验证连通性。
  • ESPv2启动日志:开启--enable_debug参数后,查看ESPv2的Cloud Run日志,检查是否有后端连接失败、配置加载错误的日志信息,这通常能直接定位问题。
  • gRPC-web请求格式:确保curl请求符合gRPC-web规范:
    • 请求方法必须为POST
    • 需携带Content-Type: application/grpc-web+proto或application/grpc-web-text+proto头
    • 请求路径应为/transcription.v1.TranscriptionService/GetHealth(对应proto中的服务和方法名)
      示例请求:
    curl -X POST \
      -H "Content-Type: application/grpc-web+proto" \
      -H "x-grpc-web: 1" \
      --data-binary @health_request.bin \
      https://<你的网关地址>/transcription.v1.TranscriptionService/GetHealth
    
  • CORS配置验证:虽然你已设置CORS参数,但可检查是否有遗漏的头或方法,比如确认x-grpc-web已正确加入cors_allow_headers(你的配置已包含,此点无问题),也可尝试用OPTIONS请求测试CORS响应是否正常。
  • Cloud Endpoints配置生效:确认端点配置已正确部署到Cloud Endpoints,ESPv2已加载最新配置。可通过gcloud endpoints services describe命令验证配置状态。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 03:57:06