Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set connect_timeout? #905

Closed
NICK-DUAN opened this issue Oct 12, 2020 · 12 comments
Closed

How to set connect_timeout? #905

NICK-DUAN opened this issue Oct 12, 2020 · 12 comments

Comments

@NICK-DUAN
Copy link

Kong default connect_timeout, read_timeout, write_timeout are 6,000, but it's not long enough with use a websocket connection, so I want to set a custom value. follow these issue: #354 #472 , but the way they did it's not work for me, so can you point out my problem?

apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
  annotations:
  name: ci-console-kong-ing
  namespace: ci
proxy:
  connect_timeout: 3000000
  protocol: http
  read_timeout: 3000000
  retries: 10
  write_timeout: 3000000
route:
  protocols:
    - http
---
apiVersion: v1
kind: Service
metadata:
  annotations:
    konghq.com/override: ci-console-kong-ing
  name: ci-webconsole-server
  namespace: ci
spec:
  ports:
    - name: http
      port: 8080
      protocol: TCP
      targetPort: 8080
  type: ClusterIP
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    konghq.com/strip-path: 'true'
    konghq.com/override: ci-console-kong-ing
    kubernetes.io/ingress.class: kong
  name: ci-webconsole-server-ing
  namespace: ci
spec:
  rules:
    - http:
        paths:
          - backend:
              serviceName: ci-webconsole-server
              servicePort: 8080
            path: /api/ci-ws/console
@NICK-DUAN
Copy link
Author

@hbagdi

@NICK-DUAN
Copy link
Author

and then i delete the annotations: konghq.com/override: ci-console-kong-ing from Ingress, but it not work, too.

@NICK-DUAN
Copy link
Author

NICK-DUAN commented Oct 12, 2020

And I get service detail:
curl https://127.0.0.1:8444/services -k

{
            "client_certificate": null,
            "connect_timeout": 3000000,
            "created_at": 1602484991,
            "host": "ci-webconsole-server.ci.8080.svc",
            "id": "be9e324b-0d96-519a-84bd-b559e17abc68",
            "name": "ci.ci-webconsole-server.8080",
            "path": "/",
            "port": 80,
            "protocol": "http",
            "read_timeout": 3000000,
            "retries": 5,
            "tags": null,
            "updated_at": 1602484991,
            "write_timeout": 3000000
}

But my websocket connection still make a 60s connection.

@hbagdi
Copy link
Member

hbagdi commented Oct 12, 2020

Hey @NICK-DUAN,
So it seems that the KongIngress configuration was correctly applied to Kong.
Do you mean to say that your websocket connection is still closed even after write and read timeouts in service have been changed to 3000000? If so, can you please describe the behavior you are seeing in more detail? Like, how do you measure time, and what happens after 60s? Do you see anything in logs of kong or the upstream service?

@NICK-DUAN
Copy link
Author

I used websocket to make a web terminal, before I create KongIngress resource, the connection will close after 60s.
Then I did create KongIngress and set connect_timeout, read_timeout, write_timeout for 180,000. But now the connection closes at an unstable time.

I don't know why and I am replacing the network environment to verify that the network environment is not the cause of the problem.

I will keep update.

@sumeet-singh04
Copy link

sumeet-singh04 commented Oct 14, 2020

And I get service detail:
curl https://127.0.0.1:8444/services -k

{
            "client_certificate": null,
            "connect_timeout": 3000000,
            "created_at": 1602484991,
            "host": "ci-webconsole-server.ci.8080.svc",
            "id": "be9e324b-0d96-519a-84bd-b559e17abc68",
            "name": "ci.ci-webconsole-server.8080",
            "path": "/",
            "port": 80,
            "protocol": "http",
            "read_timeout": 3000000,
            "retries": 5,
            "tags": null,
            "updated_at": 1602484991,
            "write_timeout": 3000000
}

But my websocket connection still make a 60s connection.

I am seeing a similar issue. Even after verifying that the service timeouts are set to 1200000, the connection timeouts after 60 secs.

kong-ingress-controller:0.9.1
kong:2.0.5

@NICK-DUAN
Copy link
Author

I changed my environment, and the result not changed, the websocket connection still close after 60s.

Sorry to forget to tell you the version:
kong-ingress-controller:0.9.0
kong:2.0

@mpwsh
Copy link

mpwsh commented Oct 19, 2020

Hi @NICK-DUAN , we had a similar issue today.

If your deployment is in AWS you should check your ELB idle timeout setting (By default is 60 seconds)
After changing this the issue was resolved.

Hope it helps

@NICK-DUAN
Copy link
Author

NICK-DUAN commented Oct 20, 2020

Hi @NICK-DUAN , we had a similar issue today.

If your deployment is in AWS you should check your ELB idle timeout setting (By default is 60 seconds)
After changing this the issue was resolved.

Hope it helps

Thanks marianopw.

But my Deployment was in TKE(Tencent Kubernetes Engine), So could you tell me what ELB idle exactly is? And I can find a same thing in TKE which can help me to resolve my problem?

@mpwsh
Copy link

mpwsh commented Oct 22, 2020 via email

@NICK-DUAN
Copy link
Author

I konw what the problem is.

This code should add to a Service instead of a Ingress:

annotations: 
  konghq.com/override: $YOUR_KONGINGRESS_NAME

And your kongIngress should set like this:

kind: KongIngress
apiVersion: configuration.konghq.com/v1
metadata:
  annotations:
    kubernetes.io/ingress.class: "kong"
    name: timeout-kong-ingress
proxy:
  protocol: http
  connect_timeout: 360000       # ms
  read_timeout: 360000
  write_timeout: 360000

And you also need a Ingress to route your request. The whole file is:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: websocket
spec:
  selector:
    matchLabels:
      app: websocket
  template:
    metadata:
      labels:
        app: websocket
    spec:
      containers:
      - name: websocket
        image: ksdn117/web-socket-test
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 8010
---
apiVersion: v1
kind: Service
metadata:
  name: websocket
  annotations:
    konghq.com/override: timeout-kong-ingress
spec:
  selector:
    app: websocket
  ports:
  - port: 80
    targetPort: 8010
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test2
  annotations:
    kubernetes.io/ingress.class: "kong"
    # konghq.com/strip_path: "true"
spec:
  rules:
    - http:
        paths:
        - path: /api/ws/test
          backend:
            serviceName: websocket
            servicePort: 80
---
kind: KongIngress
apiVersion: configuration.konghq.com/v1
metadata:
  annotations:
    kubernetes.io/ingress.class: "kong"
  name: timeout-kong-ingress
proxy:
  protocol: http
  connect_timeout: 360000
  read_timeout: 360000
  write_timeout: 360000

@rbabyuk-vs
Copy link

superb! @NICK-DUAN that helped! thank you. this was not obvious anyway))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants