Set up a classic Application Load Balancer with hybrid connectivity

This page illustrates how to deploy the classic Application Load Balancer to load balancetraffic to network endpoints that are on-premises or in other public clouds andare reachable by usinghybrid connectivity.

Note: For regional external Application Load Balancer instructions, seeSet up aregional external Application Load Balancer with hybrid connectivity.For global external Application Load Balancer instructions, seeSet up aglobal external Application Load Balancer with hybridconnectivity.

After you complete these tasks, you can optionally explore enabling additionalservices (such as Cloud CDN and Google Cloud Armor) and advanced traffic managementfeatures.

If you haven't already done so, review theHybrid connectivity NEGsoverview to understand thenetwork requirements to set up hybrid load balancing.

Setup overview

The example on this page sets up the following sample deployment:

External Application Load Balancer example for hybrid connectivity.
External Application Load Balancer example for hybrid connectivity (click to enlarge).

You must configure hybrid connectivity before you attempt to set up a hybridload balancing deployment. This document does not include the hybrid connectivitysetup.

Depending on your choice of hybrid connectivity product (eitherCloud VPN or Cloud Interconnect (Dedicated or Partner)), usethe relevant product documentation to configure this.

Permissions

To set up hybrid load balancing, you must have the following permissions:

  • On Google Cloud

    • Permissions to establish hybrid connectivity between Google Cloud andyour on-premises environment or other cloud environments. For the listof permissions needed, see the relevantNetwork Connectivity productdocumentation.
    • Permissions to create a hybrid connectivity NEG and the load balancer.TheCompute Load Balancer Adminrole(roles/compute.loadBalancerAdmin) contains the permissions required toperform the tasks described in this guide.
  • On your on-premises environment or other non-Google Cloud cloudenvironment

    • Permissions to configure network endpoints that allow services on youron-premises environment or other cloud environments to be reachable fromGoogle Cloud by using anIP:Port combination. For more information,contact your environment's network administrator.
    • Permissions to create firewall rules on your on-premises environment orother cloud environments to allow Google's health check probes to reach theendpoints.

Additionally, to complete the instructions on this page, you need to create ahybrid connectivity NEG, a load balancer, and zonal NEGs (and their endpoints)to serve as Google Cloud-based backends for the load balancer.

You should be either a projectOwneror Editor, or you should have thefollowingCompute Engine IAMroles.

TaskRequired role
Create networks, subnets, and load balancer componentsCompute Network Admin (roles/compute.networkAdmin)
Add and remove firewall rulesCompute Security Admin (roles/compute.securityAdmin)
Create instancesCompute Instance Admin (roles/compute.instanceAdmin)

Establish hybrid connectivity

Your Google Cloud and on-premises environment or other cloud environmentsmust be connected throughhybrid connectivity by usingeither Cloud Interconnect VLAN attachments or Cloud VPNtunnels with Cloud Router or Router appliance VMs. We recommend that youuse a high availability connection.

A Cloud Router enabled withglobal dynamicroutinglearns about the specific endpoint through Border Gateway Protocol (BGP) andprograms it into your Google Cloud VPC network. Regionaldynamic routing is not supported. Static routes are also not supported.

You can use either the same network or a different VPC networkwithin the same project to configure both hybrid networking(Cloud Interconnect or Cloud VPN or a Router appliance VM) and the load balancer. Notethe following:

  • If you use different VPC networks, the two networks must beconnected using either VPC Network Peering or they must beVPCspokeson the sameNetwork Connectivity Centerhub.

  • If you use the same VPC network, ensure that yourVPC network's subnet CIDR ranges don't conflict with yourremote CIDR ranges. When IP addresses overlap, subnet routes are prioritizedover remote connectivity.

For instructions, see the following documentation:

Important: Don't proceed with the instructions on this page until you set uphybrid connectivity between your environments.

Set up your environment that is outside Google Cloud

Perform the following steps to set up your on-premises environment or other cloudenvironment for hybrid load balancing:

  • Configure network endpoints to expose on-premises services toGoogle Cloud (IP:Port).
  • Configure firewall rules on your on-premises environment or other cloud environment.
  • Configure Cloud Router to advertise certain required routes to yourprivate environment.

Set up network endpoints

After you set up hybrid connectivity, you configure one or more networkendpoints within your on-premises environment or other cloud environments thatare reachable through Cloud Interconnect or Cloud VPN orRouter appliance by using anIP:port combination. ThisIP:portcombination is configured as one or more endpoints for the hybrid connectivityNEG that is created in Google Cloud later on in this process.

