Ingress-Nginx 全局超时配置及生效方式
Ingress-Nginx 全局超时完整配置(可直接落地)
一、全局 ConfigMap 配置(所有Ingress生效)
YAML
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-ingress-controller
namespace: ingress-nginx
data:
# 与后端Pod建立TCP连接超时
proxy-connect-timeout: "10"
# 读取后端响应间隔超时
proxy-read-timeout: "180"
# 向后端发送请求间隔超时
proxy-send-timeout: "180"
# 读取客户端请求头超时
client-header-timeout: "60"
# 读取客户端请求体超时
client-body-timeout: "60"
# 后端重试总超时
proxy-next-upstream-timeout: "10"
# 后端最大重试次数
proxy-next-upstream-tries: "3"
# 保持连接超时
keep-alive-timeout: "60"
二、单条 Ingress 注解配置(仅当前规则生效,优先级高于全局)
YAML
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ingress
namespace: default
annotations:
nginx.ingress.kubernetes.io/proxy-connect-timeout: "10"
nginx.ingress.kubernetes.io/proxy-read-timeout: "180"
nginx.ingress.kubernetes.io/proxy-send-timeout: "180"
nginx.ingress.kubernetes.io/client-header-timeout: "60"
nginx.ingress.kubernetes.io/client-body-timeout: "60"
nginx.ingress.kubernetes.io/proxy-next-upstream-timeout: "10"
nginx.ingress.kubernetes.io/proxy-next-upstream-tries: "3"
spec:
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: app-svc
port:
number: 80
三、关键参数极简说明
| 参数 | 作用 | 建议值 |
|---|---|---|
| proxy-connect-timeout | 连接后端TCP握手超时 | 10s |
| proxy-read-timeout | 后端长时间无响应间隔超时 | 180s(接口/报表长请求用) |
| proxy-send-timeout | 向后端传数据间隔超时 | 180s |
| keep-alive-timeout | 客户端长连接保持时间 | 60s |
四、生效方式
-
应用 ConfigMap:
kubectl apply -f nginx-ingress-configmap.yaml -
无需重启Ingress控制器,配置自动热加载
-
单应用特殊超时直接加 Ingress annotation 即可覆盖全局