kubernetes|September 16, 2022|1 min read

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

TL;DR

Increase the nginx ingress proxy timeout annotations (proxy-read-timeout, proxy-send-timeout) on your Kubernetes Ingress resource to resolve 504 errors.

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

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.

Related Posts

Drupal Code: Fetch Link, Title, Category names, tag names from every article

Drupal Code: Fetch Link, Title, Category names, tag names from every article

See the code below: The output will be 4 columns separated by comma. You can…

MySql update query - Update column by string replacement in all records

MySql update query - Update column by string replacement in all records

Problem Statement In a mysql table, I wanted to replace the hostname of the…

How to connect to a running mysql service on host from a docker container on same host

How to connect to a running mysql service on host from a docker container on same host

Introduction I have a host running mysql (not on a container). I have to run an…

How To Create Admin Subdomain In Cloudflare with Nginx Proxy using Docker with SSL

How To Create Admin Subdomain In Cloudflare with Nginx Proxy using Docker with SSL

Introduction I have my main website, which I run on Lets say: . Now, there is my…

php55w-common conflicts with php-common-5.* | Php issues while installing libraries

php55w-common conflicts with php-common-5.* | Php issues while installing libraries

I was trying to install mongo extension with pecl. It gave me error: Then, I…

Troubleshoot AWS Lambda unknown error!

Troubleshoot AWS Lambda unknown error!

After 2 days, there was my demo. I deployed my nodejs code on lambda function…

Latest Posts

REST API Design: Pagination, Versioning, and Best Practices

REST API Design: Pagination, Versioning, and Best Practices

Every time two systems need to talk, someone has to design the contract between…

Efficient Data Modelling: A Practical Guide for Production Systems

Efficient Data Modelling: A Practical Guide for Production Systems

Most engineers learn data modelling backwards. They draw an ER diagram…

Deep Dive on Caching: From Browser to Database

Deep Dive on Caching: From Browser to Database

“There are only two hard things in Computer Science: cache invalidation and…

System Design Patterns for Real-Time Updates at High Traffic

System Design Patterns for Real-Time Updates at High Traffic

The previous articles in this series covered scaling reads and scaling writes…

System Design Patterns for Scaling Writes

System Design Patterns for Scaling Writes

In the companion article on scaling reads, we covered caching, replicas, and…

System Design Patterns for Managing Long-Running Tasks

System Design Patterns for Managing Long-Running Tasks

Introduction Some operations simply can’t finish in the time a user is willing…