A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://cloud.google.com/load-balancing/docs/network/configure-weighted-netlb below:

Configure weighted load balancing | Load Balancing

Configure weighted load balancing

Stay organized with collections Save and categorize content based on your preferences.

This guide provides instructions for creating a weighted external passthrough Network Load Balancer deployment for each virtual machine (VM) instance using a regional backend service.

In this tutorial, you create an instance group with three VM instances and assign weights for each instance. You create an HTTP health check to report backend instance weights. Weighted load balancing is enabled on the backend service with locality load balancer policy as WEIGHTED_MAGLEV.

Before you begin Note: You cannot use the Google Cloud console to configure the locality load balancer policy and assign weights to VM instances. Use the Google Cloud CLI instead. Create VPC network, subnets, and firewall rules

Create a VPC network, subnet, and ingress allow firewall rules to allow connections to the backend VMs of your load balancer.

  1. Create a VPC network and subnet.

    a. To create the VPC network, run the gcloud compute networks create command:

    gcloud compute networks create NETWORK_NAME --subnet-mode custom
    

    b. In this example, the subnet's primary IPv4 address range is 10.10.0.0/24. To create the subnet, run the gcloud compute networks subnets create command:

    gcloud compute networks subnets create SUBNET_NAME \
      --network=NETWORK_NAME \
      --range=10.10.0.0/24 \
      --region=us-central1
    

    Replace the following:

  2. Create an ingress allow firewall rule to allow packets sent to destination TCP ports 80 and 443 to be delivered to the backend VMs. In this example, firewall rule allows connections from any source IP address. The firewall rule applies to VMs with the network tag network-lb-tag.

    To create the firewall rule, run the gcloud compute firewall-rules create command:

    gcloud compute firewall-rules create FIREWALL_RULE_NAME \
       --direction=INGRESS \
       --priority=1000 \
       --network=NETWORK_NAME \
       --action=ALLOW \
       --rules=tcp:80,tcp:443 \
       --source-ranges=0.0.0.0/0 \
       --target-tags=network-lb-tag
    

    Replace FIREWALL_RULE_NAME with the name of the firewall rule to create.

Create VM instances and assign weights

Create three VM instances and assign weights:

  1. Configure three backend VM instances to return the weights in the X-Load-Balancing-Endpoint-Weight header with HTTP responses. For this tutorial, you configure one backend instance to report a weight of zero, a second backend instance to report a weight of 100, and a third backend instance to report a weight of 900.

    To create the instances, run the gcloud compute instances create command:

    gcloud compute instances create instance-0 \
      --zone=us-central1-a \
      --tags=network-lb-tag \
      --image-family=debian-12 \
      --image-project=debian-cloud \
      --subnet=SUBNET_NAME \
      --metadata=load-balancing-weight=0,startup-script='#! /bin/bash
      apt-get update
      apt-get install apache2 -y
      ln -sr /etc/apache2/mods-available/headers.load /etc/apache2/mods-enabled/headers.load
      vm_hostname="$(curl -H "Metadata-Flavor:Google" \
      http://169.254.169.254/computeMetadata/v1/instance/name)"
      echo "Page served from: $vm_hostname" | \
      tee /var/www/html/index.html
      lb_weight="$(curl -H "Metadata-Flavor:Google" \
      http://169.254.169.254/computeMetadata/v1/instance/attributes/load-balancing-weight)"
      echo "Header set X-Load-Balancing-Endpoint-Weight \"$lb_weight\"" | \
      tee /etc/apache2/conf-enabled/headers.conf
      systemctl restart apache2'
    
    gcloud compute instances create instance-100 \
      --zone=us-central1-a \
      --tags=network-lb-tag \
      --image-family=debian-12 \
      --image-project=debian-cloud \
      --subnet=SUBNET_NAME \
      --metadata=load-balancing-weight=100,startup-script='#! /bin/bash
      apt-get update
      apt-get install apache2 -y
      ln -sr /etc/apache2/mods-available/headers.load /etc/apache2/mods-enabled/headers.load
      vm_hostname="$(curl -H "Metadata-Flavor:Google" \
      http://169.254.169.254/computeMetadata/v1/instance/name)"
      echo "Page served from: $vm_hostname" | \
      tee /var/www/html/index.html
      lb_weight="$(curl -H "Metadata-Flavor:Google" \
      http://169.254.169.254/computeMetadata/v1/instance/attributes/load-balancing-weight)"
      echo "Header set X-Load-Balancing-Endpoint-Weight \"$lb_weight\"" | \
      tee /etc/apache2/conf-enabled/headers.conf
      systemctl restart apache2'
    
    gcloud compute instances create instance-900 \
      --zone=us-central1-a \
      --tags=network-lb-tag \
      --image-family=debian-12 \
      --image-project=debian-cloud \
      --subnet=SUBNET_NAME \
      --metadata=load-balancing-weight=900,startup-script='#! /bin/bash
        apt-get update
        apt-get install apache2 -y
        ln -sr /etc/apache2/mods-available/headers.load /etc/apache2/mods-enabled/headers.load
        vm_hostname="$(curl -H "Metadata-Flavor:Google" \
        http://169.254.169.254/computeMetadata/v1/instance/name)"
        echo "Page served from: $vm_hostname" | \
        tee /var/www/html/index.html
        lb_weight="$(curl -H "Metadata-Flavor:Google" \
        http://169.254.169.254/computeMetadata/v1/instance/attributes/load-balancing-weight)"
        echo "Header set X-Load-Balancing-Endpoint-Weight \"$lb_weight\"" | \
        tee /etc/apache2/conf-enabled/headers.conf
        systemctl restart apache2'
    
