Gateway API is an open source project managed by the SIG-NETWORK community. The project aims to evolve service networking by providing expressive, extensible, and role-oriented interfaces. You can use Gateway API to define routing rules for accessing applications in a cluster. This topic shows you how to use Gateway API to define a routing rule for accessing an application in a cluster.
Prerequisites
- Create an ASM instance. For more information, see Create an ASM instance.
- A Container Service for Kubernetes (ACK) cluster is created. For more information, see Create a managed Kubernetes cluster.
- Add a cluster to the ASM instance. For more information, see Add a cluster to an ASM instance.
- The ingress gateway service is deployed. For more information, see Deploy an ingress gateway service.
Step 1: Deploy a sample application in an ACK cluster
Step 2: Configure Gateway API in an ASM instance
Step 3: Query the IP address of the ingress gateway
- Log on to the ACK console.
- In the left-side navigation pane of the ACK console, click Clusters.
- On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.
- In the left-side navigation pane of the details page, choose .
- At the top of the Services page, select istio-system from the Namespace drop-down list. Find the ingress gateway that is named istio-ingressgateway and view the IP address whose port is 80 in the External Endpoint column.
Verify the routing rule
- Run the following command to access the httpbin application:
curl -s -HHost:httpbin.aliyun.com "http://$INGRESS_HOST:$INGRESS_PORT/get"
Use the
-H
flag to set the Host HTTP header tohttpbin.aliyun.com
. The value of the Host HTTP header must be the same as the value of the hostnames parameter that is configured for the HTTPRoute.The following output is expected:
{ "args": {}, "headers": { "Accept": "*/*", "Content-Length": "0", "Host": "httpbin.aliyun.com", "My-Added-Header": "added-value", "User-Agent": "curl/7.75.0", "X-Envoy-Attempt-Count": "1", "X-Envoy-External-Address": "xxxxxx" }, "origin": "xxxxxx", "url": "http://httpbin.aliyun.com/get" }
- Run the following command to access the httpbin application:
curl -I -HHost:httpbin.aliyun.com "http://$INGRESS_HOST:$INGRESS_PORT/headers"
The following output is expected:
HTTP/1.1 404 Not Found
The application is accessed by using the URL that contains the get
parameter, but fails to be accessed by using the URL that contains the headers
parameter. This means that only URLs that contain the get
parameter can be used to access the httpbin application. The results indicate that
the routing rule that you defined by using Gateway API takes effect.