The application includes the following Compute Engine components:
Create a network for the instance groups.
In the Google Cloud console, go to the VPC networks page.
Click Create VPC Network.
Set the Name to fortressnet
.
Set Subnet creation mode to Automatic.
Click Create at the bottom of the page.
Create a firewall rule for the network. This rule will allow all HTTP requests sent to your instances.
In the Google Cloud console, go to the Firewall rules page.
Click Create Firewall Rule.
Set the Name to fortressnet-allow-http
.
For Network select fortressnet
.
For Targets select All instances in the network
.
Set Source IPv4 ranges to 0.0.0.0/0
.
For Protocols and ports, choose Specified protocols and ports and then select the tcp checkbox and enter 80
.
Click Create.
Create an instance template. Include a startup script that starts up a simple Apache web server on each instance.
In the Google Cloud console, go to the Instance templates page.
Click Create instance template.
Set the Name to fort-template
.
For Machine configuration, select e2-micro
(2 vCPU, 1 GB memory).
In the Advanced options section, expand Networking, and then do the following:
fortressnet
.In the Management section, for Automation enter the following Startup script:
apt update && apt -y install apache2
Click Create.
Create multiple regional managed instance groups using the instance template. Configure autoscaling for each instance group.
In the Google Cloud console, go to the Instance groups page.
Click Create instance group to create a new managed instance group.
Select New managed instance group (stateless).
Set the Name to us-central1-pool
.
For Instance template, select fort-template
.
For Location, select Multiple zones.
For Region, select us-central1
. For Zones, leave the predefined values selected.
For Autoscaling mode, select On: add and remove instances to the group.
Set Minimum number of instances to 1
.
Set Maximum number of instances to 5
.
For Autoscaling signals, edit the default selection (CPU utilization) and set the Signal type to HTTP load balancing utilization.
Set Target HTTP load balancing utilization to 80
.
Click Done.
Click Create. A dialog displays the message that you must also assign the instance group to a backend service of an HTTP load balancer.
In the confirmation dialog, click Confirm. You can configure the load balancer after you create all the instance groups.
Repeat these steps to create two more instance groups with the following changes:
europe-west1-pool
and Region as europe-west1
.asia-east1-pool
and Region as asia-east1
.(Optional) Verify the instances are healthy and serving HTTP traffic. Test the external IP address of one or more instances. You might need to wait a minute for the instances to finish the startup process.
In the Google Cloud console, go to the VM instances page.
Verify that each running instance has a green checkmark in the Status column next to the name of your instance group.
Copy an instance's External IP and paste it into a web browser.
You should see the 'Apache2 Debian Default Page' web page.
If it doesn't seem to work, try waiting a few moments.
Create a network for the instance groups.
gcloud compute networks create fortressnet --subnet-mode auto
Create a firewall rule for the network. This rule will allow all HTTP requests sent to your instances.
gcloud compute firewall-rules create fortressnet-allow-http \ --network fortressnet \ --allow tcp:80
Create an instance template. Include a startup script that starts up a simple Apache web server on each instance.
gcloud compute instance-templates create fort-template \ --machine-type e2-micro \ --network fortressnet \ --metadata startup-script='apt update && apt -y install apache2'
Create multiple regional managed instance groups using the instance template. Configure autoscaling for each instance group.
gcloud compute instance-groups managed create us-central1-pool \ --region us-central1 \ --template fort-template \ --size 1 gcloud compute instance-groups managed set-autoscaling us-central1-pool \ --region us-central1 \ --min-num-replicas 1 \ --max-num-replicas 5 \ --scale-based-on-load-balancing \ --target-load-balancing-utilization .8
gcloud compute instance-groups managed create europe-west1-pool \ --region europe-west1 \ --template fort-template \ --size 1 gcloud compute instance-groups managed set-autoscaling europe-west1-pool \ --region europe-west1 \ --min-num-replicas 1 \ --max-num-replicas 5 \ --scale-based-on-load-balancing \ --target-load-balancing-utilization .8
gcloud compute instance-groups managed create asia-east1-pool \ --region asia-east1 \ --template fort-template \ --size 1 gcloud compute instance-groups managed set-autoscaling asia-east1-pool \ --region asia-east1 \ --min-num-replicas 1 \ --max-num-replicas 5 \ --scale-based-on-load-balancing \ --target-load-balancing-utilization .8Note: Autoscaling of instance groups can be based on different criteria. Because your web service employs a Load Balancer, your autoscalers should be configured to scale based on load balancing usage. For more information, see Scaling based on load balancing serving capacity.
(Optional) Verify the instances are healthy and serving HTTP traffic. Test the external IP address of one or more instances. You might need to wait a minute for the instances to finish the startup process.
List your instances.
gcloud compute instances list
Verify under the STATUS
column that the instances are RUNNING
.
Check an instance by querying it's IP address under the EXTERNAL_IP
column.
curl http://EXTERNAL_IP | head
You should see some HTML text, including the line <title>Apache2 Debian Default Page: It works</title>
.
If it doesn't seem to work, try waiting a few moments.
The load balancer will distribute client requests among your multiple backends.
Console Select the load balancer typeIn the Google Cloud console, go to the Load balancing page.
fortressnet-balancer
.fortressnet-backend-service
.asia-east1-pool
.100
RPS per instance.europe-west1-pool
.100
RPS per instance.us-central1-pool
.100
RPS per instance.http-basic-check
.HTTP
.80
.fortressnet-http-rule
.fortressnet-ip
.fortressnet-http-ipv6-rule
.fortressnet-ipv6
.Create a basic health check. This will check whether a load balancer backend is responding to HTTP requests.
gcloud compute health-checks create http http-basic-check
Create a global backend service. This backend service will receive HTTP traffic from the load balancer.
gcloud compute backend-services create fortressnet-backend-service \ --protocol HTTP \ --health-checks http-basic-check \ --global
Add the instance groups as regional backends of the backend service. This configuration will distribute traffic among the backends based on a maximum number of requests per second (RPS) per instance.
gcloud compute backend-services add-backend fortressnet-backend-service \ --balancing-mode RATE \ --max-rate-per-instance 100 \ --instance-group us-central1-pool \ --instance-group-region us-central1 \ --global gcloud compute backend-services add-backend fortressnet-backend-service \ --balancing-mode RATE \ --max-rate-per-instance 100 \ --instance-group europe-west1-pool \ --instance-group-region europe-west1 \ --global gcloud compute backend-services add-backend fortressnet-backend-service \ --balancing-mode RATE \ --max-rate-per-instance 100 \ --instance-group asia-east1-pool \ --instance-group-region asia-east1 \ --global
Define a URL map. URL maps route different URLs to different backend services. Since we only have one backend service, we'll simply set that backend service as the default service for all URLs.
gcloud compute url-maps create fortressnet-balancer \ --default-service fortressnet-backend-service
Create an HTTP proxy route. HTTP proxy routes accept HTTP requests and route them according to your URL map. In this case, it will send all requests to your single backend service.
gcloud compute target-http-proxies create fortressnet-http-proxy \ --url-map fortressnet-balancer
Create two global static external IP addresses: one for IPv4 and one for IPv6. These will be the global external IP addresses of the load balancer.
gcloud compute addresses create fortressnet-ip \ --ip-version IPV4 \ --network-tier=PREMIUM \ --global gcloud compute addresses create fortressnet-ipv6 \ --ip-version IPV6 \ --network-tier=PREMIUM \ --global
Lookup the external IP addresses of the load balancer.
gcloud compute addresses list
Create global forwarding rules for the external IP addresses. This will forward both IPv4 and IPv6 HTTP requests to your HTTP proxy.
gcloud compute forwarding-rules create fortressnet-http-rule \ --load-balancing-scheme=EXTERNAL \ --network-tier=PREMIUM \ --global \ --target-http-proxy fortressnet-http-proxy \ --ports 80 \ --address LOAD_BALANCER_IP_ADDRESS
gcloud compute forwarding-rules create fortressnet-http-ipv6-rule \ --load-balancing-scheme=EXTERNAL \ --network-tier=PREMIUM \ --global \ --target-http-proxy fortressnet-http-proxy \ --ports 80 \ --address LOAD_BALANCER_IPV6_ADDRESS
(Optional) Verify the load balancer is working. You may need to wait a minute or three.
ConsoleIn the Google Cloud console, go to the Load balancing page.
Wait for fortressnet-balancer
to have a green check mark under the Backends column.
Click on fortressnet-balancer
.
Under Frontend copy the IPv4 address under the IP:Port column. (IPv4 addresses are of the form www.xxx.yyy.zzz
. You don't need the trailing port number :nn
.) If the Frontend section is missing, try waiting a few moments and then reloading the web page.
Enter the IP address in a web browser.
You should see the 'Apache2 Debian Default Page' web page.
If you get an 'Error 404 (Not Found)' web page instead, try waiting a few more minutes.
gcloudLookup the external IP addresses of the load balancer.
gcloud compute addresses list
Query the IPv4 address. (IPv4 addresses are of the form www.xxx.yyy.zzz
.)
curl http://LOAD_BALANCER_IP_ADDRESS | head
You should see some HTML text, including the line <title>Apache2 Debian Default Page: It works</title>
.
If you see <title>Error 404 (Not Found)!!1</title>
instead, try waiting a few more minutes.
Best Practice: Create a secure firewall to allow only internal traffic from the load balancer and the health check. Then delete the original firewall that allowed any HTTP request. This prevents individual instances from being accessible by outside clients.
ConsoleCreate a new firewall only allowing traffic from the load balancer and the health check.
In the Google Cloud console, go to the Firewall rules page.
Click Create Firewall Rule.
Set the Name to fortressnet-allow-load-balancer
.
For Network select fortressnet
.
For Targets select All instances in the network
.
For Source IP ranges type 130.211.0.0/22
and press the Enter key, then type 35.191.0.0/16
and press Enter again.
Under Protocols and ports select tcp and enter 80
.
Click Create.
Delete the old allow-everything firewall.
fortressnet-allow-http
.Create a new firewall only allowing traffic from the load balancer and the health check.
gcloud compute firewall-rules create fortressnet-allow-load-balancer \ --network fortressnet \ --source-ranges 130.211.0.0/22,35.191.0.0/16 \ --allow tcp:80
Delete the old allow-everything firewall.
gcloud compute firewall-rules delete fortressnet-allow-http -q
130.211.0.0/22
and 35.191.0.0/16
are noteworthy source IPs. 130.211.0.0/22
is the source IP for any request redirected by a Compute Engine Load Balancer. 35.191.0.0/16
is the source IP for any request sent by a Compute Engine Health Check. For more information, see the documentation for Load balancing firewall rules. (Optional) Verify that autoscaling and load balancing works Generate some test traffic
Suppose it is morning in Europe and your web service suddenly goes viral on the internet. Generate a high number of client requests all at once from Europe.
ConsoleCreate an instance installed with the Siege load testing tool.
In the Google Cloud console, go to the Create an instance page.
Set the Name to europe-loadtest
.
For Region select europe-west1
.
For advanced settings, expand the Advanced options section, and do the following:
apt -y install siege
To create the VM, click Create.
Get the IPv4 address of the load balancer.
In the Google Cloud console, go to the Load balancing page.
Click fortressnet-balancer
.
Under Frontend copy the IPv4 address under the IP:Port column. (IPv4 addresses are of the form www.xxx.yyy.zzz
.)
SSH into the load testing instance.
In the Google Cloud console, go to the VM instances page.
Wait for the europe-loadtest
instance to have a green checkmark under the Name column.
Click SSH on europe-loadtest
under the Connect column.
Start siege. Target the IPv4 address of the load balancer.
siege -c150 http://LOAD_BALANCER_IP_ADDRESS
Create an instance installed with the Siege load testing tool.
gcloud compute instances create europe-loadtest \ --network default \ --zone europe-west1-c \ --metadata startup-script='apt -y install siege'
Get the IPv4 address of the load balancer.
gcloud compute addresses list
Open a new shell session where the gcloud
command is available.
In your new shell session, SSH into the load testing instance.
gcloud compute ssh --zone europe-west1-c europe-loadtest
Start siege. Target the IPv4 address of the load balancer.
siege -c150 http://LOAD_BALANCER_IP_ADDRESS
After running the siege
command you should see output declaring The server is now under siege...
[alert] Zip encoding disabled; siege requires zlib support to enable it ** SIEGE 4.0.2 ** Preparing 150 concurrent users for battle. The server is now under siege...Monitor load balancing and autoscaling
In the Google Cloud console, go to the Load balancing page.
Click the load balancer named fortressnet-balancer
.
Click the Monitoring tab.
In the Backend drop-down, select fortressnet-backend-service
.
It may take up to ten minutes to display enough data. Soon you should see a display similar to the following:
What's happening here:
The load test starts sending a large amount of traffic all at once. At first, the load balancer distributes requests equally among the three backends. The number of requests quickly exceeds your autoscaling limits, and may even cause your servers to return Backend 5xx errors
which will show up on the monitoring display. The autoscaler starts to spin up additional instances as needed.
Autoscaling catches up with capacity needs. To minimize request latency, Compute Engine load balancers try to route requests to the backend that is closest to the client. In this case, since the load test traffic originates from Europe, the load balancer prefers to route more requests to the Europe backend. As a result, autoscaling may spin up more instances in the Europe backend to handle a higher fraction of requests.
Suppose your web service also catches on in Asia with the afternoon internet crowd. Generate a high number of requests from Asia.
ConsoleTo create another instance installed with the Siege load testing tool, do the following:
In the Google Cloud console, go to the VM instances page.
Click Create instance.
Set the Name to asia-loadtest
.
For Region select asia-east1
.
Expand the Advanced options section.
Expand the Management section.
In the Automation section, enter the following startup script:
apt -y install siege
Click Create.
To get the IP address of the load balancer, do the following:
In the Google Cloud console, go to the Load balancing page.
Click fortressnet-balancer
.
Under Frontend copy the IPv4 address under the IP:Port column. (IPv4 addresses are of the form www.xxx.yyy.zzz
.)
SSH into the load testing instance.
asia-loadtest
instance to have a green checkmark under the Name column.asia-loadtest
under the Connect column.Start siege. Target the IPv4 address of the load balancer.
siege -c150 http://LOAD_BALANCER_IP_ADDRESS
In your original shell session, create another instance installed with the Siege load testing tool.
gcloud compute instances create asia-loadtest \ --network default \ --zone asia-east1-c \ --metadata startup-script='apt -y install siege'
Get the IPv4 address of the load balancer.
gcloud compute addresses list
Open a new shell session where the gcloud
command is available.
In your new shell session, SSH into the load testing instance.
gcloud compute ssh --zone asia-east1-c asia-loadtest
Start siege. Target the IPv4 address of the load balancer.
siege -c150 http://LOAD_BALANCER_IP_ADDRESS
Again, you should see output declaring The server is now under siege...
[alert] Zip encoding disabled; siege requires zlib support to enable it ** SIEGE 4.0.2 ** Preparing 150 concurrent users for battle. The server is now under siege...Monitor load balancing and autoscaling
Go back to the load balancing monitoring display from last time. It may take up to ten minutes to display enough new data. Soon you should see a display similar to the following:
What's happening here:
Again, the load test sends another large number of requests all at once. At first the load balancer distributes requests equally among the existing three backends. As the number of requests exceeds your autoscaling limits, the autoscaler starts to spin up additional instances as needed.
Autoscaling catches up with the new capacity needs. The load balancer still prefers to route requests to the nearest available backends. As a result, eventually the Asia backend receives requests mostly from Asia, the Europe backend receives requests mostly from Europe, and the US backend receives everything else.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4