增加proxy_send_timeout和proxy_read_timeout入口nginx

时间:2018-12-03 11:07:39

标签: nginx kubernetes google-kubernetes-engine

我正在GKE上运行部署,

使用quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.12.0图片作为nginx-ingress-controller

我正在尝试增加proxy_send_timeoutproxy_read_timeout,紧随此link

这是我的入口配置:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-ingress
  namespace: production
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "360s"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "360s"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "360s"
    nginx.ingress.kubernetes.io/proxy-body-size: 100m
    nginx.ingress.kubernetes.io/client-body-buffer-size: 100m
spec:
  rules:
  - host: app.my.com
    http:
      paths:
      - backend:
          serviceName: front-app
          servicePort: 80
  - host: api.my.com
    http:
      paths:
      - backend:
          serviceName: backend-app
          servicePort: 80
  - host: api.old.com
    http:
      paths:
      - backend:
          serviceName: backend-app
          servicePort: 80
  tls:
  - hosts:
    - app.my.com
    - api.my.com
    secretName: tls-secret-my-com
  - hosts:
    - api.old.com
    secretName: tls-secret-old-com

但这仍然不会更改proxy_send_timeoutproxy_read_timeout

耗时超过60秒(默认为nginx超时)的请求已关闭

我看到此日志:

[error] 20967#20967: * upstream prematurely closed connection while reading response header from upstream, client: 123.456.789.12, server: api.my.com, request: "GET /v1/example HTTP/2.0", upstream: "http://11.22.3.44:4000/v3/example", host: "api.my.com", referrer: "https://app.my.com/"

当我进入Nginx吊舱时:

> kubectl exec -it nginx-ingress-controller-xxxx-yyyy -n ingress-nginx -- bash
> cat /etc/nginx/nginx.conf

输出:

server {
    server_name _ ;

    listen 80 default_server  backlog=511;
    location / {
        # Custom headers to proxied server

        proxy_connect_timeout                   5s;
        proxy_send_timeout                      60s;
        proxy_read_timeout                      60s;

proxy_send_timeoutproxy_read_timeout设置为60s,而不是我在入口配置的360s

所以我尝试手动更改nginx conf上的超时,但是我没有在客户端上获得超时,但是每次重新启动nginx时,这些值都会返回到默认的60s < / p>

如何正确配置入口的超时时间?

3 个答案:

答案 0 :(得分:6)

基于:https://github.com/kubernetes/ingress-nginx/issues/2007

尝试将注释中的值更改为“ 360”。该值必须是数字。

答案 1 :(得分:1)

根据Kubernetes documentation,应将数字值视为字符串。

示例:

  kind: Ingress
  metadata:
    name: webapp-domain-local
    annotations:
      nginx.ingress.kubernetes.io/proxy-connect-timeout: "10"
      nginx.ingress.kubernetes.io/proxy-read-timeout: "1"
  spec:
    rules:
    - host: webapp.domain.local
      http:
        paths:
        - backend:
            serviceName: webapplication
            servicePort: 8080```

答案 2 :(得分:0)

使用如下所示的注解

     kubernetes.io/ingress.class: nginx
     kubernetes.io/ingress.allow-http: "false"
     nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
     nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"

它应该反映在nginx conf文件中,如下


                        proxy_send_timeout                      3600s;
                        proxy_read_timeout                      3600s;