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

在Google Kubernetes Engine上连接SurrealDB时出现502 Bad Gateway错误

GKE部署SurrealDB后连接出现502 Bad Gateway问题排查

按照SurrealDB官方《在GKE(Google Kubernetes Engine)上部署》指南操作,前期所有步骤均成功,但首次执行连接命令时出现502 Bad Gateway错误,相关信息如下:

连接命令及报错

$ surreal sql -e http://1.2.3.4   # timestamps are omitted
ERROR surreal::cli: There was a problem with the database:
 There was an error processing a remote HTTP request: 
 HTTP status server error (502 Bad Gateway) for url (http://1.2.3.4/health)

Ingress状态

$ kubectl get ingress surrealdb-tikv
NAME             CLASS    HOSTS   ADDRESS   PORTS   AGE
surrealdb-tikv   <none>   *       1.2.3.4   80      3h5m

Pod日志(服务正常启动)

$ kubectl logs surrealdb-tikv-xxxxxxxxx-xxxxx
INFO surreal::env: Running 1.1.0+20240109.05682e3 for linux on x86_64
WARN surreal::dbs: ❌🔒 IMPORTANT: Authentication is disabled. This is not recommended for production use. 🔒❌
INFO surrealdb::kvs::ds: Connecting to kvs store at tikv://sdb-datastore-pd:2379
INFO surrealdb::kvs::ds: Connected to kvs store at tikv://sdb-datastore-pd:2379
INFO surrealdb::node: Started node agent
INFO surrealdb::net: Started web server on 0.0.0.0:8000

可能的原因及排查步骤

  • Ingress与Service端口不匹配
    SurrealDB Pod监听8000端口,需确认Ingress配置是否正确将80端口转发到Service的8000端口。执行以下命令查看Service配置:

    kubectl get service surrealdb-tikv -o yaml
    

    检查spec.ports.targetPort是否为8000,同时确认Ingress的backend.service.port是否指向该端口。

  • Service与Pod标签不匹配
    检查Service是否正确关联到Pod:

    kubectl get endpoints surrealdb-tikv
    

    若ENDPOINTS列无内容,说明Service的标签选择器与Pod标签不匹配,执行以下命令对比两者标签:

    kubectl describe pod surrealdb-tikv-xxxxxxxxx-xxxxx | grep Labels
    kubectl describe service surrealdb-tikv | grep Selector
    
  • GKE Ingress健康检查失败
    GKE Ingress控制器依赖健康检查判断后端服务状态,若配置错误会返回502:

    1. 在集群内Pod中测试健康端点:curl http://localhost:8000/health,确认返回200状态码。
    2. 登录GKE控制台查看该Ingress对应的健康检查配置,确认端口为8000、路径为/health、预期响应码为200。
  • 网络策略或防火墙限制
    检查集群是否存在网络策略阻止Ingress控制器访问SurrealDB Pod,或VPC防火墙规则是否允许外部访问集群内部8000端口。可临时禁用网络策略测试,或调整防火墙规则。

  • Ingress未完全就绪
    尽管Ingress已分配IP,GKE负载均衡器可能仍在配置中。等待数分钟后重试,或查看Ingress事件确认状态:

    kubectl describe ingress surrealdb-tikv
    

    需确保事件中显示"Successfully configured backend"等就绪提示。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 00:57:27