You need to enable JavaScript to run this app.
Volcengine Kubernetes Engine

Volcengine Kubernetes Engine

Copy page
Download PDF
Customize ALB Ingress forwarding rules
Configuring traffic forwarding to multiple back-end services
Copy page
Download PDF
Configuring traffic forwarding to multiple back-end services
An ALB Ingress lets you configure multiple backend server groups in a forwarding rule and use either Services in the cluster or existing backend server groups. When a request passes through the ALB instance, the ALB instance can forward it to different back-end server groups based on weights.​
warning​
It is highly recommended that you first read Considerations for using ALB Ingresses carefully before getting started.​
Prerequisites​
  • The alb-ingress-controller add-on has been installed and upgraded to v0.35.0 or later. For details, see Upgrading add-ons.​
Procedure​
Creating through the console​
tip​
You can only use the console to configure an ALB ingress that uses a Standard edition ALB instance. To use a Basic edition ALB instance, see the following YAML configuration.​
  1. Log in to the VKE console.​
  1. In the left navigation bar, click Cluster.​
  1. On the cluster list page, click the target cluster for which you need to configure an Ingress.​
  1. In the left navigation bar of the cluster management page, click Services and Ingresses > Ingress. On the page that appears, click Create Ingress.​
  • Select Application Load Balancer (ALB) for Ingress type.​
  • Enable Custom forwarding rules and configure the details of the forwarding rules.​
​
Parameter​
Description​
Forwarding conditions​
Configure forwarding conditions, including the domain name, path, and HTTP header.​
  • Forwarding conditions can be configured individually or in combination. When multiple forwarding conditions are configured, the logical relationship between these forwarding conditions is AND. For example, if you configure both a domain name and a path in a forwarding rule, then only requests that match the specified domain name and path will match this forwarding rule.​
  • Multiple values can be configured within the same forwarding condition, and these values have a logical relationship of OR. For example, if you configure multiple values for a domain name condition, requests that match any of the values are a match for the rule.​
Forwarding actions​
The target service and port for forwarding. For this example, select the Forward to action.​
  • Service name: Select an existing service name in the cluster. If no service is available, create a service based on the instructions in Services.​
  • Port: Select the port number of the corresponding service.​
  • Weight: Specify the weight of the corresponding service. Valid values: 0 to 100.​
  • When the number of server groups is 1, the default weight is 100.​
  • When the weight of a server group is set to 0, ALB does not forward client traffic to that server group.​
tip​
When you configure multiple services, the sum of their weights is not required to be 100. The ALB instance can forward client traffic to the corresponding service by proportion based on the weight of each service. For details, see Server group weighting.​
​
  1. Click Confirm.​
Creating through kubectl​
You can specify multiple back-end server groups for an ALB Ingress by using annotations. The configuration slightly varies based on whether the ALB Ingress uses a Standard edition ALB instance or a Basic edition ALB instance.​
​
Standard edition ALB
Basic edition ALB
​
The following content provides sample configurations and annotation descriptions for an ALB Ingress that uses a Standard ALB instance.​
Warning​
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-actions.service-demo.​
​
apiVersion: networking.k8s.io/v1​
kind: Ingress​
metadata:​
name: alb-ingress # The custom Ingress name.​
namespace: default # Namespace of the Ingress​
annotations:​
ingress.vke.volcengine.com/loadbalancer-actions.{{service-name}}: | ​
[{​
"type": "ForwardGroup",​
"forwardGroupConfig": {​
"serverGroupStickySession": {​
"enabled": "on",​
"timeout": 100​
},​
"backends": [​
{​
"serviceName": "service-demo-a",​
"weight": 80,​
"servicePort": 80​
},​
{​
"serviceName": "service-demo-b",​
"weight": 20,​
"servicePort": 80​
}​
]​
}​
}]​
spec:​
ingressClassName: alb​
rules:​
- host: example.com​
http:​
paths:​
- pathType: Prefix​
path: /​
backend:​
service:​
name: service-demo # The service name. The name needs to be consistent with the value of {{service-name}} in the loadbalancer-actions.{{service-name}} annotation.​
port:​
name: use-annotation # The fixed value. When you configure multiple back-end server groups, port.name must be use-annotation.​
​
The following table describes fields in the ingress.vke.volcengine.com/loadbalancer-actions.{{service-name}} annotation.​
​
Parameter​
Type​
Description​
Default value​
type​
String​
The action type of the custom forwarding rule. If you want to forward traffic to multiple back-end server groups, you need to set the value to ForwardGroup.​
No​
forwardGroupConfig​
Object of​
StickySessionConfig​
The configuration of session persistence between back-end server groups.​
No​
backends​
Array of​
BackendConfig​
The configurations of the back-end servers.​
No​
​
StickySessionConfig​
​
Parameter​
Type​
Description​
default value​
serverGroupStickySession.enabled​
String​
Whether to enable the session persistence feature between back-end service groups. Valid values:​
  • on: enable​
  • off: disable​
