Ingress and Gateway API on Kubernetes: exposing your app over HTTPS

  1. Introduction
  2. What Ingress is
  3. IngressClass
  4. Example: routing by hostname and path
  5. Turning on HTTPS with TLS
  6. Gateway API: the newer way
  7. Quick comparison
  8. Checking
  9. Common mistakes
  10. Summary
  11. References

Introduction

In Kubernetes Services: ClusterIP, NodePort, LoadBalancer and cluster DNS we saw how Services help Pods find each other.

To let outside users reach a web application, you could use a LoadBalancer Service, but one load balancer per application quickly becomes expensive and hard to manage.

Kubernetes has two ways to consolidate: Ingress (the long-standing way) and Gateway API (the newer way). This article explains both and how to turn on HTTPS.

What Ingress is

Ingress is an object that declares HTTP and HTTPS routing rules: which hostname and path a request is sent to, and which Service receives it.

One point many people miss: Ingress itself does nothing. It is only a declaration.

You must install an Ingress controller (a program running in the cluster that reads Ingresses and configures a matching proxy).

Kubernetes ships with no controller; there are many choices from the community and from cloud providers.

IngressClass

A cluster can run several controllers. IngressClass is an object that names each controller, and an Ingress picks its controller with the ingressClassName field. List the classes available:

kubectl get ingressclass

If the list is empty, the cluster has no controller and the Ingress you create will be handled by nobody.

Example: routing by hostname and path

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web
  namespace: demo
spec:
  ingressClassName: example-class
  rules:
    - host: app.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 80
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: api
                port:
                  number: 80

A quick explanation:

The class name example-class above is only an example; replace it with a name from kubectl get ingressclass.

Turning on HTTPS with TLS

For an Ingress to serve HTTPS, you need a certificate and private key stored in a Secret of type kubernetes.io/tls in the same namespace. Create it with:

kubectl -n demo create secret tls web-tls --cert=fullchain.pem --key=privkey.pem

Then reference it in the Ingress:

spec:
  ingressClassName: example-class
  tls:
    - hosts:
        - app.example.com
      secretName: web-tls
  rules:
    - host: app.example.com
      # ... as above

Note: the private key is a secret.

Do not put key files into a source repository; handling Secrets is discussed further in ConfigMaps and Secrets: separating configuration from your application image on Kubernetes.

Many teams also use a component that requests and renews certificates automatically instead of creating them by hand, but the mechanism underneath is still a TLS-type Secret as above.

When you choose a controller, read its own documentation, because many advanced features (path rewriting, rate limiting, redirects) are configured through annotations specific to each controller and are not part of the common Ingress specification.

Gateway API: the newer way

The Kubernetes documentation states plainly that the project recommends using Gateway instead of Ingress; the Ingress API has been "frozen" (no further development), but it is still GA and there are no plans to remove it.

So you need not rush to drop an Ingress that works well, but for new systems consider Gateway API.

Gateway API separates roles more clearly with three main kinds of objects:

This split lets operations teams manage the Gateway while application teams write only their own HTTPRoute.

Gateway API is a set of CRDs you install into the cluster and it needs an implementation that supports it; it is not available by default. A minimal HTTPRoute example:

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: web
  namespace: demo
spec:
  parentRefs:
    - name: shared-gateway
  hostnames:
    - app.example.com
  rules:
    - backendRefs:
        - name: web
          port: 80

Quick comparison

Status

Ingress

GA, frozen

Gateway API

Recommended for new needs

Roles

Ingress

One object for everything

Gateway API

Separate Class, Gateway, Route

Advanced features

Ingress

Often via controller-specific annotations

Gateway API

Many are part of the specification

Extra installation

Ingress

Ingress controller

Gateway API

Gateway API CRDs and an implementation

Checking

  1. kubectl get ingressclass shows at least one class.

  2. kubectl -n demo get ingress web shows an address in the ADDRESS column (it may take a while).

  3. Point the hostname's DNS to that address, then run curl -I https://app.example.com.

  1. Use kubectl -n demo describe ingress web to read the events if it is not working.

Common mistakes

Summary

Ingress gathers HTTP/HTTPS routing into one entry point, but it needs a controller and the right ingressClassName. HTTPS uses a TLS-type Secret.

Ingress is still supported; for new systems, Gateway API is the recommended direction, with clearer role separation.

References

Ingress and Gateway API on Kubernetes: exposing your app over HTTPS