Nginx Ingress 超时/连接丢失

Nginx Ingress timeouts / connection drops

考虑这个 NodePort 服务:

k describe service myservice
...
Type:                     NodePort
IP:                       10.15.248.153
Port:                     myservice  8080/TCP
TargetPort:               8080/TCP
NodePort:                 myservice  30593/TCP
Endpoints:                10.12.223.56:8080

考虑一个正好需要 120 秒的请求:

# time curl -vkH 'http://myservce:8080/test?timeout=120'
*   Trying 10.15.248.153...
* TCP_NODELAY set
* Connected myservice (10.15.248.153) port 8080 (#0)
...
< HTTP/1.1 200

real    2m0.023s
user    0m0.009s
sys 0m0.009s

这很好。所以我配置了 nginx-ingress 超时:

nginx.ingress.kubernetes.io/proxy-send-timeout: "900"
nginx.ingress.kubernetes.io/proxy-read-timeout: "900"
nginx.ingress.kubernetes.io/proxy-connect-timeout: "60"

我可以确认它在 nginx.conf:

proxy_connect_timeout                   60s;
proxy_send_timeout                      900s;
proxy_read_timeout                      900s;

所以现在,我尝试进入 nginx ingress pod 并尝试通过 nginx-ingress 访问我的服务:

time curl -vkH 'http://127.0.0.1/myservice/test?timeout=120'

但这次我得到空响应 - 有时在 35 秒后,有时在 90 秒后,但它会到达那里:

* Curl_http_done: called premature == 0
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server

我不知道会发生什么。看起来好像 nginx 随机重新启动并且我的连接断开了。

出于某种原因,nginx 进程不断重新加载 - 每 30 秒一次。每次重新加载时,所有连接都会断开。

解决办法是设置:

worker-shutdown-timeout: "900s"

在 nginx-ingress config-map.