考虑这个 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 访问 myservice:
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 被随机重新启动并且我的连接被丢弃了。