Backends

Use a Backend resource to define a backing destination that you want kgateway to route to. A Backend destination is external to the cluster and, as such, cannot be represented as a Kubernetes Service. For more information, see the Backend API docs.

Types

Check out the following guides for examples on how to use the supported Backends types with kgateway.

Routing

You can route to a Backend by simply referencing that Backend in the backendRefs section of your HTTPRoute resource as shown in the following example. Note that if your Backend and HTTPRoute resources exist in different namespaces, you must create a Kubernetes ReferenceGrant resource to allow the HTTPRoute to access the Backend.

⚠️
Do not specify a port in the spec.backendRefs.port field when referencing your Backend. The port is defined in your Backend resource and ignored if set on the HTTPRoute resource.
backend-httproute.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: static-backend
  namespace: default
spec:
  parentRefs:
  - name: http
    namespace: kgateway-system
  hostnames:
    - static.example
     rules:
       - backendRefs:
         - name: json-backend
           kind: Backend
           group: gateway.kgateway.dev
         filters:
         - type: URLRewrite
           urlRewrite:
             hostname: jsonplaceholder.typicode.com
   EOF

For an example, see the Static Backend guide.