If an ALB Ingress points to a standard ALB instance, it supports query string-based traffic forwarding. This method uses query strings to determine the back-end Service to which traffic will be forwarded.
A query string is the segment of a URL that comes after the ? character, and is commonly used to send request parameters in the key-value pair format to a server. Its format is key=value, and it supports multiple parameters separated by the & character. For example, in the URL https://example.com/search?keyword=k8s&page=1, keyword=k8s and page=1 are the query string parameters.
Query strings are commonly used in GET requests to transmit non-sensitive data, such as search keywords and pagination information. Since parameters are exposed in the URL, they are not suitable for transmitting private content, for example, passwords. Special characters (such as spaces, Chinese characters) must be URL-encoded (for example: a space is encoded as %20) to avoid possible parsing errors.
- The alb-ingress-controller add-on has been installed and upgraded to v0.37.1 or later. For details, see Upgrading add-ons.
Creating through the console
- In the left navigation bar, click Cluster.
- On the cluster list page, click the target cluster for which you need to configure an Ingress.
- In the left navigation bar of the cluster management page, click Services and Ingresses > Ingress. Then click Create Ingress.
- Select Application Load Balancer (ALB) for Ingress type.
- In the Forwarding rules settings, select the Enable check box to configure custom forwarding rules.
An ALB Ingress allows you to configure query string-based forwarding by using annotations. The following is an example YAML with comments for annotations.
- The {{service-name}} field in the annotation must match the name of the back-end service configured in spec.rules. For example, in this case, the correct annotation is ingress.vke.volcengine.com/loadbalancer-conditions.service-demo.
- The QueryString configured in the annotation will be merged with the host configuration in spec.rules. For example, in this case, requests with example.com as the host and query string key1:value1 will all be forwarded to the service-demo service.
The following table describes fields in the ingress.vke.volcengine.com/loadbalancer-conditions.{{service-name}} annotation.
value
- Click Instance in the left navigation bar. In the instance list, find the target ALB instance and click Listener in the Actions column.
- On the listener details page, find the target listener. In the Actions column, click Edit forwarding rules to view the existing forwarding rules of the listener. Confirm that the query string matches the configured one.
Sending access requests for verification
tip
Before verification, make sure that you have deployed back-end applications and services in the cluster. In this example, an NGINX image is used and the service path is /demo. For deployment steps, see Using ALB Ingresses for service deployment. - Access the service by using the domain name configured in the ALB Ingress. In this example, 14.***.***.*** is the public IP address of the ALB instance.
Since no query string is provided in the result, the back-end service cannot be accessed correctly.
- Run the following command again to access the service using an allowed HTTP request method.
Since a matching query string is provided in the request, the back-end service can be accessed correctly.