Service Mesh ASM provides cross-region traffic distribution and cross-region failover capabilities for application services. Cross-region traffic distribution routes traffic to multiple clusters based on configured weights, enabling multi-region load balancing. Cross-region failover shifts traffic from a failed region to other regions, achieving cross-region disaster recovery. Using the Bookinfo application as an example, this topic describes how to use cross-region failover and traffic distribution to implement cross-region disaster recovery and load balancing.
Network planning
Before you begin, plan the CIDR blocks, names, and other details for your vSwitches, VPCs, and clusters. This topic uses the following plan:
For more information about multi-cluster address planning for the data plane, see Multi-cluster network planning.
vSwitch and VPC network planning
VPC network planning
Object
VPC name
Region
IPv4 CIDR block
Cluster
vpc-hangzhou
cn-hangzhou
20.0.0.0/8
vpc-shanghai
cn-shanghai
21.0.0.0/8
Service Mesh
vpc-hangzhou2
cn-hangzhou
192.168.0.0/16
vSwitch network planning
ImportantTo avoid route conflicts after connecting VPCs using CEN, ensure that the two vSwitches do not use overlapping CIDR blocks.
Object
vSwitch name
VPC
IPv4 CIDR block
Cluster
vpc-hangzhou-switch-1
vpc-hangzhou
20.0.0.0/16
vpc-shanghai-switch-1
vpc-shanghai
21.0.0.0/16
Service Mesh
vpc-hangzhou-switch-2
vpc-hangzhou2
192.168.0.0/24
Pod and Service network planning for clusters
Cluster name
Region
VPC
Pod CIDR
Service CIDR
ack-hangzhou
cn-hangzhou
vpc-hangzhou
10.0.0.0/16
172.16.0.0/16
ack-shanghai
cn-shanghai
vpc-shanghai
10.1.0.0/16
172.17.0.0/16
Step 1: Create clusters in different regions
Create VPCs and vSwitches in the China (Hangzhou) and China (Shanghai) regions according to the preceding plan. For more information, see Create a vSwitch and Create a VPC and a vSwitch.
Create clusters in the China (Hangzhou) and China (Shanghai) regions using the VPCs and network plan described earlier. For more information, see Create an ACK managed cluster.
Create an ASM instance in the China (Hangzhou) region according to the preceding plan. For more information, see Create an ASM instance.
Step 2: Use CEN to connect VPCs across regions
Use CEN to connect the VPC networks between clusters and between clusters and the Service Mesh.
Log on to the Cloud Enterprise Network console and create a CEN instance. For more information, see Create a Cloud Enterprise Network instance.
Create transit routers.
On the Cloud Enterprise Network instances page, click the CEN instance created in Step 1. Then, under the Basic Information tab, click Create Transit Router.
In the Create Transit Router dialog box, select a Region, enter a Name, and then click Confirm.
This example creates two transit routers:
Region: China (Shanghai), Name: shanghai-router.
Region: China (Hangzhou), Name: hangzhou-router.
Add VPCs to the transit routers. Repeat the following steps for both the Shanghai and Hangzhou transit routers to connect their respective VPCs.
On the Cloud Enterprise Network instances page, click the CEN instance created in Step 1. Then, under the Basic Information tab, click the ID of the newly created transit router to go to its details page.
Click the Intra-region Connections tab, and then click Create Network Instance Connection. Set Instance Type to Virtual Private Cloud (VPC), and select the VPC instance corresponding to the region for Network Instance.
Keep other settings at their default values and click Create.
Configure cross-region bandwidth.
Click the transit router created in Step 2. On the right side of the page, click Create Network Instance Connection.
In the Connect Network Instance dialog box, configure the settings and click Create.
The following example shows the configuration for Hangzhou to Shanghai. Region refers to the current region, and Peer Region refers to the destination region. For more information about configuration options, see Inter-region connection. Configure the following settings: set Instance Type to Inter-region Connection, Region to China (Hangzhou), Connection Name to
to-shanghai, Peer Region to China (Shanghai), Bandwidth Allocation Method to Pay-by-Data-Transfer, and Bandwidth to1Mbps. Expand Advanced Configuration and select the following check boxes: Automatically Associate with Default Route Table of Transit Router, Automatically Propagate System Routes to Default Route Table of Transit Router, and Automatically Publish Routes to Peer Region.After creation, you can view the new instance on the Inter-region Connections tab.
Add security group rules.
The following example uses the Flannel network plug-in. Add the Pod CIDR block of the peer cluster to the security group of each cluster.
NoteIf you use the Terway network plug-in, use the vSwitch CIDR block of the cluster. You can log on to the VPC console and find the vSwitch CIDR block in the vSwitch page under the IPv4 CIDR column.
-
Log on to the ACK console. In the left navigation pane, click Clusters.
Obtain the Pod CIDR blocks.
On the Clusters page, select the China (Shanghai) region, click the ack-shanghai cluster name, and then on the Cluster Information page, go to the Basic Information tab to obtain the Pod CIDR block for the ack-shanghai cluster.
Return to the Clusters page, select the China (Hangzhou) region, click the ack-hangzhou cluster name, and then on the Cluster Information page, go to the Basic Information tab to obtain the Pod CIDR block for the ack-hangzhou cluster.
Configure security groups.
On the Cluster Information page for each cluster, go to the Basic Information tab and click the security group ID next to Control Plane Security Group.
On the Security Group Details tab, under Inbound, click Add Rule.
Set Protocol Type to All, set Source to the Pod CIDR block of the peer cluster, keep other settings at their defaults, and then click Actions → Save.
Log on to nodes in both clusters and use the ping command to test connectivity between the clusters. For more information, see Log on to a node.
-
Step 3: Add clusters to the ASM instance and create a managed ingress gateway
Add the clusters in the China (Hangzhou) and China (Shanghai) regions to the ASM instance. For more information, see Add a cluster to an ASM instance.
Create an ingress gateway.
apiVersion: istio.alibabacloud.com/v1beta1 kind: IstioGateway metadata: annotations: asm.alibabacloud.com/managed-by-asm: 'true' name: ingressgateway namespace: istio-system spec: gatewayType: ingress dnsPolicy: ClusterFirst externalTrafficPolicy: Local hostNetwork: false ports: - name: http port: 80 protocol: TCP targetPort: 80 - name: https port: 443 protocol: TCP targetPort: 443 replicaCount: 1 resources: limits: cpu: '2' memory: 2G requests: cpu: 200m memory: 256Mi rollingMaxSurge: 100% rollingMaxUnavailable: 25% runAsRoot: true serviceType: LoadBalancer
Step 4: Deploy the Bookinfo demo application
The following steps require switching kubeconfig contexts multiple times. We recommend that you configure both cluster kubeconfigs in the same config file and use kubectl config use-context to switch contexts. You can also use kubecm or kubectx to manage kubeconfig files for multiple clusters.
Deploy the Bookinfo application in both the ack-hangzhou and ack-shanghai clusters.
kubectl apply -f bookinfo.yamlConnect to the ASM instance using kubectl and create routing rules.
Create asm.yaml with the following content.
Create the routing rules.
kubectl apply -f asm.yaml
Verify that the Bookinfo application is deployed successfully.
Obtain the ingress gateway address.
-
In the address bar of your browser, enter http://{IP address of the ingress gateway}/productpage and refresh the page several times to observe the default round-robin routing.
Each time you refresh the page, you access one of the v1, v2, or v3 versions of the reviews service. You will notice that traffic to the three versions of the reviews service is distributed in an approximately 1:1:1 ratio.
The reviews-v1 page displays only text reviews with no star ratings, the reviews-v2 page displays black star ratings, and the reviews-v3 page displays red star ratings.
Step 5: Use cross-region failover and cross-region traffic distribution
Configure cross-region failover
Disable the reviews service in the ack-hangzhou cluster.
-
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
On the Deployments page, set the Namespace to default and click Scale in the Actions column to the right of reviews-v1.
In the Scale dialog box, set Desired Number of Pods to 0 and click OK.
-
Configure the DestinationRule.
Configure the DestinationRule so that if the reviews service cannot be reached within 1 second, it is ejected for 1 minute.
-
On the details page of the ASM instance, choose in the left-side navigation pane.
On the DestinationRule page, click YAML in the Actions column next to reviews.
In the Edit panel, add the following content and click OK.
spec: ...... trafficPolicy: connectionPool: http: maxRequestsPerConnection: 1 outlierDetection: baseEjectionTime: 1m consecutive5xxErrors: 1 interval: 1smaxRequestsPerConnection: maximum number of requests per connection.
baseEjectionTime: minimum ejection duration.
consecutive5xxErrors: number of consecutive errors.
interval: interval between ejection checks.
-
Enable cross-region failover.
-
On the details page of the ASM instance, choose in the left-side navigation pane.
ASM instance version earlier than 1.22.6.66
On the Base Information page, click Geolocation-based Load Balancing to the right of Setting.
In the Geolocation-based Failover dialog box, set it so that when the policy source is cn-shanghai, fail over to cn-hangzhou, and when the policy source is cn-hangzhou, fail over to cn-shanghai. Then, click Submit.
ASM instance version 1.22.6.66 or later
On the Base Information page, click Geolocation-based Load Balancing to the right of Setting.
Click Specify priority rules for regions under Cross-region Rules. Set Failed Region to
cn-shanghaiand The region to which the traffic is preferentially routed tocn-hangzhou.Click Add. Then set Failed Region to
cn-hangzhouand Preferred Failover Region tocn-shanghai. Click Save.
-
Run the following command to send 10 requests to the Bookinfo application and count how many times the request is routed to the v2 version of the reviews service.
for ((i=1;i<=10;i++));do curl http://<ingress gateway address on port 80 in ack-hangzhou cluster>/productpage 2>&1|grep full.stars;done|wc -lExpected output:
20You will see 20 lines returned from 10 requests (each request routed to the v2 reviews service returns two lines containing
full stars), indicating that all 10 requests were routed to the v2 reviews service in the ack-shanghai cluster. Cross-region failover succeeded.
Configure cross-region traffic distribution
Cross-region traffic distribution is supported only for ASM instances of version 1.22.6.66 or later.
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose .
On the Base Information page, click Geolocation-based Load Balancing to the right of Configure a Geolocation-based Load Balancing.
Click Configure a traffic distribution rule. Set Source to
cn-hangzhou, Destination tocn-shanghai, and Traffic Percentage to 10%. Click Save.NoteBy default, geolocation-based load balancing uses failover mode. You must first click Disable in the upper-right corner of the page before you can switch to and enable traffic distribution mode.
Run the following command to send 10 requests to the Bookinfo application and verify that cross-region traffic distribution works.
for ((i=1;i<=10;i++));do curl http://<ingress gateway address on port 80 in ack-hangzhou cluster>/productpage 2>&1|grep full.stars;doneExpected output:
<!-- full stars: --> <!-- full stars: -->You will see two lines containing
full starsfrom 10 requests, indicating that 9 requests were routed to the v1 reviews service in the ack-hangzhou cluster and 1 request was routed to the v2 reviews service in the ack-shanghai cluster. Traffic was successfully distributed across clusters based on the configured weights.
FAQ
Why does adding a Kubernetes cluster to ASM fail even though I connected the cluster VPCs using Cloud Enterprise Network (CEN)?
If your clusters are in different regions and you have not purchased a cross-region data transfer plan or correctly configured cross-region traffic, the ASM control plane cannot connect to the data plane clusters, causing the cluster addition to fail.
To resolve this issue, reconfigure cross-region traffic in Cloud Enterprise Network (CEN) to connect the cluster VPCs. For more information, see Step 2: Use CEN to connect VPCs across regions.