Gateway API

Understand the core Gateway API resources and configure and verify an HTTP entry point for a Kubernetes order service with Traefik.

🎯 Introduction

In the previous article, we created the orders Service. Other Pods in the same Namespace can find it at http://orders, but your computer's browser usually cannot access this internal cluster name directly.

To let users access the order service at the /api/info path on orders.gateway.test, we need an entry point that receives HTTP requests, with rules that choose a Service based on the hostname and path.

This article focuses on one task: configure an HTTP entry point for the Node.js order service with Gateway API and verify its routing rules. We will first examine the request path and three core resources, then complete a local exercise. Public access, DNS configuration, and HTTPS are outside this exercise's scope.


🧱 Why a Service also needs an entry point

Recall the order service resources:

  • The orders Deployment maintains the desired number of order service Pods.
  • The orders Service provides a stable internal cluster address for those Pods.

A browser outside the cluster cannot rely directly on the internal orders name. We want it to use a hostname, with an entry point routing requests to the order Service according to rules.

Our goal is for requests with hostname orders.gateway.test and path /api/info to reach the order service's Express endpoint.

Distinguish the goal from this exercise: A production website needs DNS pointing to a reachable entry point. Here, we use kubectl port-forward and curl's Host header to simulate external HTTP requests locally. A successful curl request does not mean you can enter orders.gateway.test directly in a browser.

First, examine the request path:

How does a request reach the order service?

Browser / curl

orders.gateway.test/api/info

Send an HTTP request
Traefik (the proxy that handles the request)

Uses Gateway listener settings and HTTPRoute matching rules to forward the request to the orders Service

Gateway
Configures the listener
HTTPRoute
Provides matching rules
Traefik reads both resources as configuration. HTTP traffic flows through the proxy.
Forward after a match
orders Service :80

Provides a stable entry point for order Pods and selects an available backend

Send to one backend
Order Pod A
Node.js :3000
Order Pod B
Node.js :3000

This diagram shows the logical request path. A request normally goes to one eligible backend Pod at a time.

There are two key points:

  1. Traefik is the proxy that actually receives and forwards HTTP requests.
  2. Gateway API is not another proxy. It is a set of Kubernetes configuration resources that tell Traefik how to handle requests.

Our task is therefore to configure entry point rules for the existing orders Service, rather than modify the order application.


🧩 Three core Gateway API resources

Suppose our only task is this: send requests for orders.gateway.test/api/info to the orders Service.

Traefik needs three pieces of information: which implementation provides the entry point, which traffic it accepts, and which requests go to the order service. Gateway API separates them into three resources:

Three Gateway API resources and their roles

GatewayClass

Who implements the gateway?

Specifies a controller such as Traefik

Gateway

Where does the gateway receive requests?

Defines the HTTP listener port and allows routes to attach

HTTPRoute

Where should requests go?

Matches hostnames and paths, then points to the orders Service

Note: These are configuration resources, not three running proxies. Traefik receives and forwards the HTTP requests.
ResourceQuestion it answersConfiguration here
GatewayClassWhich implementation provides the entry point?Traefik
GatewayWhat traffic does the entry point accept?HTTP requests
HTTPRouteWhich requests go to which Service?Requests matching the hostname and /api path go to orders

For this order service, the Gateway allows HTTPRoutes in the course Namespace to attach to it. The HTTPRoute defines the relationship between orders.gateway.test, /api, and the orders Service.

These are configuration relationships, not three servers that a request traverses in sequence. Traefik still receives and forwards the HTTP requests.

The YAML below maps to these three resources. For now, understand their roles without memorizing every field.


🛠 Configuring and verifying Gateway API

Reuse the environment from earlier articles:

  • kind cluster: node-course;
  • Namespace:course;
  • Deployment and Service: orders; Service port 80 maps to application port 3000.

This article uses Traefik to handle HTTP requests. Environment preparation has two parts: teach Kubernetes the Gateway API resource types, and install Traefik to read their configuration. The internal workings of CRDs and Helm are not the focus here.

The example pins Gateway API v1.6.3 Standard + Traefik Helm Chart 42.3.0. Chart 42.x requires Kubernetes 1.30 or later. If your earlier kind cluster uses an older version, prepare a compatible practice environment first. These installation and update commands are intended only for the dedicated course cluster, not for direct use in production.

About the output: All terminal output below is simulated to explain the results. Use your own cluster's actual output when following along. The configuration was checked against official documentation but has not been tested end to end in a real kind environment.

1. Check the order service

Open a terminal:

kubectl config current-context
kubectl get nodes
kubectl get deployment,service -n course

Simulated output:

kind-node-course

NAME                        STATUS   ROLES           AGE   VERSION
node-course-control-plane   Ready    control-plane   20m   v1.34.0

NAME                     READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/orders   2/2     2            2           10m

NAME             TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
service/orders   ClusterIP   10.96.42.10   <none>        80/TCP    8m

The first line identifies the current cluster context. Check VERSION in kubectl get nodes for the Kubernetes version; v1.34.0 here is simulated. READY 2/2 indicates two ready order Deployment replicas, and service/orders confirms the order Service exists.