If there are multiple paths to the IP endpoint, routingfollows the behavior described in theCloud Routeroverview.

Set up firewall rules

The following firewall rules must be created on your on-premises environmentor other cloud environment:

  • Create an ingress allow firewall rule to allow traffic from Google's health-checking probes to your endpoints. The source IP address ranges to be allowed are35.191.0.0/16 and130.211.0.0/22. For more information, seeProbe IP ranges and firewall rules.

Advertise routes

Configure Cloud Router toadvertise the following custom IPranges to youron-premises environment or other cloud environment:

  • The ranges used by Google's health check probes:35.191.0.0/16 and130.211.0.0/22.

Set up the Google Cloud environment

For the following steps, make sure you use the same VPC network(calledNETWORK in this procedure) thatwas used to configure hybrid connectivity between the environments.

Create the subnet for the backends

This subnet is used to create the load balancer's zonal NEG backends, thefrontend, and the internal IP address.

Create this subnet in theNETWORKnetwork that was used to configure hybrid connectivity between theenvironments.

Console

  1. In the Google Cloud console, go to theVPC networks page.

    Go to VPC networks

  2. Go to the network that was used to configure hybridconnectivity between the environments.

  3. In theSubnets section:

    1. Set theSubnet creation mode toCustom.
    2. In theNew subnet section, enter the following information:
      • Name:LB_SUBNET_NAME
      • Region:REGION
      • IP address range:LB_SUBNET_RANGE
    3. ClickDone.
  4. ClickCreate.

gcloud

Create a subnet in theNETWORKnetwork that was used to configure hybrid connectivity between theenvironments.

gcloud compute networks subnets createLB_SUBNET_NAME \    --network=NETWORK \    --range=LB_SUBNET_RANGE \    --region=REGION

Create firewall rule

In this example, you create the following firewall rule:

  • fw-allow-health-check: An ingress rule, applicable to the Google Cloudinstances being load balanced, that allows traffic from the load balancer andGoogle Cloud health checking systems (130.211.0.0/22 and35.191.0.0/16). This example uses the target tagallow-health-check toidentify the backend VMs to which it should apply.

Console

  1. In the Google Cloud console, go to theFirewall policies page.

    Go to Firewall policies

  2. ClickCreate firewall rule:

    1. Enter aName offw-allow-health-check.
    2. In theNetwork section, selectNETWORK.
    3. UnderTargets, selectSpecified target tags.
    4. Populate theTarget tags field withallow-health-check.
    5. SetSource filter toIPv4 ranges.
    6. SetSource IPv4 ranges to130.211.0.0/22 and35.191.0.0/16.
    7. UnderProtocols and ports, selectSpecified protocols and ports.
    8. Select the checkbox next toTCP and type80 for the portnumbers.
  3. ClickCreate.

gcloud

  1. Create thefw-allow-health-check-and-proxy rule to allowthe load balancer and Google Cloud health checks to communicate withbackend instances on TCP port80.

    ReplaceNETWORK with the name ofthe VPC network used to configure hybrid connectivity.

    gcloud compute firewall-rules create fw-allow-health-check \    --network=NETWORK \    --action=allow \    --direction=ingress \    --target-tags=allow-health-check \    --source-ranges=130.211.0.0/22,35.191.0.0/16 \    --rules=tcp:80

Set up the zonal NEG

For Google Cloud-based backends, we recommend you configure multiple zonalNEGs in the same region where you configuredhybridconnectivity.

For this example, we set up a zonal NEG (withGCE_VM_IP_PORT type endpoints)in theREGION region. First create the VMs intheGCP_NEG_ZONE zone. Thencreate a zonal NEG in the sameGCP_NEG_ZONE andadd the VMs' network endpoints to the NEG.

Create VMs

