Gateway API is the next-generation traffic routing standard defined by the Kubernetes community. APIG supports Gateway API. This topic describes how to enable Gateway API capabilities via APIG, and expose in-cluster services to external users through declarative Gateway and HTTPRoute resources.
tip
[Beta · apply for trial]: This feature is currently in Beta. To use this feature, contact your account manager.
Gateway API is the next-generation service networking routing specification defined by the Kubernetes SIG-Network community. It provides standardized, extensible, role-separated declarative interfaces for cluster traffic governance. Compared with the traditional Ingress API, Gateway API adopts a more granular resource hierarchy model that clearly separates responsibilities among infrastructure administrators (GatewayClass), cluster operators (Gateway), and application developers (HTTPRoute). In addition, Gateway API natively supports advanced routing capabilities such as multi-protocol, multi-tenant, traffic weighting, and header matching capabilities.
APIG is fully compatible with the Kubernetes Gateway API standard. You only need to create compliant Gateway and HTTPRoute resources in the container cluster, and APIG will automatically synchronize configurations and distribute routes, achieving the transition from declarative definition to traffic forwarding. The resources currently supported by APIG are as follows.
- You have created a VKE cluster with version v1.24 or higher. For detailed operations, see Creating clusters.
Step 1: Configure Gateway API synchronization
- Select the target region in the top navigation bar.
- In the left-side navigation pane, select the target instance from the Instance management drop-down list. Then, click Import container cluster.
- On the Custers page, click Import cluster.
- On the "Import cluster" page, select the cluster to be imported. In the Gateway API synchronization section, configure Gateway Class and Namespace as needed. Currently, only one Gateway Class type is supported. Then, click Confirm.
Step 2: Install Gateway API CRD
You must first establish a connection between your VKE cluster and kubectl, then perform the following and subsequent operations in the kubectl client. For detailed operations, see Connecting to a cluster via kubectl. Execute the following command to install the Gateway API CRD for your container cluster. If it is already installed, skip this step.
tip
The highest compatible version of Gateway API CRD for the current gateway is v1.4.0. The above command uses Gateway API CRD version v1.4.0 as an example, which is not mandatory.
Step 3: Deploy a sample application
- Create the nginx-demo.yaml file with the following content.
- Execute the following command to deploy the application.
- Execute the following command to check the application's running status.
- The expected result is as follows. When the STATUS is Running, it indicates that the application is running.
Step 4: Deploy Gateway and route
- Customize GatewayClass and create the gatewayclass.yaml file.
- Execute the following command to deploy GatewayClass.
- Create the gateway.yaml file to configure Gateway and route, with the following content.
tip
- When backendRefs points to the backend corresponding to the Inference Service, the controller will, based on the current watch logic, translate it into a container-type Upstream on the APIG side. The weight and match condition of HTTPRoute are still processed based on Gateway API semantics. Data plane capabilities are jointly carried by APIG Route and the container-type Upstream.
- Execute the following command to deploy Gateway and routing rules.
- Wait about 2 minutes, then execute the following command to check the Gateway status.
- The expected result is as follows. When the PROGRAMMED status is True, it indicates that the Gateway is ready.
- Confirm that the route listening has taken effect.
- Select the target region in the top navigation bar.
- In the left-side navigation pane, select the target instance from the Instance management drop-down list. Then, click Route list. If the list includes the Gateway API route created on the container side, it indicates that the route listening has taken effect.
Step 5: Test application access
- In the left-side navigation pane, select the target instance from the Instance management drop-down list. Then, click Instance overview.
- In the Access portal section, obtain the gateway access point address.
- Execute the following command to access the application. Before the execution, replace the gateway access point address with the actual address you obtained.
- The expected output is as follows:
Scenario 1: Split traffic by weight
If you set weights for multiple backend services, requests will be distributed proportionally to different services. This approach is commonly used in canary releases.
- Create the nginx.yaml file and deploy two nginx applications. The old-nginx service returns the string This is the old version of nginx, while the new-nginx service returns the string This is the new version of nginx.
- Create the httproute-weight.yaml file.
tip
The weight field specifies the relative weight value. In the above configuration, approximately 90% of the traffic is routed to old-nginx, while 10% of the traffic is routed to new-nginx.
- Execute the following commands to deploy the application and routing rules.
- Execute the following commands to access the application multiple times and verify traffic distribution.
- The expected result is as follows: most responses are This is the old version of nginx, only a few responses are This is the new version of nginx, with a ratio close to 9:1.
Scenario 2: Header-based canary routing
You can configure a header match rule to route traffic carrying specific request headers to the canary service, while traffic without those headers is routed to the stable version. This method is commonly used to validate the canary version without impacting online users.
- Based on the previous deployment example, deploy the canary service for nginx-demo. Create the nginx-canary.yaml file, where the new-canary service returns the string This is the new version of nginx.
- Execute the following command to deploy the canary application nginx-canary.
- Create the httproute-canary.yaml file and configure header-based canary routing rules. This configuration defines two routing rules: Traffic carrying the request header env: canary is routed to the canary version nginx-canary, while other traffic is routed to the stable version nginx-demo.
- Execute the following command to deploy the routing rules.
- Execute the following command to access the stable version when the specified header is not carried. Before the execution, replace the gateway access point address with the actual address you obtained in step 5.
- The expected result is as follows, which indicates successful access to the stable version nginx-demo.
- Execute the following command to access the canary version when the env: canary request header is carried. Before the execution, replace the gateway access point address with the actual address you obtained in step 5.
- The expected result is as follows, which indicates successful access to the canary version nginx-canary.
Scenario 3: Route selection and weighted traffic distribution based on OpenAI protocol header
In AI inference service scenarios, clients typically send requests via the OpenAI-compatible protocol and carry organization identifiers (such as OpenAI-Organization) or project identifiers (such as OpenAI-Project) in the HTTP headers. By leveraging the matches.headers capability of HTTPRoute, you can achieve routing based on these protocol headers. When a header condition is matched, weighted traffic splitting can be implemented via backendRefs.weight within the corresponding rule. This method is widely used for canary releases of AI models.
This example reuses the old-nginx and new-nginx services deployed in "Scenario 1" to demonstrate how to route traffic to different backends based on the OpenAI protocol header, and allocate traffic by weight within the match rules.
- Create the httproute-openapi.yaml file.
tip
- Rule 1: When the request path starts with /v1 and carries Header OpenAI-Organization: org-a, 90% of the traffic is routed to old-nginx, while 10% of the traffic is routed to new-nginx, enabling a canary release for a specific organization.
- Rule 2: When the request path starts with /v1 and carries Header OpenAI-Project: project-b, all traffic is routed to new-nginx, enabling a full switch for a specific project.
- Execute the following command to deploy the routing rules.
- Execute the following command to carry the OpenAI-Organization: org-a header for multiple accesses, and verify the weighted routing at the organization level.
- The expected result is as follows: most responses are This is the old version of nginx, only a few responses are This is the new version of nginx, with a ratio close to 9:1.
- Execute the following command to carry the OpenAI-Project: project-b header for access, and verify the full routing at the project level.
- The expected result is as follows. Under this rule, all traffic is routed to new-nginx. Therefore, every access returns the content of the new version.