Kubernetes Gateway API

Kuma supports Kubernetes Gateway API for configuring built-in gateway as well as traffic routing using the experimental GAMMA routing spec.

Installation

Checkout our dedicated installation guide.

Customization

Gateway API provides the parametersRef field on GatewayClass.spec to provide additional, implementation-specific configuration to Gateways. When using Gateway API with Kuma, you can refer to a MeshGatewayConfig resource:

  1. apiVersion: gateway.networking.k8s.io/v1
  2. kind: GatewayClass
  3. metadata:
  4. name: kuma
  5. spec:
  6. controllerName: gateways.kuma.io/controller
  7. parametersRef:
  8. kind: MeshGatewayConfig
  9. group: kuma.io
  10. name: kuma

This resource has the same structure as the MeshGatewayInstance resource except that the tags field is optional. With a MeshGatewayConfig you can then customize the generated Service and Deployment resources.

Multi-mesh

You can specify a Mesh for Gateway and HTTPRoute resources by setting the kuma.io/mesh annotation Note that HTTPRoutes must also have the annotation to reference a Gateway from a non-default Mesh.

Cross-mesh

Cross-mesh gateways are supported with Gateway API. You’ll just need to create a corresponding GatewayClass pointing to a MeshGatewayConfig that sets crossMesh: true:

  1. apiVersion: gateway.networking.k8s.io/v1
  2. kind: GatewayClass
  3. metadata:
  4. name: kuma-cross-mesh
  5. spec:
  6. controllerName: gateways.kuma.io/controller
  7. parametersRef:
  8. group: kuma.io
  9. kind: MeshGatewayConfig
  10. name: default-cross-mesh
  11. ---
  12. apiVersion: kuma.io/v1alpha1
  13. kind: MeshGatewayConfig
  14. metadata:
  15. name: default-cross-mesh
  16. spec:
  17. crossMesh: true

and then reference it in your Gateway:

  1. apiVersion: gateway.networking.k8s.io/v1
  2. kind: Gateway
  3. metadata:
  4. name: kuma
  5. namespace: default
  6. spec:
  7. gatewayClassName: kuma-cross-mesh
  8. listeners:
  9. - name: proxy
  10. port: 8080
  11. protocol: HTTP

Multi-zone Deployments

The Gateway API supports multi-zone deployments, but with some limitations:

  • Gateway API resources like Gateway, ReferenceGrant, and HTTPRoute must be created in non-global zones.

  • Only services deployed within the same Kubernetes cluster, such as the HTTPRoute, can be referenced via backendRef.

    Important Note: This limitation exist because, Kuma currently only allows referencing as backendRefs Kubernetes Services.

    This is a temporary limitation. We’re actively working on extending backendRef to support Kuma’s MeshServices. Once this feature is complete, you’ll be able to reference services across different clusters within your mesh.

    To better visualize this limitation here’s an example scenario that describes how you could configure multi-zone deployments with the Gateway API. In this example, you have the following resources:

    • Two zones (zone-1 and zone-2) in separate Kubernetes clusters

    • Gateway with listener on port 8080 deployed in zone-1

    • Two services:

      • A service named backend deployed in each zone

      • A service named db deployed only in zone-2

    1. flowchart TD
    2. subgraph c2["k8s-cluster-2"]
    3. subgraph z2["zone-2"]
    4. subgraph c1z2s1["Service"]
    5. b2(backend)
    6. end
    7. subgraph c1z2s2["Service"]
    8. db(db)
    9. end
    10. end
    11. end
    12. subgraph c1["k8s-cluster-1"]
    13. subgraph z1["zone-1"]
    14. subgraph Gateway
    15. listener(:8080)
    16. end
    17. subgraph Service
    18. b1(backend)
    19. end
    20. end
    21. end

    If you deploy multi-zone with Gateway API, the following will occur:

    • If you create an HTTPRoute with a backendRef targeting the backend service in k8s-cluster-1, it will only route traffic to the backend service in k8s-cluster-1.
    1. flowchart TD
    2. subgraph c2["k8s-cluster-2"]
    3. subgraph z2["zone-2"]
    4. subgraph c1z2s1["Service"]
    5. backend2(backend)
    6. end
    7. subgraph c1z2s2["Service"]
    8. db(db)
    9. end
    10. end
    11. end
    12. subgraph c1["k8s-cluster-1"]
    13. subgraph z1["zone-1"]
    14. subgraph Service
    15. backend1(backend)
    16. end
    17. subgraph Gateway
    18. listener(:8080)
    19. end
    20. subgraph HTTPRoute
    21. route1(/)
    22. end
    23. route1--"❌"-->backend2
    24. linkStyle 0 stroke:red,color:red,stroke-dasharray: 5 5;
    25. route1-->backend1
    26. listener-->route1
    27. end
    28. end
    • Similarly, if you create an HTTPRoute with a backendRef pointing to the db service in k8s-cluster-1, it will result in a HTTPRoute with a ResolvedRefs status condition of BackendNotFound because service db is not present in k8s-cluster-1.
    1. flowchart TD
    2. subgraph c2["k8s-cluster-2"]
    3. subgraph z2["zone-2"]
    4. subgraph c1z2s1["Service"]
    5. backend2(backend)
    6. end
    7. subgraph c1z2s2["Service"]
    8. db(db)
    9. end
    10. end
    11. end
    12. subgraph c1["k8s-cluster-1"]
    13. subgraph z1["zone-1"]
    14. subgraph Gateway
    15. listener(:8080)
    16. end
    17. subgraph HTTPRoute
    18. route1(/)
    19. end
    20. subgraph Service
    21. backend1(backend)
    22. end
    23. route1--"❌"-->db
    24. linkStyle 0 stroke:red,color:red,stroke-dasharray: 5 5;
    25. listener-->route1
    26. end
    27. end

Service to service routing

Kuma also supports routing between services with HTTPRoute in conformance with the GAMMA specifications.

GAMMA is a Gateway API subproject focused on mesh implementations of Gateway API and extending the Gateway API resources to mesh use cases.

The key feature of HTTPRoute for mesh routing is specifying a Kubernetes Service as the parentRef, as opposed to a Gateway. All requests to this Service are then filtered and routed as specified in the HTTPRoute.

  1. apiVersion: gateway.networking.k8s.io/v1
  2. kind: HTTPRoute
  3. metadata:
  4. name: canary-demo-app
  5. namespace: kuma-demo
  6. spec:
  7. parentRefs:
  8. - name: demo-app
  9. port: 5000
  10. kind: Service
  11. rules:
  12. - backendRefs:
  13. - name: demo-app-v1
  14. port: 5000
  15. - name: demo-app-v2
  16. port: 5000

The namespace of the HTTPRoute is key. If the route’s namespace and the parentRef’s namespace are identical, Kuma applies the route to requests from all workloads. If the route’s namespace differs from its parentRef’s namespace, the HTTPRoute applies only to requests from workloads in the route’s namespace.

Remember to tag your Service ports with appProtocol: http to use them in an HTTPRoute!

Because of how Kuma maps resources at the moment, the combination of the HTTPRoutes name and namespace and the parent Service name and namespace must be no more than 249 characters.

How it works

Kuma includes controllers that reconcile Gateway API CRDs and convert them into the corresponding Kuma CRDs. This is why in the GUI, Kuma MeshGateways/MeshHTTPRoutes/MeshTCPRoutes are visible and not Kubernetes Gateway API resources.

Kubernetes Gateway API resources serve as the source of truth for Kuma gateways and routes. Any edits to the corresponding Kuma resources are overwritten.