Configuring Advanced Forwarding Rules for a LoadBalancer Ingress
Ingresses offer diverse forwarding rules that can match listeners based on different request parameters like HTTP request methods, headers, query strings, CIDR blocks, and cookies. Each listener is associated with an ELB access port. This facilitates flexible service distribution and resource allocation.

Prerequisites
- A CCE standard or Turbo cluster is available, and the cluster version meets the following requirements:
- v1.23: v1.23.18-r10 or later
- v1.25: v1.25.16-r0 or later
- v1.27: v1.27.16-r0 or later
- v1.28: v1.28.13-r0 or later
- v1.29: v1.29.8-r0 or later
- v1.30: v1.30.4-r0 or later
- Other clusters of later versions
- The cluster can be accessed using kubectl. For details, see Connecting to a Cluster Using kubectl.
Notes and Constraints
- This feature is only available when dedicated load balancers are used.
- This feature relies on the ELB advanced forwarding policies. Once the ELB advanced forwarding policies are enabled, the forwarding policy priority is not determined by the domain name or path matching. You can customize the forwarding policy priority as needed. For details about the forwarding policy priority, see Forwarding Policy Priorities of LoadBalancer Ingresses.
Using kubectl
- Use kubectl to access the cluster. For details, see Connecting to a Cluster Using kubectl.
- Create a YAML file named ingress-test.yaml. The file name can be customized.
vi ingress-test.yaml
An example YAML file of an ingress created using an existing load balancer is as follows:apiVersion: networking.k8s.io/v1 kind: Ingress metadata: annotations: kubernetes.io/elb.class: performance kubernetes.io/elb.id: ab53c3b2-xxxx-xxxx-xxxx-5ac3eb2887be kubernetes.io/elb.port: '80' # Access the svc-hello1 service. Ensure that this service is available. kubernetes.io/elb.conditions.svc-hello1: | [ { "type": "Method", "methodConfig": { "values": [ "GET", "POST" ] } }, { "type": "Header", "headerConfig": { "key": "gray-hello", "values": [ "value1", "value2" ] } }, { "type": "Cookie", "cookieConfig": { "values": [ { "key": "querystringkey1", "value": "querystringvalue2" }, { "key": "querystringkey3", "value": "querystringvalue4" } ] } }, { "type": "QueryString", "queryStringConfig": { "key": "testKey", "values": [ "testValue" ] } }, { "type": "SourceIp", "sourceIpConfig": { "values": [ "192.168.0.0/16", "172.16.0.0/16" ] } } ] name: ingress-test spec: ingressClassName: cce rules: - http: paths: - path: /hello1 pathType: ImplementationSpecific backend: service: name: svc-hello1 port: number: 80
Table 1 Annotations for advanced forwarding rules Parameter
Type
Description
kubernetes.io/elb.conditions.${svc_name}
String
Configure an advanced forwarding rule. ${svc_name} indicates the Service name, which can contain a maximum of 48 characters.
If the annotation value is set to [], the advanced forwarding rule is deleted.
An annotation value is in the form of a JSON array. For details, see Table 2.
NOTICE:The rules in a condition array are connected by an AND relationship, while the values in the same rule block are connected by an OR relationship. For example, if both Method and QueryString are configured, the target traffic can be distributed only when both rules are met. However, if the Method value is GET or POST, the target traffic can be distributed only when both rules are met and the Method value must be GET or POST.
- Create an ingress.
kubectl create -f ingress-test.yaml
If information similar to the following is displayed, the ingress has been created:
ingress/ingress-test created
- Check the created ingress.
kubectl get ingress
If information similar to the following is displayed, the ingress has been created:NAME CLASS HOSTS ADDRESS PORTS AGE ingress-test cce * 121.**.**.** 80 10s
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot