Gateway API Routes

Routing traffic via HTTPRoute and GRPCRoute.

Routes in the Gateway API describe routing logic: binding to a Gateway, request matching rules, and backend services. You manage them in a cluster namespace.

Supported route types:

TypeAPIDestination
HTTPRoutegateway.networking.k8s.io/v1HTTP/HTTPS routing
GRPCRoutegateway.networking.k8s.io/v1gRPC routing

Where to configure:

  • namespace - section Networks → Routes.
  • Through custom resources: namespace → section Administration → Custom resources → API group gateway.networking.k8s.io → HTTPRoute or GRPCRoute.

For a general overview of the Gateway API, see Gateway API. For classic publishing via Ingress, see How to publish an application.

The Routes page displays a list of created routes (HTTPRoute, GRPCRoute) in the namespace.

Screenshot: list of routes

List of Gateway API routes


Creating a route

On the Routes page, click +Add Route and select the route type: HTTP, GRPC. On the page that opens, fill in:

  • Name - required, unique within the namespace; does not change when editing.
  • Labels and Annotations are optional.
Screenshot: selecting route type

Select route type

Object specification

The route must be linked to at least one Gateway. Press + to select a Gateway from the list of available ones. If necessary, select a handler name.

  1. The list of available Gateways depends on the namespace of the route and the Allowed routes from namespaces settings in Gateway handlers:
  • The namespace of the route and Gateway are the same - select the name Gateway and the name of the handler;
Screenshot: adding Gateway from the same namespace

Adding Gateway from the same namespace

  • Gateway from another namespace—the list of available Gateways for selection is determined if the Gateway handler allows route binding from all namespaces (ALL) and/or the route namespace labels match the namespace Selector in the handler.
Screenshot: adding Gateway from another namespace

Adding Gateway from another namespace

  1. Hosts (optional) - hostnames that must match the request header to select this route. If hostname is specified in both a handler and a route, there must be at least one overlapping name to attach to the handler.
Example of hostnames matching
hostname in Listenerhost in routeAttachment
test.example.com(not specified)yes
test.example.comtest.example.comyes
test.example.comfoo.example.comno
*.example.com(not specified)yes
*.example.com*.example.comyes
*.example.comfoo.test.example.comyes
*.example.comexample.comno

Rules

In the Rules block, route rules can be specified: matching requests based on matches (Matches) and forwarding them to Backend Services. You can set several rules. Click + to configure the rule. In the window that opens, configure:

  1. Rule name (optional) – the name of the route rule, must be unique in the route. When added, appears in the list of rules in the Rules block.
  2. Matches - if it is necessary to set up a matching condition with an incoming request.
Matches principleDescription
Logic AND inside one ruleSeveral conditions (matches) are specified in one rule, the request must match all these conditions at the same time
OR logic between different rulesIf the request matches the conditions of at least one of the rules, it will be sent to the backends specified in this rule

Click + in the Matches section to add a matching condition. The following settings are available in the side window:

FieldDescription
PathHTTP request path to match
Path typeDetermines how to interpret the request path value specified in the Path field. Three types are supported:
  • Exact - requires an exact match of the path in the request.
  • PathPrefix - requires a match of the path prefix (for example, /login will match /login, /login/oauth, etc.).
  • RegularExpression - requires a match with a regular expression. Support for this type is implementation dependent.
MethodThe HTTP method that the request must match. Possible values: GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH
HTTP request headersConditions to match against HTTP request headers. In one Match, you can specify several conditions for the HTTP request headers and all of them must be met. Each header is defined by three parameters:
  • Name - the name of the header.
  • Type - the mapping type (Exact or RegularExpression).
  • Value - the value of the header.
HTTP request parametersConditions to match with query parameters. In one Match you can specify several conditions for parameters and all of them must be met. The following are available for the parameter:
  • Name - the name of the parameter.
  • Type - the mapping type (Exact or RegularExpression).
  • Value - the value of the parameter.
FieldDescription
GRPC methodThe name of the gRPC method that the request should match. If a method name is specified, the Service field must also be filled in. If both fields (Service and Method) are not specified, the rule will match any gRPC requests.
ServiceThe name of the gRPC service that the request should match.
TypeDetermines how to interpret the values of the Service and GRPC Method fields. Two types are supported:
  • Exact - requires an exact match of the service name and/or method.
  • RegularExpression - requires a match with a regular expression. Important: Support for this type is implementation dependent.
`
GRPC HeadersConditions to match against gRPC request headers. Each header is defined by three parameters:
  • Name - the name of the header.
  • Type - the mapping type (Exact or RegularExpression).
  • Value - the value of the header (required field).
The added match is displayed in the list of the **Matches** block. Clicking on a line opens a viewing window with the ability to delete. 3. **Backend Services** - a list of target backends (Kubernetes Service) to route traffic that matches the route rule. You can specify several services for traffic distribution. Click **+** in the **Backend Services** block to add a Service: | Field | Required | Description | |------|----------------|----------| | **ServiceName** | Yes | Service in the same namespace where the route will be added. Specify the service if it has already been created in the namespace. In the absence of Service - manual entry | | **Service Port** | Yes |Network port on which the target Service receives traffic | | **Weight** | No | Proportional value for distributing traffic between backends. Weight (not a percentage) determines the proportion relative to the sum of the weights of all backends in the rule. By default, if the weight is not specified, it will be set to 1. Weight = 0 - no traffic will be sent to this backend. When specifying one backend, it receives 100% of the traffic regardless of the specified weight value. |
Screenshot: creating HTTPRoute ![Creating HTTPRoute](/route-create-filled.png)
Screenshot: setting up Rules and Backend Services ![Setting up Rules and Backend Services](/route-rules.png)
Click **Save** to create your route. ### Example route manifests
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: my-app-route
  namespace: my-namespace
spec:
  parentRefs:
    - name: example-gateway
      namespace: infra
      sectionName: http
  hostnames:
    - app.example.com
  rules:
    - name: default
      matches:
        - path:
            type: PathPrefix
            value: /
      backendRefs:
        - name: my-service
          port: 80
apiVersion: gateway.networking.k8s.io/v1
kind: GRPCRoute
metadata:
  name: grpc-app
  namespace: my-namespace
spec:
  parentRefs:
  - name: my-gateway
  hostnames:
  - "example.com"
  rules:
  - matches:
    - method:
        service: com.example.user
        method: Login
    backendRefs:
    - name: my-service
      port: 50051
--- ## View and edit Click on a route line in the list to open the view page. The **HTTP route** or **GRPC route** tab displays the associated Gateways, hosts and routing rules. If necessary, you can change hosts, rules, matches and backend services.
Screenshot: viewing HTTPRoute ![View HTTPRoute](/route-view.png)
Screenshot: viewing GRPCRoute ![GRPCRoute View](/grpc-view.png)
--- ## Related topics - [Gateways](/2.15/en/cluster-admin/networking/gateways/) — entry points to which routes are attached; - [Gateway Classes](/2.15/en/cluster-admin/networking/gateway-classes/) — select a GatewayClass when creating a Gateway; - [Gateway API](/2.15/en/cluster-admin/networking/gateway-api/) - overview and typical configuration scenario; - [CRD of the Gateway API module](/2.15/en/cluster-admin/services/platform-services/load-balancer/shturval-gateway-api-crds/) — installation of the CRD Gateway API in the cluster; - [Gateway API Controller in Cilium](/2.15/en/cluster-admin/services/platform-services/critical-services/shturval-networking/#cilium-gateway-api) - enable the controller in shturval-networking.