Console

  1. Go to the VM instances page in the Google Cloud console.
    Go to VM instances

  2. ClickCreate instance.

  3. Set theName tovm-a1.

  4. For theRegion, chooseREGION.

  5. For theZone, chooseGCP_NEG_ZONE.

  6. In theBoot disk section, ensure thatDebian GNU/Linux 12 (bookworm) is selected for the boot diskoptions. ClickChoose to change the image if necessary.

  7. ClickAdvanced options and make the following changes:

    • ClickNetworking and add the followingNetwork tags:allow-health-check.
    • ClickEdit underNetwork interfaces and make the following changes then clickDone:
      • Network:NETWORK
      • Subnet:LB_SUBNET_NAME
      • IP stack type:IPv4 and IPv6 (dual-stack)
    • ClickManagement. In theStartup script field, copy and pastethe following script contents. The script contents are identical forall four VMs:

      #! /bin/bashapt-get updateapt-get install apache2 -ya2ensite default-ssla2enmod sslvm_hostname="$(curl -H "Metadata-Flavor:Google" \http://metadata.google.internal/computeMetadata/v1/instance/name)"echo "Page served from: $vm_hostname" | \tee /var/www/html/index.htmlsystemctl restart apache2
  8. ClickCreate.

  9. Repeat the following steps to create a second VM, using the followingname and zone combination:

    • Name:vm-a2, zone:GCP_NEG_ZONE

gcloud

Create the VMs by running the following command two times, using these combinations for the name of the VM and its zone. The script contents are identical for both VMs.

  • VM_NAME ofvm-a1 and anyGCP_NEG_ZONE zone ofyour choice
  • VM_NAME ofvm-a2 and the sameGCP_NEG_ZONE zone

    To supportIPv4 traffic, run the following command:

    gcloud compute instances createVM_NAME \    --zone=GCP_NEG_ZONE \    --image-family=debian-12 \    --image-project=debian-cloud \    --tags=allow-health-check \    --ipv6-network-tier=PREMIUM    --stack-type=IPV4_ONLY \    --subnet=LB_SUBNET_NAME \    --metadata=startup-script='#! /bin/bash      apt-get update      apt-get install apache2 -y      a2ensite default-ssl      a2enmod ssl      vm_hostname="$(curl -H "Metadata-Flavor:Google" \      http://metadata.google.internal/computeMetadata/v1/instance/name)"      echo "Page served from: $vm_hostname" | \      tee /var/www/html/index.html      systemctl restart apache2'

Create the zonal NEG

Console

To create a zonal network endpoint group:

  1. Go to the Network Endpoint Groups page in the Google Cloud console.
    Go to the Network Endpoint Groups page
  2. ClickCreate network endpoint group.
  3. Enter aName for the zonal NEG. Referred to asGCP_NEG_NAME in thisprocedure.
  4. Select theNetwork endpoint group type:Network endpoint group(Zonal).
  5. Select theNetwork:NETWORK
  6. Select theSubnet:LB_SUBNET_NAME
  7. Select theZone:GCP_NEG_ZONE
  8. Enter theDefault port:80.
  9. ClickCreate.

Add endpoints to the zonal NEG:

  1. Go to the Network Endpoint Groups page in the Google Cloud console.
    Go to the Network endpoint groups
  2. Click theName of the network endpoint group created in the previousstep (GCP_NEG_NAME). Yousee theNetwork endpoint group details page.
  3. In theNetwork endpoints in this group section, clickAdd networkendpoint. You see theAdd network endpoint page.
  4. Select aVM instance to add its internal IP addresses as networkendpoints. In theNetwork interface section, the name, zone,and subnet of the VM is displayed.
  5. In theIPv4 address field, enter the IPv4 address of the new networkendpoint.
  6. Select thePort type.
    1. If you selectDefault, the endpoint uses the default port80for all endpoints in the network endpoint group. This is sufficientfor our example because the Apache server is serving requests atport80.
    2. If you selectCustom, enter thePort number for the endpointto use.
  7. To add more endpoints, clickAdd network endpoint and repeat theprevious steps.
  8. After you add all the endpoints, clickCreate.

gcloud

  1. Create a zonal NEG (withGCE_VM_IP_PORT endpoints)using thegcloud compute network-endpoint-groupscreatecommand:

    gcloud compute network-endpoint-groups createGCP_NEG_NAME \    --network-endpoint-type=GCE_VM_IP_PORT \    --zone=GCP_NEG_ZONE \    --network=NETWORK \    --subnet=LB_SUBNET_NAME

    You can either specify a--default-port while creating the NEG,orspecify a port number for eachendpointas shown in the next step.

  2. Add single-stack endpoints toGCP_NEG_NAME.

    gcloud compute network-endpoint-groups updateGCP_NEG_NAME \    --zone=GCP_NEG_ZONE \    --add-endpoint='instance=vm-a1,port=80' \    --add-endpoint='instance=vm-a2,port=80'

Set up the hybrid connectivity NEG

