Kubernetes
HTTP/2
ingress-nginx
Networking
DevOps

How to get HTTP/2 working in a Kubernetes cluster using ingress-nginx

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

As modern web applications demand high performance and efficient resource usage, HTTP/2 has become a widely adopted protocol due to its benefits over HTTP/1.1, such as multiplexing, header compression, and server push. Kubernetes is the leading container orchestration platform, and ingress-nginx is a popular choice for managing external access to services within a Kubernetes cluster. In this article, we will explore how to enable and configure HTTP/2 using ingress-nginx in a Kubernetes environment.

Understanding HTTP/2

Before diving into the implementation, it's important to understand the improvements HTTP/2 brings:

  • Multiplexing: Multiple requests and responses can be sent over a single TCP connection simultaneously, reducing latency caused by the HTTP/1.1's head-of-line blocking.
  • Header Compression: Uses HPACK compression to reduce overhead and improve speeds.
  • Server Push: Allows the server to send resources to the client proactively.
  • Stream Prioritization: Clients can specify which resources are more critical.

For Kubernetes environments, leveraging these features can greatly enhance performance and resource utilization.

Prerequisites

Before proceeding, ensure you have the following:

  • A Kubernetes cluster running version 1.14 or later.
  • kubectl command-line tool installed and configured to communicate with your cluster.
  • Understanding of Kubernetes Ingress concepts.
  • The ingress-nginx controller installed in your cluster.

Enabling HTTP/2 in ingress-nginx

The ingress-nginx controller supports HTTP/2 by default for HTTPS connections, but you may need to ensure it's correctly configured. Here's a step-by-step guide to set it up:

Step 1: Install ingress-nginx

If you haven’t installed the ingress-nginx controller yet, you can do so via Helm or using kubectl . Here's an example using kubectl :

  • hosts:
    • your-domain.com
  • host: your-domain.com
    • path: /
  • HTTP/2 Timeouts: You can specify timeouts using annotations. For example, nginx.ingress.kubernetes.io/proxy-read-timeout: "10"
  • Max Concurrent Streams: Control the number of simultaneous calls using nginx.ingress.kubernetes.io/http2-max-concurrent-streams annotation.
  • Enable/Disable HTTP/2: If necessary, you can disable HTTP/2 with the nginx.ingress.kubernetes.io/force-ssl-redirect: "true" annotation to fall back to HTTP/1.1 intentionally.
  • Client Support: Ensure your clients support HTTP/2. Most modern browsers and HTTP libraries do.
  • Security: Always use strong TLS ciphers and protocols.
  • Testing: Use tools like curl and browser developer tools to test performance and behavior under HTTP/2.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.