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

将Google Cloud Function配置为负载均衡后端时Serverless NEG无法显示函数的问题

Google Cloud Function作为负载均衡后端的可访问要求

要让Cloud Function能被Cloud Function类型的Serverless NEG识别并挂载到负载均衡,必须满足以下硬性条件:

  • 必须是第二代(2nd gen)函数:第一代Cloud Function不支持直接关联Cloud Function类型的Serverless NEG,只有第二代函数才会出现在该类型NEG的可选列表中。如果你的函数是第一代,哪怕配置了正确的ingress参数也不会被识别。
  • 部署时ingress配置必须为internal-and-gclb:部署函数时必须指定--ingress-settings=internal-and-gclb,这个配置限制函数仅接受来自内部VPC和Google Cloud负载均衡器的请求,是函数能被NEG关联的必要前提。可通过gcloud functions describe <函数名>查看ingressSettings字段确认配置是否生效。
  • 只能是HTTP触发的函数:事件触发的Cloud Function无法通过负载均衡直接访问,只有HTTP触发的第二代函数才支持这种场景。
  • NEG区域必须与函数部署区域完全匹配:第二代Cloud Function是区域级资源,创建Serverless NEG时必须选择和函数完全一致的区域,否则会提示“当前所选区域和项目中无Cloud Function存在”。
  • 必须允许未认证访问:要么部署时加上--allow-unauthenticated参数,要么在IAM权限中给allUsers分配roles/cloudfunctions.invoker角色。因为负载均衡对函数的调用属于未认证请求,没有这个权限会导致调用失败。

另外需要注意:你在Cloud Run类型NEG中看到的函数,本质是第二代Cloud Function底层托管的Cloud Run服务,但这不是官方推荐的Cloud Function关联负载均衡的方式,建议使用Cloud Function类型的NEG来关联,以获得更贴合Cloud Function的管理体验。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 18:46:05