2

I want to set up two backends in the same load balancing on GCP, and route traffic to the second backend only after the first backend fails.

I tried the following configuration for testing: we set up two backends in the backend service configuration with the balancing mode set to Utilization. We set the capacity of the backup backend to 0. However, in this case, we found that traffic still cannot be routed to the backup backend after the primary origin server fails.

Duojie
  • 23
  • 4
  • can you share what test did you make for this scenario and what documentation you are following for this set up? – Yvan G. Mar 15 '23 at 22:11
  • Thank you for your reply, I did the test above has been said, the reference document is the address is: https://cloud.google.com/load-balancing/docs/https#classic-global-td – Duojie Mar 16 '23 at 06:51
  • What I am actually referring to is how you send traffic to your load balancer and detect that it is not routed to another backend. What are the results, did it drop from the first backend. This information is needed for we might see something from the error message that can give us what we need to check the concern. – Yvan G. Mar 16 '23 at 21:40
  • Another way we can do is through [TCP load balancer failover](https://cloud.google.com/load-balancing/docs/network/networklb-setting-up-failover) depends is this load balancer fits in your set up. There is an option here where you can choose if your backend is for failover. – Yvan G. Mar 16 '23 at 21:43

2 Answers2

0

I replicate this concern using an https external load balancer. What I did is create two backend service. In this case, in order for you to understand the flow of the traffic of the load balancer you can review traffic distribution on this link.

I used this command "for ((i=0;i<50;i++)); do curl -w "%{time_total}\n" -o /dev/null -s http://LB IP address; done" (change LB IP address by using your own load balancer ip address) in cloud shell to monitor the traffic. The right way to know if the traffic will flow to a different backend once the other backend fails is to turn off the VM instance you use in your instance group.

In my scenario, first I infused traffic to the load balancer and monitored the traffic, it distributed the traffic on both backend to reach both instances. Then I turn off one of my VM instance associated in one of my backend and did test again. What happens is all traffic is distributed to available backend.

Yvan G.
  • 753
  • 1
  • 8
  • 1
    Thank you for your reply. The difference is that I want only A backend to provide service when both backends are normal, and B backend to provide service only when A is down. Previously, I tested by setting the capacity of both backends, and found that I could not achieve the expected effect, and the traffic could not be switched. – Duojie Mar 23 '23 at 09:25
0

Now, I write messages to Pub/Sub by configuring Monitoring Alert, which triggers Cloud Function to patch the configuration of the backend service. The current method first can achieve, for example, after the appearance of the Http 5xx status code, automatically adjust the capacity of the back-end service.

The above is a method I tested, I do not know if GCP has other more convenient and faster methods can be used.

The following code is my reference to the GCP client library to use:

from pprint import pprint
    
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

credentials = GoogleCredentials.get_application_default()

service = discovery.build('compute', 'v1', credentials=credentials)

# Project ID for this request.
project = 'my-project'  # TODO: Update placeholder value.

# Name of the BackendService resource to patch.
backend_service = 'my-backend-service'  # TODO: Update placeholder value.

backend_service_body = {
    # TODO: Add desired entries to the request body. Only assigned entries
    # will be changed.
}

request = service.backendServices().patch(project=project, backendService=backend_service, body=backend_service_body)
response = request.execute()

# TODO: Change code below to process the `response` dict:
pprint(response)
Duojie
  • 23
  • 4