🎓 A1Learner
🔍
0 of 51 lessons completed

Kubernetes: Ingress and the Gateway API

An Ingress is a single entry point that routes HTTP traffic to the right Service. The Gateway API is the modern form of that idea, and it replaces the old Ingress controllers.

Install the Gateway API first

The Gateway API needs its standard-channel CRDs installed before any Gateway can exist. This one command installs them.

kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.3.0/standard-install.yaml

A Gateway that listens

A Gateway is the door. It listens on a port and names the GatewayClass that runs it. No traffic reaches an app until a route points at it.

apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: web-gateway
spec:
  gatewayClassName: nginx
  listeners:
    - name: http
      port: 80
      protocol: HTTP

An HTTPRoute that points at the app

An HTTPRoute is the signpost. It says that traffic arriving at the Gateway for the path goes to the web Service. One Gateway can hold many routes.

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: web-route
spec:
  parentRefs:
    - name: web-gateway
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /
      backendRefs:
        - name: web
          port: 80

Example

kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.3.0/standard-install.yaml
kubectl apply -f gateway.yaml
kubectl get gateway web-gateway

Key points

  • Gateway API: the modern way to route HTTP traffic into a cluster
  • GatewayClass: the kind of gateway the cluster can run, like nginx
  • Gateway: the entry point that listens for traffic on a port
  • HTTPRoute: the rule that sends a path or a host to a Service
  • CRD: a CustomResourceDefinition, a new object kind added to the cluster.
  • TLS: the encryption that keeps traffic private.
  • cert-manager: a tool that adds TLS certificates to a cluster.
  • Use cert-manager to add TLS certificates to a Gateway
  • Use one Gateway for many apps, with one HTTPRoute per app

In this example, the first command installs the Gateway API standard-channel CRDs. The second command creates a Gateway and an HTTPRoute from the file. The third command reads the Gateway back, and it shows it is programmed and ready to take traffic.

Note

the community ingress-nginx controller is retired, so new work should use the Gateway API

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

A new cluster needs one entry point for HTTP traffic. Which is the right primary path?