Create an instance group

In this tutorial, you provide instructions to create an unmanaged instance group containing all three VM instances(instance-0, instance-100, and instance-900).

Create an HTTP health check

In this tutorial, you provide instructions to create an HTTP health check to read the HTTP response containing the backend VM's weight."

Create a backend service

The following example provides instructions to create a regional external backend service configured to use weighted load balancing.

  1. Create a backend service with the HTTP health check and set the locality load balancer policy to WEIGHTED_MAGLEV.

  2. Add the instance group to the backend service.

  3. Reserve a regional external IP address for the load balancer.

  4. Create a forwarding rule using the reserved regional external IP address IP_ADDRESS. Connect the forwarding rule to the backend service.

Verify backend weights using backend service API

Verify that the backend weights are properly reported to the HTTP health check.

The output is the following:

backend: https://www.googleapis.com/compute/projects/project-name/{project}/zones/us-central1-a/instanceGroups/{instance-group-name}
status:
  healthStatus:
  - forwardingRule: https://www.googleapis.com/compute/projects/{project}/regions/us-central1/forwardingRules/{firewall-rule-name}
    forwardingRuleIp: 34.135.46.66
    healthState: HEALTHY
    instance: https://www.googleapis.com/compute/projects/{project}/zones/us-central1-a/instances/instance-0
    ipAddress: 10.10.0.5
    port: 80
    weight: '0'
  - forwardingRule: https://www.googleapis.com/compute/projects/{project}/regions/us-central1/forwardingRules/{firewall-rule-name}
    forwardingRuleIp: 34.135.46.66
    healthState: HEALTHY
    instance: https://www.googleapis.com/compute/projects/{project}/zones/us-central1-a/instances/instance-100
    ipAddress: 10.10.0.6
    port: 80
    weight: '100'
  - forwardingRule: https://www.googleapis.com/compute/projects/{project}/regions/us-central1/forwardingRules/{firewall-rule-name}
    forwardingRuleIp: 34.135.46.66
    healthState: HEALTHY
    instance: https://www.googleapis.com/compute/projects/{project}/zones/us-central1-a/instances/instance-900
    ipAddress: 10.10.0.7
    port: 80
    weight: '900'
  kind: compute#backendServiceGroupHealth

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-07 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[],[]]


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