# 502 网关错误（Ingress/Nginx）— 上游连接过早关闭

- **ID:** `kubernetes/ingress-nginx-502-bad-gateway-upstream`
- **领域:** kubernetes
- **类别:** network_error
- **错误码:** `502`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

后端服务（上游）无响应或过早关闭连接，通常由于负载过高或超时配置错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| ingress-nginx 1.7.0 | active | — | — |
| Kubernetes 1.27 | active | — | — |
| nginx 1.23 | active | — | — |

## 解决方案

1. ```
   检查上游服务健康状态：`kubectl get pods -l app=<service>` 和 `kubectl logs <pod>`。如果负载过高，增加资源或启用水平 Pod 自动伸缩。
   ```
2. ```
   添加 Ingress 注释以调整超时：`nginx.ingress.kubernetes.io/proxy-read-timeout: '600'` 和 `nginx.ingress.kubernetes.io/proxy-send-timeout: '600'`。
   ```

## 无效尝试

- **** — Only temporarily clears the issue; the upstream problem remains. (60% 失败率)
- **** — Does not address the upstream service's inability to handle connections. (70% 失败率)
- **** — May mask the issue but can cause resource exhaustion if upstream is truly broken. (50% 失败率)
