HTTPRoute

The HTTPRoute resource in the Kubernetes Gateway API is used to define and manage routing rules for HTTP traffic within a Kubernetes cluster. HTTPRoute is determined by the Gateway API community. It specifies how HTTP requests should be directed from a Gateway to various backend services based on criteria such as paths and headers.

Key aspects of the HTTPRoute include:

  • Routing Rules: Defines detailed routing rules for HTTP requests, such as routing based on URL paths, request headers, and query parameters.
  • Service Mapping: Allows configuring of different HTTP requests to be mapped to different backend services or endpoints within the cluster.
  • Advanced Features: Supports advanced routing features, including weight-based routing and header-based routing, which are useful for traffic management and canary deployments.

By using HTTPRoute, Kubernetes users can precisely control how HTTP traffic is distributed and handled across their services, enabling flexible and efficient traffic management.

CR Parameters

The table below describes the HTTPRoute spec parameters:

Parameter Description
parentRefs.name Specifies the name of the parent resources that is associated with HTTPRoute. For example, http-gateway
parentRefs.sectionName Specifies the section name or category of the parent that is associated with HTTPRoute. For example, http
rules.backendRefs.name Specifies the name of the backend service to which the traffic must be sent. For example, spk-app-http-8000-f5ing-testapp
rules.backendRefs.port Specifies the port on which the backend service is listening. For example, 8080
rules.backendRefs.weight Specifies the weight for load balancing the traffic between multiple backends. For example, 30
rules.matches.path.type Specifies the path matching rule. For example, PathPrefix. This means the path should start with the specified value.
rules.matches.path.value Specifies the prefix that must match. For example, /v1/chat/completions
rules.matches.headers.type Specifies the header matching rules.
rules.matches.headers.name Specifies the name of header that must match.
rules.matches.headers.value Specifies the value of header that must match.
Note: You can refer to HTTPRoute for more details.

Support Status

The table below describes the support status of HTTPRoute CR paremeters:

Parameter Supported/Not Supported/Optional
parentRefs.name Supported
parentRefs.sectionName Supported
rules.backendRefs.name Supported
rules.backendRefs.port Supported
rules.backendRefs.weight Supported
rules.matches.path.type Supported
rules.matches.path.value Supported
rules.matches.headers.type Supported
rules.matches.headers.name Supported
rules.matches.headers.value Supported

Sample CRs

Basic HTTPRoute CR

apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: my-http-gateway-class
spec:
  controllerName: "f5.com/f5-gateway-controller"
  description: "F5 BIG-IP http route Kubernetes Gateway"
---
apiVersion: gateway.k8s.f5net.com/v1
kind: Gateway
metadata:
  name: http-gateway
spec:
  addresses:
  - type: "IPAddress"
    value: <IP Address>
  gatewayClassName: my-http-gateway-class
  listeners:
  - name: http
    protocol: HTTP
    port: 8088
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: http-route
spec:
  parentRefs:
  - name: http-gateway
    sectionName: http
  rules:
  - backendRefs:
    - name: spk-app-http-8000-f5ing-testapp
      port: 8000

HTTPRoute CR for SSL config

apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
  name: ssl-http-gateway-class
spec:
  controllerName: "f5.com/f5-gateway-controller"
  description: "F5 BIG-IP http route Kubernetes Gateway"
---
apiVersion: gateway.k8s.f5net.com/v1
kind: Gateway
metadata:
  name: ssl-http-gateway
spec:
  addresses:
  - type: "IPAddress"
    value: <IP Address>
  gatewayClassName: ssl-http-gateway-class
  listeners:
  - name: https
    protocol: HTTPS
    port: 443
    tls:
      certificateRefs:
      - kind: Secret
        group: ""
        name: tls-secret
        namespace: spk-app-1
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: ssl-http-route
spec:
  parentRefs:
  - name: ssl-http-gateway
    sectionName: https
  rules:
  - backendRefs:
    - name: spk-app-http-8000-f5ing-testapp
      port: 8000

HTTPRoute CR for URL based routing

apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
  name: my-ai-http-gateway-class
spec:
  controllerName: "f5.com/f5-gateway-controller"
  description: "F5 BIG-IP http route Kubernetes Gateway"
---
apiVersion: gateway.k8s.f5net.com/v1
kind: Gateway
metadata:
  name: ai-http-gateway
spec:
  addresses:
  - type: "IPAddress"
    value: <IP Address>
  gatewayClassName: my-ai-http-gateway-class
  listeners:
  - name: http
    protocol: HTTP
    port: 8088
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: ai-http-route
spec:
  parentRefs:
  - name: ai-http-gateway
    sectionName: http
  rules:
    - matches:
      - path:
          type: PathPrefix
          value: /v1/chat
      backendRefs:
      - name: llama-2-7b-chat
        port: 8000
    - backendRefs:
      - name: spk-app-http-8000-f5ing-testapp
        port: 8000

HTTPRoute CR for header based routing

apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
  name: header-path-http-gateway-class
spec:
  controllerName: "f5.com/f5-gateway-controller"
  description: "F5 BIG-IP http route Kubernetes Gateway"
---
apiVersion: gateway.k8s.f5net.com/v1
kind: Gateway
metadata:
  name: header-path-http-gateway
spec:
  addresses:
  - type: "IPAddress"
    value: <IP Address>
  gatewayClassName: header-path-http-gateway-class
  listeners:
  - name: http
    protocol: HTTP
    port: 8088
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: header-path-http-route
spec:
  parentRefs:
  - name: header-path-http-gateway
    sectionName: http
  rules:
    - matches:
      - path:
          type: PathPrefix
          value: /v1/chat/completions
        headers:
        - type: Exact
          name: Content-Type
          value: application/json
        - type: Exact
          name: env
          value: canary
      backendRefs:
      - name: llama-2-7b-chat
        port: 8000
    - backendRefs:
      - name: spk-app-http-8000-f5ing-testapp
        port: 8000

HTTPRoute CR for traffic weight distrubution

apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: distribute-http-gateway-class
spec:
  controllerName: "f5.com/f5-gateway-controller"
  description: "F5 BIG-IP Kubernetes Gateway"
---
apiVersion: gateway.k8s.f5net.com/v1
kind: Gateway
metadata:
  name: distribute-http-gateway
spec:
  addresses:
  - type: "IPAddress"
    value: <IP Address>
  gatewayClassName: distribute-http-gateway-class
  listeners:
  - name: foo
    protocol: HTTP
    port: 80
    allowedRoutes:
      kinds:
      - kind: HTTPRoute
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: distribute-http-app-1
spec:
  parentRefs:
  - name: distribute-http-gateway
    sectionName: foo
  rules:
  - backendRefs:
    - name: tcp-testapp-rg-0-f5ing-testapp
      port: 8050
      weight: 70
    - name: tcp-testapp-rg-1-f5ing-testapp
      port: 8050
      weight: 30