off​
serverGroupStickySession.timeout​
Integer​
Configure the session persistence timeout between back-end server groups.​
  • Valid values: 1 to 86400. Unit: seconds.​
  • Default value: 1000.​
1000​
​
BackendConfig​
​
Parameter​
Type​
Description​
Default value​
serviceName​
String​
The name of the back-end service. If no service is available, create a service based on the instructions in Services.​
No​
weight​
Integer​
The weight of the back-end service. Valid values: 0 to 100.​
  • When the number of server groups is 1, the default weight is 100.​
  • When the weight of a server group is set to 0, ALB does not forward client traffic to that server group.​
tip​
When you configure multiple services, the sum of their weights is not required to be 100. The ALB instance can forward client traffic to the corresponding service by proportion based on the weight of each service. For details, see Server group weighting.​
No​
servicePort​
Integer​
The port number of the back-end service. The value can range from 1 to 65535.​
No​
​
​
​
Validating results​
Viewing configuration​
tip​
The details pages of forwarding rules differ between Standard edition ALB instances and Basic edition ALB instances. This topic provides an example of viewing the details page of a forwarding rule for a Standard edition ALB instance.​
  1. Log in to the ALB console.​
  1. Click Instance in the left navigation bar. In the instance list, find the target ALB instance and click Listener in the Actions column.​
  1. 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. You can see multiple back-end server groups. The rule details should be consistent with the configured ones.​
  1. For a forwarding rule, click ​alt​ to view rule details. The rule details should be consistent with the configured ones.​
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 /. 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.​
​
curl -H "Host: example.com" http://14.***.***.***​
​
The expected result is as follows: When the requested domain is example.com and the original path is /, the service is accessible through the ALB Ingress.​
​
<!DOCTYPE html>​
<html>​
<head>​
<title>Welcome to nginx!</title>​
<style>​
html { color-scheme: light dark; }​
body { width: 35em; margin: 0 auto;​
font-family: Tahoma, Verdana, Arial, sans-serif; }​
</style>​
</head>​
<body>​
<h1>Welcome to nginx!</h1>​
<p>If you see this page, the nginx web server is successfully installed and​
working. Further configuration is required.</p>​
​
<p>For online documentation and support please refer to​
<a href="http://nginx.org/">nginx.org</a>.<br/>​
Commercial support is available at​
<a href="http://nginx.com/">nginx.com</a>.</p>​
​
<p><em>Thank you for using nginx.</em></p>​
</body>​
</html>​
​
You specified multiple back-end server groups for the ALB Ingress, and configured different services and weights for each back-end server group. If you access the service multiple times, traffic is forwarded to different back-end server groups according to the weight ratio. For example, execute the following command to send 20 access requests:​
​
for i in {1..20}; do curl -H "Host: example.com" http://14.***.***.***; done;​
​
The expected result is that traffic is forwarded to different back-end server groups according to the weights specified in the configuration.​
​
This is the new version of nginx​
This is the new version of nginx​
This is the new version of nginx​
This is the old version of nginx​
This is the new version of nginx​
This is the new version of nginx​
This is the new version of nginx​
This is the new version of nginx​
This is the new version of nginx​
This is the old version of nginx​
This is the new version of nginx​
This is the old version of nginx​
This is the new version of nginx​
This is the new version of nginx​
This is the new version of nginx​
This is the old version of nginx​
This is the new version of nginx​
This is the new version of nginx​
This is the new version of nginx​
This is the new version of nginx​
​
​
Last updated: 2026.10.16 16:55:40