Kubernetes - How to Solve Gateway Timeout with Http Statuscode Error 504

September 16, 2022

Introduction

You have a running kubernetes setup, and have a webservice (exposed via Ingress) which is running well. But, for few requests you are getting below error:

504 Gateway Timeout

Note: You will not have any application logs in this case. You might wonder that from where this error is coming.

Solution - Kubernetes Ingress Proxy Timeouts

Note: the default timeout value is 60 seconds. If your requests are taking longer than that, you need to change it. Example Ingress yaml file:

apiVersion: contour.heptio.com/v1beta1
kind: IngressRoute
metadata:
  name: my-ws-ingressroute
  namespace: my-namespace
  annotations:
    kubernetes.io/ingress.class: "contour-corp"
    # timeout in seconds
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
spec:
  virtualhost:
    fqdn: my-fqdn.com
    tls:
      secretName: my-tls-secret
  routes:
  - match: /api
    services:
    - name: api-ws-service
      port: 8080
  - match: /
    services:
    - name: ui-service
      port: 8080

And, apply this config via kubectl apply -f command.

It is important to note that you need to set a number, not any character like 3600s. It will not work.

Above will set timeout to 3600, which is pretty long. It is not advisable to set long timeouts. Configure it as per your need.

Hope it helps.


Similar Posts

Latest Posts