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

Kubernetes - How to Set Namespace So You Do Not Need to Mention it Again and Again in Kubectl Commands.

Kubernetes - How to Set Namespace So You Do Not Need to Mention it Again and Again in Kubectl Commands.

Introduction In some of the cases, we need to specify namespace name along with…

Kubernetes - How to Configure Docker Repository to Pull Image and Configure Secret

Kubernetes - How to Configure Docker Repository to Pull Image and Configure Secret

Introduction In most of cases, you are not pulling images from docker hub public…

How to configure Grafana (Free version) with oAuth Okta, with SSL on Kubernetes

How to configure Grafana (Free version) with oAuth Okta, with SSL on Kubernetes

Introduction In our previous post How to configure Grafana on docker, we saw how…

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Most developers use Claude Code like a search engine — ask a question, get an…

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Every office lobby has the same problem: a visitor walks in, nobody’s at the…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

Latest Posts

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Most developers use Claude Code like a search engine — ask a question, get an…

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Every office lobby has the same problem: a visitor walks in, nobody’s at the…

Server Security Best Practices — Complete Hardening Guide for Production Systems

Server Security Best Practices — Complete Hardening Guide for Production Systems

Every breach post-mortem tells the same story: an unpatched service, a…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF have been in the OWASP Top 10 for over a decade. They’re among the…

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

The OWASP Top 10 is the industry standard for web application security risks. If…