If these resources are missing, complete the Deployment and Service exercises first. You do not need to rewrite the Node.js code.

You can also run kubectl get endpointslices -n course -l kubernetes.io/service-name=orders to confirm that the Service found order Pods. If there are no backends, check Pod and Service labels before installing the gateway.

2. Prepare Gateway API and Traefik

Step 1: Install the Gateway API resource definitions. A standard kind cluster may not recognize GatewayClass, Gateway, and HTTPRoute by default. Install their resource types first:

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

Simulated output excerpt:

customresourcedefinition.apiextensions.k8s.io/gatewayclasses.gateway.networking.k8s.io serverside-applied
customresourcedefinition.apiextensions.k8s.io/gateways.gateway.networking.k8s.io serverside-applied
customresourcedefinition.apiextensions.k8s.io/httproutes.gateway.networking.k8s.io serverside-applied

The resource types have been submitted to the cluster. CRD stands for CustomResourceDefinition; for now, think of it as adding a new resource type to Kubernetes.

Step 2: Install Traefik. Use Helm to install the entry point application. Helm is an application installation tool for Kubernetes. If it is not installed, macOS users can run brew install helm; for other systems, see the official installation guide.

helm repo add traefik https://traefik.github.io/charts
helm repo update
helm upgrade --install traefik traefik/traefik \
  --version 42.3.0 \
  --namespace traefik --create-namespace \
  --set providers.kubernetesGateway.enabled=true \
  --set gateway.enabled=false \
  --set gatewayClass.enabled=false \
  --wait --timeout 5m

--version 42.3.0 pins the chart version, and providers.kubernetesGateway.enabled=true enables reading Gateway API resources. The two enabled=false settings prevent the chart from creating a Gateway and GatewayClass automatically so we can create them ourselves; they do not disable Gateway API. If a Helm release with this name already exists, upgrade --install updates it, so do not run this casually against another cluster.

Simulated excerpt after a successful first installation:

Release "traefik" does not exist. Installing it now.
NAME: traefik
NAMESPACE: traefik
STATUS: deployed

Next, check that Traefik is running and its Service exposes HTTP port 80:

kubectl get pods -n traefik
kubectl get service traefik -n traefik

Simulated output in command order, showing only key details:

NAME                       READY   STATUS    RESTARTS   AGE
traefik-6f8c9d7b5-abcde   1/1     Running   0          40s

NAME      TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)                    AGE
traefik   LoadBalancer   10.96.88.20   <pending>     80:30080/TCP,443:30443/TCP  1m

The Traefik Pod is ready. In a standard kind cluster, an external address of <pending> does not prevent local testing with port-forward. The entry point application is now ready, but it has not yet been told to route requests to orders.

3. Write the Gateway API configuration

With the orders Service in place, answer three questions: Which implementation provides the entry point? Which requests does it accept? Where does it send them? We will examine the three resources in that order, then combine them in one file.

First: GatewayClass—select Traefik.

kind: GatewayClass
metadata:
  name: traefik-course
spec:
  controllerName: traefik.io/gateway-controller

controllerName selects the controller implementation for this class of Gateway. Here we select Traefik and name the GatewayClass traefik-course.

Second: Gateway—configure the HTTP entry point.

kind: Gateway
metadata:
  name: orders-gateway
  namespace: course
spec:
  gatewayClassName: traefik-course
  listeners:
    - name: http
      protocol: HTTP
      port: 8000
      allowedRoutes:
        namespaces:
          from: Same

gatewayClassName references the GatewayClass we just defined. listeners configures HTTP traffic, with port: 8000 matching Traefik's web entry point in this example. from: Same allows only routes in the same Namespace to attach. Since the Gateway is in course, we also place the HTTPRoute there.

Third: HTTPRoute—select the order service.

kind: HTTPRoute
metadata:
  name: orders-route
  namespace: course
spec:
  parentRefs:
    - name: orders-gateway
  hostnames:
    - orders.gateway.test
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /api
      backendRefs:
        - name: orders
          port: 80

parentRefs references orders-gateway; hostnames and PathPrefix: /api match the hostname and URL path. backendRefs sends requests to port 80 of the orders Service. Express already exposes /api/info, so no path rewrite is needed.

The three snippets above show only selected fields. Do not apply them individually. The following is the complete configuration to save and apply.

Create gateway-api.yaml:

# ① Use Traefik as the entry point implementation
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: traefik-course
spec:
  controllerName: traefik.io/gateway-controller
---
# ② Create an HTTP entry point
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: orders-gateway
  namespace: course
spec:
  gatewayClassName: traefik-course
  listeners:
    - name: http
      protocol: HTTP
      port: 8000
      allowedRoutes:
        namespaces:
          from: Same
---
# ③ Specify the hostname, path, and backend Service
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: orders-route
  namespace: course
spec:
  parentRefs:
    - name: orders-gateway
  hostnames:
    - orders.gateway.test
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /api
      backendRefs:
        - name: orders
          port: 80

The three resources share one YAML file, separated by ---. Each includes the apiVersion Kubernetes needs to recognize it.

Several ports appear in the exercise. Use the diagram to understand them rather than memorizing the numbers:

Five ports along the request path

Your computer

curl sends a test request through port forwarding

:8081

Traefik Service

Passes requests to the Traefik proxy

:80

Traefik HTTP listener

Matches requests using Gateway and HTTPRoute configuration

:8000

orders Service

Provides a stable entry point for the order application

:80

Order Pod

The port the Express app listens on

:3000

This diagram uses the article's example configuration. Each port 80 belongs to a different Service.

This diagram represents the exercise: local 8081 → Traefik Service 80 → Traefik internal HTTP entry point 8000 → orders Service 80 → order Pod 3000. The two 80 ports belong to different Services. Port 8000 comes from this Traefik configuration; Gateway API does not require it.

4. Create the resources and inspect the results

kubectl apply -f gateway-api.yaml

Simulated output:

gatewayclass.gateway.networking.k8s.io/traefik-course created
gateway.gateway.networking.k8s.io/orders-gateway created
httproute.gateway.networking.k8s.io/orders-route created

All three resources have been submitted to Kubernetes. Successful submission does not guarantee working requests. Check that Traefik accepted the configuration:

Step 1: Check the GatewayClass.

kubectl get gatewayclass traefik-course

Simulated output:

NAME             CONTROLLER                      ACCEPTED   AGE
traefik-course   traefik.io/gateway-controller   True       25s

ACCEPTED=True means Traefik accepted the GatewayClass.

Step 2: Check the Gateway.

kubectl get gateway orders-gateway -n course

Simulated output; ADDRESS may be empty in kind:

NAME             CLASS            ADDRESS   PROGRAMMED   AGE
orders-gateway   traefik-course             True         20s

PROGRAMMED=True means the controller reports that it has configured the entry point. It still does not guarantee successful HTTP requests.

Step 3: Check the HTTPRoute.

kubectl describe httproute orders-route -n course

Simulated output, showing only part of the status:

Status:
  Parents:
    Parent Ref:
      Name:  orders-gateway
    Conditions:
      Type:    Accepted
      Status:  True
      Type:    ResolvedRefs
      Status:  True

Parent Ref associates the route with orders-gateway. Accepted=True means the route was accepted, and ResolvedRefs=True means its backend references resolve. You still need to send an HTTP request to verify that it reaches the application.

5. Access the order service

In kind, use port forwarding for temporary access to Traefik from your computer. Since we have not configured DNS or a public load balancer, a successful test does not let you enter orders.gateway.test directly in a browser.

Terminal A:

kubectl port-forward -n traefik service/traefik 8081:80

Simulated output:

Forwarding from 127.0.0.1:8081 -> 8000
Forwarding from [::1]:8081 -> 8000

Refer to the port diagram above for the mappings. port-forward creates a temporary test connection between your computer and Traefik; it does not configure a production entry point for public users.

Terminal B (leave terminal A running):

curl -i -H 'Host: orders.gateway.test' http://127.0.0.1:8081/api/info

Simulated response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{"service":"orders","version":"v1"}

The Host header supplies the hostname used to match orders.gateway.test in the HTTPRoute, so local testing does not require editing your hosts file. A 200 OK response with the same JSON as /api/info in the Service article confirms that the request reached Node.js. This verifies the temporary local entry point, not a configured public domain.

Now try the non-matching path /other:

curl -i -H 'Host: orders.gateway.test' http://127.0.0.1:8081/other

If no other rule matches, you may see:

HTTP/1.1 404 Not Found

404 page not found

This is not a Pod failure. The HTTPRoute matches paths beginning with /api, so /other does not match.

After testing, press Ctrl+C in terminal A to stop forwarding. The Gateway API resources remain in the cluster.


❓ Questions and answers

Q: Why use Gateway API when a Service already exists?

A Service provides stable internal access to a group of Pods. Gateway API configures how external HTTP requests enter and selects Services by hostname and path.

Q: Do GatewayClass, Gateway, and HTTPRoute each start a separate proxy?

No. They are configuration resources. A proxy managed by a compatible controller, such as Traefik, actually handles requests.

Q: What is Ingress? Do I also need to learn it?

Ingress is another Kubernetes API for configuring HTTP/HTTPS entry points, and existing projects still use it. New projects can evaluate Gateway API first. You do not need to learn Ingress before this article or configure both APIs for the same entry point.


🧪 Exercise

Change the HTTPRoute path in gateway-api.yaml:

value: /orders

Apply it again:

kubectl apply -f gateway-api.yaml

Keep port forwarding running, or restart it, then request the original /api/info path:

curl -i -H 'Host: orders.gateway.test' http://127.0.0.1:8081/api/info

Because the path no longer matches, and assuming no other route matches, expect 404. This indicates that the entry point rule did not match; it does not indicate a bug in the order service.

Finally, restore /api, run kubectl apply again, and confirm the endpoint returns JSON.

Success criteria: Explain the responsibilities of GatewayClass, Gateway, and HTTPRoute in your own words, and observe the difference between a successful request and 404 by changing the path.


🎉 You now understand why an order Service needs an HTTP entry point and have used Gateway API to verify a simulated local HTTP request reaching a Node.js Pod.