When creating the NEG, use aZONE that minimizes the geographicdistance between Google Cloud and your on-premises or other cloudenvironment. For example, if you are hosting a service in an on-premisesenvironment in Frankfurt, Germany, you can specify theeurope-west3-aGoogle Cloud zone when you create the NEG.

Moreover, if you're using Cloud Interconnect, theZONE usedto create the NEG should be in the same region where the hybrid connectivityCloud Interconnect VLAN attachment was configured.

For the available regions and zones, see theCompute Enginedocumentation: Available regions andzones.

Console

To create a hybrid connectivity network endpoint group:

  1. Go to the Network Endpoint Groups page in the Google Cloud console.
    Go to Network endpoint groups
  2. ClickCreate network endpoint group.
  3. Enter aName for the hybrid NEG. Referred to asON_PREM_NEG_NAME in thisprocedure.
  4. Select theNetwork endpoint group type:Hybrid connectivity networkendpoint group (Zonal).
  5. Select theNetwork:NETWORK
  6. Select theSubnet:LB_SUBNET_NAME
  7. Select theZone:ON_PREM_NEG_ZONE
  8. Enter theDefault port.
  9. ClickCreate

Add endpoints to the hybrid connectivity NEG:

  1. Go to the Network Endpoint Groups page in the Google Cloud console.
    Go to the Network Endpoint Groups page
  2. Click theName of the network endpoint group created in the previousstep (ON_PREM_NEG_NAME). Yousee theNetwork endpoint group detail page.
  3. In theNetwork endpoints in this group section, clickAdd networkendpoint. You see theAdd network endpoint page.
  4. Enter theIP address of the new network endpoint.
  5. Select thePort type.
    1. If you selectDefault, the endpoint uses the default portfor all endpoints in the network endpoint group.
    2. If you selectCustom, you can enter a differentPort numberfor the endpoint to use.
  6. To add more endpoints, clickAdd network endpoint and repeat theprevious steps.
  7. After you add all the non-Google Cloud endpoints,clickCreate.

gcloud

  1. Create a hybrid connectivity NEG using thegcloud compute network-endpoint-groupscreatecommand.

    gcloud compute network-endpoint-groups createON_PREM_NEG_NAME \    --network-endpoint-type=NON_GCP_PRIVATE_IP_PORT \    --zone=ON_PREM_NEG_ZONE \    --network=NETWORK
  2. Add the endpoint toon-prem-neg:

    gcloud compute network-endpoint-groups updateON_PREM_NEG_NAME \    --zone=ON_PREM_NEG_ZONE \    --add-endpoint="ip=ON_PREM_IP_ADDRESS_1,port=PORT_1" \    --add-endpoint="ip=ON_PREM_IP_ADDRESS_2,port=PORT_2"

You can use this command to add the network endpoints youpreviouslyconfigured on-premises or in your cloud environment.Repeat--add-endpoint as many times as needed.

You can repeat these steps to create multiple hybrid NEGs if needed.

Configure the load balancer

Console

Note: You cannot use the Google Cloud console to create a load balancerthat has mixed zonal and hybrid connectivity NEGs backends in a singlebackend service. Use eithergcloud or the REST API instead.

