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

通过GKE Ingress暴露gRPC服务遇阻,求排查方案

问题诊断与解决方案

核心问题分析

你的gRPC服务无法通过GKE Ingress正常工作,主要源于以下几个关键问题:

1. 访问端口错误

你的Ingress配置了TLS终止,GKE Ingress默认会将80端口的请求重定向到443端口,但gRPC客户端不支持HTTP重定向机制。直接访问80端口时,要么触发TLS握手错误(Ingress在80端口不提供TLS服务),要么因无法处理重定向导致超时。

2. 后端TLS证书验证失败

你的gRPC服务器使用自签名证书启用TLS,而GKE Ingress创建的后端服务默认会验证后端证书的有效性。自签名证书不被GCP信任根认可,导致Ingress无法与后端gRPC服务器建立稳定连接,最终出现超时。

3. Service协议注解配置不准确

你设置了cloud.google.com/app-protocols: {"gateway":"HTTP2"},但你的gRPC服务器基于TLS(HTTPS)运行,正确的协议注解应为{"gateway":"HTTPS"}——该注解用于告知GKE Ingress后端服务的协议类型,错误配置会导致通信协议不匹配。


分步解决方案

第一步:使用正确端口访问

gRPC请求需指向Ingress的443端口,而非80端口:

grpcurl -insecure <ingress-ip>:443 list

-insecure参数用于跳过客户端对Ingress证书的验证(若Ingress使用自签名/内部证书)。

第二步:禁用后端证书验证(适配自签名证书场景)

创建或修改BackendConfig,添加禁用证书验证的配置:

apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  name: health-checker
spec:
  healthCheck:
    type: HTTP
    httpHealthCheck:
      port: 81
      requestPath: /health
  backendService:
    protocol: HTTPS
    securitySettings:
      disableCertificateValidation: true  # 禁用后端证书验证
  timeoutSec: 30

更新Service注解,确保BackendConfig正确关联并修正协议配置:

apiVersion: v1
kind: Service
metadata:
  name: gateway
  annotations:
    cloud.google.com/app-protocols: '{"gateway":"HTTPS"}'  # 修正为HTTPS协议
    cloud.google.com/backend-config: '{"ports": {"80":"health-checker"}}'
    cloud.google.com/neg: '{"ingress":true}'
spec:
  type: NodePort
  ports:
  - name: health-checker
    port: 81
    targetPort: 81
  - name: gateway
    port: 80
    targetPort: 80
  selector:
    app: gateway  # 替换为你的Deployment标签

第三步:确认Ingress后端健康状态

执行以下命令检查Ingress后端状态:

kubectl get ingress gateway
kubectl describe ingress gateway

确保后端服务的Backend状态为HEALTHY,若显示UNHEALTHY,检查BackendConfig的健康检查路径、端口是否与HTTP健康检查器匹配。


验证

完成配置后,重新执行gRPC请求:

grpcurl -insecure <ingress-ip>:443 list

此时应能正常获取gRPC服务列表,与直接访问NodePort的结果一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 02:31:03