502
kubernetes
network_error
ai_generated
true
502 网关错误(Ingress/Nginx)— 上游连接过早关闭
502 Bad Gateway (Ingress/Nginx) — upstream prematurely closed connection
ID: kubernetes/ingress-nginx-502-bad-gateway-upstream
80%修复率
88%置信度
1证据数
2023-06-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| ingress-nginx 1.7.0 | active | — | — | — |
| Kubernetes 1.27 | active | — | — | — |
| nginx 1.23 | active | — | — | — |
根因分析
后端服务(上游)无响应或过早关闭连接,通常由于负载过高或超时配置错误。
English
The backend service (upstream) is not responding or closes connections prematurely, often due to high load or misconfigured timeouts.
官方文档
https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#custom-timeouts解决方案
-
检查上游服务健康状态:`kubectl get pods -l app=<service>` 和 `kubectl logs <pod>`。如果负载过高,增加资源或启用水平 Pod 自动伸缩。
-
添加 Ingress 注释以调整超时:`nginx.ingress.kubernetes.io/proxy-read-timeout: '600'` 和 `nginx.ingress.kubernetes.io/proxy-send-timeout: '600'`。
无效尝试
常见但无效的做法:
-
60% 失败
Only temporarily clears the issue; the upstream problem remains.
-
70% 失败
Does not address the upstream service's inability to handle connections.
-
50% 失败
May mask the issue but can cause resource exhaustion if upstream is truly broken.