liveBook · Manning

Gateway api

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

Gateway API is a Kubernetes networking API for expressing and implementing traffic routing through gateway resources.

Gateway API expresses how traffic reaches applications in a Kubernetes cluster. Compared with an ingress resource, it separates infrastructure configuration from application routing and supports traffic management at layers 4 and 7. It can address traffic entering the cluster and traffic between workloads across namespaces. section 6.7

For a routing task, identify which resource belongs to each responsibility:

  • GatewayClass is cluster-scoped. An infrastructure provider defines the controller and underlying infrastructure, such as an external load balancer. section 6.7
  • Gateway configures operational details such as listeners, ports, protocols, and TLS certificates. A cluster operator manages it. section 6.7
  • A Route defines application-level routing. An application developer can use HTTPRoute for HTTP traffic or another route type, such as TCPRoute. section 6.7

Route a hostname to an application

Apply three gateway.networking.k8s.io/v1 resources with kubectl. Set GatewayClass.spec.controllerName to example.com/gateway-controller. Create a Gateway in the default namespace with gatewayClassName pointing to that class and an HTTP listener on port 80. Then create an HTTPRoute whose parentRefs names the Gateway, whose hostname is www.example.com, and whose PathPrefix / rule sends traffic to the nginx backend on port 8080. section 6.7

$ cat <<EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: example-httproute
spec:
  parentRefs:
  - name: example-gateway
  hostnames:
  - "www.example.com"
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /
    backendRefs:
    - name: nginx
      port: 8080

$ kubectl get httproute
NAME                HOSTNAMES             AGE
example-httproute   ["www.example.com"]   20s

The HTTPRoute manifest shows the parent reference, hostname, path match, and backend reference together. The accompanying kubectl get httproute output verifies that the route appears with its configured hostname; it does not demonstrate that traffic reaches the backend. section 6.7

For CKA practice, know how the three resources fit together and how they differ from a single ingress resource. Gateway API uses custom resource definitions (CRDs); the stated exam emphasis is configuring the objects rather than necessarily installing the API. section 6.7 section 9.3.5

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Works through three resource manifests and an HTTPRoute check, but does not demonstrate controller installation or end-to-end traffic verification.
Examples
Uses kubectl manifests for a GatewayClass, HTTP Gateway listener, and hostname-and-path HTTPRoute targeting an nginx backend.
What it assumes
Assumes familiarity with ingress and Service resources while introducing GatewayClass, Gateway, and HTTPRoute through manifests.
What you can do after
Apply it via kubectl by configuring GatewayClass, Gateway, and HTTPRoute resources and checking that the HTTPRoute appears.
How it connects
Connects ingress resources, Services, load balancers, TLS termination, HTTP routing, and custom resource definitions.

Also explained in

Compare how 3 books explain gateway api →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.