gcloud

  1. Create a global static external IP address to which external clients send traffic.
      gcloud compute addresses createLB_IP_ADDRESS_NAME \      --global
  2. Create ahealth check for the backends.
      gcloud compute health-checks create httpHTTP_HEALTH_CHECK_NAME \      --use-serving-port
  3. Create a backend service. You add both the zonal NEG and the hybrid connectivity NEG as backends to this backend service.
  4.   gcloud compute backend-services createBACKEND_SERVICE \      --health-checks=HTTP_HEALTH_CHECK_NAME \      --global
  5. Add the zonal NEG as a backend to the backend service:
      gcloud compute backend-services add-backendBACKEND_SERVICE \      --global \      --balancing-mode=RATE \      --max-rate-per-endpoint=MAX_REQUEST_RATE_PER_ENDPOINT \      --network-endpoint-group=GCP_NEG_NAME \      --network-endpoint-group-zone=GCP_NEG_ZONE
    For details about configuring the balancing mode, see the gcloud CLI documentation for the--max-rate-per-endpoint parameter.
  6. Add the hybrid NEG as a backend to the backend service:
      gcloud compute backend-services add-backendBACKEND_SERVICE \      --global \      --balancing-mode=RATE \      --max-rate-per-endpoint=MAX_REQUEST_RATE_PER_ENDPOINT \      --network-endpoint-group=ON_PREM_NEG_NAME \      --network-endpoint-group-zone=ON_PREM_NEG_ZONE
  7. Create a URL map to route incoming requests to the backend service.
      gcloud compute url-maps createURL_MAP_NAME \      --default-serviceBACKEND_SERVICE
  8. Perform this step only if you want to create an HTTPS loadbalancer. This is not required for HTTP load balancers.
    To create an HTTPS load balancer, you must have anSSL certificate resource to use in the HTTPS target proxy. You can create an SSL certificate resource using either a Google-managed SSL certificate or a self-managed SSL certificate. Using Google-managed certificates is recommended because Google Cloud obtains, manages, and renews these certificates automatically.

    To create a Google-managed certificate, you must have a domain. If you don't have a domain, you can use a self-signed SSL certificate for testing.

    To create a Google-managed SSL certificate resource:
    gcloud compute ssl-certificates createSSL_CERTIFICATE_NAME \    --domainsDOMAIN
    To create a self-managed SSL certificate resource:
    gcloud compute ssl-certificates createSSL_CERTIFICATE_NAME \    --certificateCRT_FILE_PATH \    --private-keyKEY_FILE_PATH
  9. Create a target HTTP(S) proxy to route requests to your URL map.

    For an HTTP load balancer, create an HTTP target proxy:
    gcloud compute target-http-proxies createTARGET_HTTP_PROXY_NAME \    --url-map=URL_MAP_NAME
    For an HTTPS load balancer, create an HTTPS target proxy.The proxy is the portion of the loadbalancer that holds the SSL certificate for HTTPS Load Balancing, so youalso load your certificate in this step.
    gcloud compute target-https-proxies createTARGET_HTTPS_PROXY_NAME \    --ssl-certificates=SSL_CERTIFICATE_NAME \    --url-map=URL_MAP_NAME
  10. Create a forwarding rule to route incoming requests to the proxy.

    For an HTTP load balancer:
    gcloud compute forwarding-rules createHTTP_FORWARDING_RULE_NAME \    --address=LB_IP_ADDRESS_NAME \    --target-http-proxy=TARGET_HTTP_PROXY_NAME \    --global \    --ports=80
    For an HTTPS load balancer:
    gcloud compute forwarding-rules createHTTPS_FORWARDING_RULE_NAME \    --address=LB_IP_ADDRESS_NAME \    --target-https-proxy=TARGET_HTTPS_PROXY_NAME \    --global \    --ports=443

Connect your domain to your load balancer

After the load balancer is created, note the IP address that is associated withthe load balancer—for example,30.90.80.100. To point your domain to yourload balancer, create anA record by using your domain registration service. Ifyou added multiple domains to your SSL certificate, you must add anA recordfor each one, all pointing to the load balancer's IP address. For example, tocreateA records forwww.example.com andexample.com, use the following:

NAME                  TYPE     DATAwww                   A        30.90.80.100@                     A        30.90.80.100

If you use Cloud DNS as your DNS provider, seeAdd, modify, and delete records.

Testing the load balancer

Note: It might take a few minutes for the load balancer configuration topropagate globally after you first deploy it.

Now that you have configured your load balancer, you can start sendingtraffic to the load balancer's IP address.

  1. Go to the Load balancing page in the Google Cloud console.
    Go to the Load balancing page

  2. Click on the load balancer you just created.

  3. Note theIP Address of the load balancer.

  4. Send traffic to the load balancer.

    • If you created anHTTP load balancer, you can test your load balancerusing a web browser by going tohttp://IP_ADDRESS.ReplaceIP_ADDRESS with the load balancer's IPaddress. You should be directed to the service you have exposed through theendpoint.

    • If you created anHTTPS load balancer, you can test your load balancerby usingcurl as follows. ReplaceIP_ADDRESS withtheload balancer's IP address. Youshould be directed to the service you have exposed through the endpoint.

      curl -k https://IP_ADDRESS

      If that does not work and you are using a Google-managed certificate,confirm that your certificate resource's status is ACTIVE. For moreinformation, seeGoogle-managed SSL certificate resourcestatus.Then test the domain pointing to the load balancer's IP address. Forexample:

      curl -s https://DOMAIN_NAME

      ReplaceDOMAIN_NAME with your application domain name, forexample,test.example.com.

  5. Testing the non-Google Cloud endpoints depends onthe service you have exposed through the hybrid NEG endpoint.

What's next

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

Last updated 2025-10-24 UTC.