Creating Cross-Region Load Balancing

This guide demonstrates how to create an HTTP(S) load balancer that forwards traffic to instances in two different regions. If you need to forward user requests based on the URL host or path, see the content-based example.

Overview

For this scenario, you will create four Compute Engine instances, two each in two different regions. You will then configure the rest of the system so that incoming connections are sent to the appropriate instance.

The resources you will be creating connect together as shown here:

Cross-region load balancing
Cross-region load balancing diagram

Before you begin

These instructions assume you are using an auto subnet network or a legacy network. If you are using a custom subnet network, then some of the steps below, such as creating an instance, additionally require you to specify the subnetwork range.

If you prefer to work from the command line, install the gcloud command-line tool, as described on the Prerequisites page.

If you haven't run the gcloud command-line tool previously, first run gcloud init to authenticate.

Configuring instances

  1. In this example, create two virtual machine instances in each of two different regions, configure them for testing, and give them all the same tag. This tag will be used by a firewall rule to allow incoming traffic to reach your instances.

    The startup script installs apache and creates a unique home page for each instance.

    Console


    1. Go to the VM instances page in the Google Cloud Platform Console.
      Go to the VM instances page
    2. Click Create instance.
    3. Set Name to www-1 if you're doing HTTP, wwws-1 if you're doing HTTPS.
    4. Set the Zone to us-central1-b.
    5. Click Management, disk, networking, SSH keys to to reveal advanced settings.
    6. Under Management, populate the Tags field with http-tag for HTTP traffic, https-tag for HTTPS traffic, or both tags if you're doing both kinds of traffic
    7. Insert the following script into the Startup script field:
      sudo apt-get update
      sudo apt-get install apache2 -y
      sudo a2ensite default-ssl
      sudo a2enmod ssl
      sudo service apache2 restart
      echo '<!doctype html><html><body><h1>server 1</h1></body></html>' | sudo tee /var/www/html/index.html
    8. Leave the default values for rest of the fields.
    9. Click Create.
    10. Create www-2 or wwws-2 with the same settings, except with the following text inserted into the Startup script field:
      sudo apt-get update
      sudo apt-get install apache2 -y
      sudo a2ensite default-ssl
      sudo a2enmod ssl
      sudo service apache2 restart
      echo '<!doctype html><html><body><h1>server 2</h1></body></html>' | sudo tee /var/www/html/index.html
    11. Create www-3 or wwws-3 with the same settings, except with Zone set to europe-west1-b and the following text inserted into the Startup script field:
      sudo apt-get update
      sudo apt-get install apache2 -y
      sudo a2ensite default-ssl
      sudo a2enmod ssl
      sudo service apache2 restart
      echo '<!doctype html><html><body><h1>server 3</h1></body></html>' | sudo tee /var/www/html/index.html
    12. Create www-4 or wwws-4 with the same settings, except with Zone set to europe-west1-b and the following text inserted into the Startup script field:
      sudo apt-get update
      sudo apt-get install apache2 -y
      sudo a2ensite default-ssl
      sudo a2enmod ssl
      sudo service apache2 restart
      echo '<!doctype html><html><body><h1>server 4</h1></body></html>' | sudo tee /var/www/html/index.html

    gcloud: HTTP


    gcloud compute instances create www-1 \
        --image-family debian-8 \
        --image-project debian-cloud \
        --zone us-central1-b \
        --tags http-tag \
        --metadata startup-script="#! /bin/bash
          sudo apt-get update
          sudo apt-get install apache2 -y
          sudo service apache2 restart
          echo '<!doctype html><html><body><h1>www-1</h1></body></html>' | tee /var/www/html/index.html
          EOF"
    
    gcloud compute instances create www-2 \
        --image-family debian-8 \
        --image-project debian-cloud \
        --zone us-central1-b \
        --tags http-tag \
        --metadata startup-script="#! /bin/bash
          sudo apt-get update
          sudo apt-get install apache2 -y
          sudo service apache2 restart
          echo '<!doctype html><html><body><h1>www-2</h1></body></html>' | tee /var/www/html/index.html
          EOF"
    
    gcloud compute instances create www-3 \
        --image-family debian-8 \
        --image-project debian-cloud \
        --zone europe-west1-b \
        --tags http-tag \
        --metadata startup-script="#! /bin/bash
          sudo apt-get update
          sudo apt-get install apache2 -y
          sudo service apache2 restart
          echo '<!doctype html><html><body><h1>www-3</h1></body></html>' | tee /var/www/html/index.html
          EOF"
    
    gcloud compute instances create www-4 \
        --image-family debian-8 \
        --image-project debian-cloud \
        --zone europe-west1-b \
        --tags http-tag \
        --metadata startup-script="#! /bin/bash
          sudo apt-get update
          sudo apt-get install apache2 -y
          sudo service apache2 restart
          echo '<!doctype html><html><body><h1>www-4</h1></body></html>' | tee /var/www/html/index.html
          EOF"
    

    gcloud: HTTPS


    gcloud compute instances create wwws-1 \
        --image-family debian-8 \
        --image-project debian-cloud \
        --zone us-central1-b \
        --tags http-tag \
        --metadata startup-script="#! /bin/bash
          sudo apt-get update
          sudo apt-get install apache2 -y
          sudo a2ensite default-ssl
          sudo a2enmod ssl
          sudo service apache2 restart
          echo '<!doctype html><html><body><h1>wwws-1</h1></body></html>' | tee /var/www/html/index.html
          EOF"
    
    gcloud compute instances create wwws-2 \
        --image-family debian-8 \
        --image-project debian-cloud \
        --zone us-central1-b \
        --tags http-tag \
        --metadata startup-script="#! /bin/bash
          sudo apt-get update
          sudo apt-get install apache2 -y
          sudo a2ensite default-ssl
          sudo a2enmod ssl
          sudo service apache2 restart
          echo '<!doctype html><html><body><h1>wwws-2</h1></body></html>' | tee /var/www/html/index.html
          EOF"
    
    gcloud compute instances create wwws-3 \
        --image-family debian-8 \
        --image-project debian-cloud \
        --zone europe-west1-b \
        --tags http-tag \
        --metadata startup-script="#! /bin/bash
          sudo apt-get update
          sudo apt-get install apache2 -y
          sudo a2ensite default-ssl
          sudo a2enmod ssl
          sudo service apache2 restart
          echo '<!doctype html><html><body><h1>wwws-3</h1></body></html>' | tee /var/www/html/index.html
          EOF"
    
    gcloud compute instances create wwws-4 \
        --image-family debian-8 \
        --image-project debian-cloud \
        --zone europe-west1-b \
        --tags http-tag \
        --metadata startup-script="#! /bin/bash
          sudo apt-get update
          sudo apt-get install apache2 -y
          sudo a2ensite default-ssl
          sudo a2enmod ssl
          sudo service apache2 restart
          echo '<!doctype html><html><body><h1>wwws-4</h1></body></html>' | tee /var/www/html/index.html
          EOF"
    

  2. Create a firewall rule to allow external traffic to your virtual machine instances. This rule allows traffic from all sources, which is useful while you're setting up and testing your configuration. Later, you'll have the option of disabling HTTP(S) traffic from sources other than the load balancing service. The firewall rule makes use of the http-tag or https-tag tag that you created earlier. The firewall rule allows traffic to reach instances with the tag on the designated port.

    Console


    1. Go to the Firewalls page in the Google Cloud Platform Console.
      Go to the Firewalls page
    2. Click Create firewall rule.
    3. Enter a Name of www-firewall.
    4. Select Network to be default.
    5. Set Source filter to Allow from any source (0.0.0.0/0).
    6. Set Allowed protocols and ports to tcp:80 if you are using HTTP between the load balancer and the backends, tcp:443 if you are using HTTPS between the load balancer and the backends, or tcp:80,443 for both.
    7. Set Target tags to http-tag if you are using HTTP between the load balancer and the backends, https-tag if you are using HTTPS between the load balancer and the backends, or both. If specifying both, enter one, then press the Tab key, then enter the other.
    8. Click Create. It may take a moment for the Console to display the new firewall rule, or you might have to click Refresh to see the rule.

    gcloud: HTTP


    gcloud compute firewall-rules create www-firewall \
        --target-tags http-tag --allow tcp:80
    

    gcloud: HTTPS


    gcloud compute firewall-rules create www-firewall \
        --target-tags https-tag --allow tcp:443
    

  3. Verify that your instances are running.

    Console


    1. Go to the VM instances page in the Google Cloud Platform Console.
      Go to the VM instances page
    2. Click the addresses for your instances in the External IP column.

    [HTTPS only] In the browser, add https:// in front of the IP address. If you don't have a certificate on the instance, or only have a self-signed one, you'll have to accept the browser's warning about the lack of valid certificate.

    gcloud: HTTP


    1. List your instances to get their IP addresses from the EXTERNAL_IP column.

      gcloud compute instances list

    2. Run curl for each instance to confirm that they respond.

      curl http://IP_ADDRESS

    gcloud: HTTPS


    The curl -k option allows curl to work even if you have a self-signed certificate or no certificate at all. If you have a normal certificate, you can remove that parameter.

    1. List your instances to get their IP addresses from the EXTERNAL_IP column.

      gcloud compute instances list

    2. Run curl for each instance to confirm that they respond.

      curl -k https://IP_ADDRESS

Configuring services needed by the load balancing service

Now that your instances are up and running, set up the services needed for load balancing. You will create the following:

To configure these services, perform the following steps:

  1. Create a global static external IP address for your load balancer.

    Console


    1. Go to the External IP addresses page in the Google Cloud Platform Console.
      Go to the External IP addresses page
    2. Click Reserve static IP.
    3. Assign a Name of lb-ip-cr. You can pick another name, but use it consistently in subsequent steps.
    4. Set Type to Global.
    5. Click Reserve.

    gcloud: HTTP


    gcloud compute addresses create lb-ip-cr --global
    

    gcloud: HTTPS


    gcloud compute addresses create lb-ip-cr --global
    

  2. Create an instance group for each of your zones.

    Console


    1. Go to the Instance groups page in the Google Cloud Platform Console.
      Go to the Instance groups page
    2. Click Create instance group.
    3. Set the Name to us-resources-w for HTTP, or us-resources-s for HTTPS.
    4. Set the Zone to us-central1-b.
    5. Under Instance definition, click Select existing instances.
    6. From VM instances select www-1 and www-2 for HTTP, or wwws-1 and wwws-2 for HTTPS.
    7. Leave other settings as they are.
    8. Click Create.
    9. Repeat steps, but set the following:
      • Name: europe-resources-w for HTTP, or europe-resources-s for HTTPS
      • Zone: europe-west1-b
      • Instances: www-3 and www-4 for HTTP, or wwws-3 and wwws-4 for HTTPS
    10. Confirm that you now have two instance groups, each with two instances.

    gcloud: HTTP


    gcloud compute instance-groups unmanaged create us-resources-w --zone us-central1-b
    
    gcloud compute instance-groups unmanaged create europe-resources-w --zone europe-west1-b
    

    gcloud: HTTPS


    gcloud compute instance-groups unmanaged create us-resources-s --zone us-central1-b
    
    gcloud compute instance-groups unmanaged create europe-resources-s --zone europe-west1-b
    

  3. Add the instances you created earlier to the instance groups.

    Console


    Completed as part of prior step.

    gcloud: HTTP


    gcloud compute instance-groups unmanaged add-instances us-resources-w \
        --instances www-1,www-2 \
        --zone us-central1-b
    
    gcloud compute instance-groups unmanaged add-instances europe-resources-w \
        --instances www-3,www-4 \
        --zone europe-west1-b
    

    gcloud: HTTPS


    gcloud compute instance-groups unmanaged add-instances us-resources-s \
        --instances wwws-1,wwws-2 \
        --zone us-central1-b
    
    gcloud compute instance-groups unmanaged add-instances europe-resources-s \
        --instances wwws-3,wwws-4 \
        --zone europe-west1-b
    

  4. Create a health check.

    Console


    Use the gcloud command for HTTP if you are using HTTP between the load balancer and the backends. Use the gcloud command for HTTPS if you are using HTTPS between the load balancer and the backends. If you are using both, run both commands.

    gcloud: HTTP


    gcloud compute health-checks create http http-basic-check
    

    gcloud: HTTPS


    gcloud compute health-checks create https https-basic-check
    

Configuring the load balancing service

Load balancer functionality involves several connected services. In this section, you will set up and connect the services. The services you will create are as follows:

  • Named ports, which the load balancer uses to direct traffic to your instance groups.
  • Backend services, which monitor the usage and health of instances. Backend services know whether the instances in the instance group can receive traffic or not. If they cannot, the load balancer redirects traffic elsewhere if there are underutilized instances elsewhere.
  • A URL map, which parses the URL of the request and can forward certain requests to specific backend services based on the host and path of the request URL. In the example, since we are not using content-based forwarding, the URL map will only contain the default mapping.
  • An SSL certificate resource, if you are using HTTPS, which contains SSL certificate information for the load balancer.
  • A target proxy, which receives the request from the user and forwards it to the URL map. The target proxy is the service that decrypts SSL traffic using the SSL certificate resource. The target proxy can forward traffic to your instances via HTTP or HTTPS.
  • A global forwarding rule, which holds the global external IP address resource. The global forwarding rule forwards the incoming request to the target proxy.

Console


Name your load balancer

  1. Go to the Load balancing page in the Google Cloud Platform Console.
    Go to the Load balancing page
  2. Click Create load balancer.
  3. Under HTTP(S) load balancing, click Start configuration.
  4. For the Name of the load balancer, enter web-map.

Backend configuration

Configure a default backend service to handle your traffic.

  1. Click Backend configuration.
  2. In the Create or select a backend service pull-down menu, select Create a backend service.
  3. Set the Name of the backend service to web-map-backend-service.
  4. For Protocol, if traffic between the load balancer and the instances is to be HTTP, leave the everything as is. If the protocol is to be to HTTPS (recommended), click the Edit pencil and set Protocol to HTTPS and Named port to 'https`.
  5. Under Backends, set Instance group to us-resources-w or us-resources-s, depending on whether you're configuring HTTP or HTTPS.
  6. If traffic between the load balancer and the instances is to be HTTPS, set Port numbers to 443. If traffic between the load balancer and the instances is to be HTTP, set Port numbers to 80.
  7. Leave the default values for rest of the fields.
  8. Click Add backend.
  9. Select the europe-resources-w or europe-resources-s instance group, depending on whether you're configuring HTTP or HTTPS.
  10. If traffic between the load balancer and the instances is to be HTTPS, set Port numbers to 443. If traffic between the load balancer and the instances is to be HTTP, set Port numbers to 80.
  11. Leave the default values for rest of the fields.
  12. Set Health check to http-basic-check or https-basic-check, depending on whether you're configuring HTTP or HTTPS. This must match the Port numbers setting above. Use the HTTP health check if you set it port 80. Use the HTTPS health check if you set it to 443.

Host and path rules

In the left panel of the New HTTP(S) load balancer page, click Host and path rules.

For this example, we don't need to configure any host or path rules since all traffic will go to the default rule, so we can accept the pre-populated default.

Frontend configuration

If you are using HTTPS between the client and the load balancer, you will need an SSL certificate resource to configure the proxy. If you don't have one, see SSL Certificates for information on how to create a self-signed one for testing purposes. You should not use a self-signed certificate for production purposes.

  1. In the left panel of the New HTTP(S) load balancer page, click Frontend configuration.
  2. In the Protocol field, select HTTPS if you want HTTPS between the client and the load balancer. Select HTTP if you want HTTP between the client and the load balancer.
  3. In IP, select lb-ip-cr, which you created earlier.
  4. Select a Port of 80 if you are using HTTP. HTTPS traffic defaults to 443 and cannot be changed.
  5. [HTTPS only] If you already have an SSL certificate resource you want to use, select it from the Certificate drop-down menu. If not, select
    Create a new certificate.
    1. Fill in a Name of www-ssl-cert.
    2. In the appropriate fields upload your Public key certificate (.crt file), Certificate chain (.csr file), and Private key (.key file).
    3. Click Create.

Review and finalize

  1. In the left panel of the New HTTP(S) load balancer page, click Review and finalize.
  2. Compare your settings to what you intended to create.
  3. If everything looks correct, click Create to create your HTTP(S) load balancer.

gcloud: HTTP


  1. For each instance group, define an HTTP service and map a port name to the relevant port.

    gcloud compute instance-groups unmanaged set-named-ports us-resources-w \
        --named-ports http:80 \
        --zone us-central1-b
    
    gcloud compute instance-groups unmanaged set-named-ports europe-resources-w \
        --named-ports http:80 \
        --zone europe-west1-b
    
  2. Create a backend service and specify its parameters. Set the --protocol field to HTTP because we are using HTTP to go to the instances. Use the http-basic-check health check we created earlier as the health check.

    gcloud compute backend-services create web-map-backend-service \
        --protocol HTTP \
        --health-checks http-basic-check \
        --global
    
  3. Add your instance groups as backends to the backend services. A backend defines the capacity (max CPU utilization or max queries per second) of the instance groups it contains. In this example, set the balancing mode to be CPU utilization, the max utilization to be 80%, and the capacity scaling to be 1. Set the capacity scaling to 0 if you wish to drain a backend service.

    gcloud compute backend-services add-backend web-map-backend-service \
        --balancing-mode UTILIZATION \
        --max-utilization 0.8 \
        --capacity-scaler 1 \
        --instance-group us-resources-w \
        --instance-group-zone us-central1-b \
        --global
    
    gcloud compute backend-services add-backend web-map-backend-service \
        --balancing-mode UTILIZATION \
        --max-utilization 0.8 \
        --capacity-scaler 1 \
        --instance-group europe-resources-w \
        --instance-group-zone europe-west1-b \
        --global
    
  4. Create a default URL map that directs all incoming requests to all your instances.

    gcloud compute url-maps create web-map \
        --default-service web-map-backend-service
    
  5. Create a target HTTP proxy to route requests to your URL map.

    gcloud compute target-http-proxies create http-lb-proxy \
        --url-map web-map
    
  6. Look up the static IP address you created for your load balancer. You need to specify it in the next step when you create your forwarding rule. Replace [LB_IP_ADDRESS] in the next command with your static IP address.

    gcloud compute addresses list
    
  7. Create a global forwarding rule to handle and route incoming requests. A forwarding rule sends traffic to a specific target HTTP or HTTPS proxy depending on the IP address, IP protocol, and port specified. The global forwarding rule does not support multiple ports. Replace [LB_IP_ADDRESS] in the command with the static IP address you created.

    gcloud compute forwarding-rules create http-content-rule \
        --address [LB_IP_ADDRESS] --global \
        --target-http-proxy http-lb-proxy \
        --ports 80
    

gcloud: HTTPS


  1. For each instance group, define an HTTPS service and map a port name to the relevant port. Once configured, the load balancing service forwards traffic to the named port.

    gcloud compute instance-groups unmanaged set-named-ports us-resources-s \
        --named-ports https:443 \
        --zone us-central1-b
    
    gcloud compute instance-groups unmanaged set-named-ports europe-resources-s \
        --named-ports https:443 \
        --zone europe-west1-b
    
  2. Create a backend service for each content provider. Set the --protocol field to HTTPS because we are using HTTPS to go to the instances. Use the https-basic-check health check we created earlier as the health check.

    gcloud compute backend-services create web-map-backend-service \
        --protocol HTTPS \
        --health-checks https-basic-check
    
  3. Add your instance groups as backends to the backend services. A backend defines the capacity (max CPU utilization or max queries per second) of the instance groups it contains. In this example, set the balancing mode to be CPU utilization, the max utilization to be 80%, and the capacity scaling to be 1. Set the capacity scaling to 0 if you wish to drain a backend service.

    gcloud compute backend-services add-backend web-map-backend-service \
        --balancing-mode UTILIZATION \
        --max-utilization 0.8 \
        --capacity-scaler 1 \
        --instance-group us-resources-s \
        --zone us-central1-b
    
    gcloud compute backend-services add-backend web-map-backend-service \
        --balancing-mode UTILIZATION \
        --max-utilization 0.8 \
        --capacity-scaler 1 \
        --instance-group europe-resources-s \
        --zone europe-west1-b
    
  4. Create a default URL map that directs all incoming requests to all your instances. If you need to divide your traffic to different instances depending on the URL being requested, see content-based routing.

    gcloud compute url-maps create web-map \
        --default-service web-map-backend-service
    
  5. Create an SSL certificate resource to use in the HTTPS proxy. If you don’t have a private key and signed certificate, you can create and use a self-signed certificate for testing purpose. See SSL Certificates for further information. You should not use a self-signed certificate for production purposes.

    gcloud compute ssl-certificates create www-ssl-cert \
        --certificate CRT_FILE_PATH \
        --private-key KEY_FILE_PATH
    
  6. Create a target HTTPS proxy to route requests to your URL map. The proxy is the portion of the load balancer that holds the SSL certificate for HTTPS load balancing, so you also load your certificate in this step.

    gcloud compute target-https-proxies create https-lb-proxy \
        --url-map web-map --ssl-certificate www-ssl-cert
    
  7. Create a global forwarding rule to handle and route incoming requests. A forwarding rule sends traffic to a specific target HTTP or HTTPS proxy depending on the IP address, IP protocol, and port specified. The global forwarding rule does not support multiple ports. Replace [LB_IP_ADDRESS] in the command with the static IP address you created.

    gcloud compute forwarding-rules create https-rule \
        --address lb-ip-1 \
        --global \
        --target-https-proxy https-lb-proxy \
        --ports 443
    

After creating the global forwarding rule, it can take several minutes for your configuration to propagate.

Sending traffic to your instances

Now that you have configured your load balancing service, you can start sending traffic to the forwarding rule and watch the traffic be dispersed to different instances.

Console


  1. Go to the Load balancing page in the Google Cloud Platform Console.
    Go to the Load balancing page
  2. Click on web-map to expand the load balancer you just created.
  3. In the Backend section, confirm that instances are healthy by checking the Healthy column. It can take a few moments for the display to indicate that the instances are healthy.
  4. Once the display shows that the instances are healthy, copy the IP:Port from the Frontend section and paste that into your browser.
  5. In your browser you should see your default content page displayed. If you used a self-signed certificate for testing, your browser will display a warning. You will have to explicitly tell your browser to accept the certificate.

gcloud: HTTP


  1. Find the IP address of your global forwarding rule.

    gcloud compute forwarding-rules list
    
  2. Use the curl command to test.

    curl http://IP_ADDRESS
    

In your browser you should see your default content page displayed. If you used a self-signed certificate for testing, your browser will display a warning. You will have to explicitly tell your browser to accept the certificate.

gcloud: HTTPS


  1. Find the IP address of your global forwarding rule.

    gcloud compute forwarding-rules list
    
  2. Use the curl command to test.

    curl -k https://IP_ADDRESS
    

In your browser you should see your default content page displayed. If you used a self-signed certificate for testing, your browser will display a warning. You will have to explicitly tell your browser to accept the certificate.

You should see responses from the region closest to you. If your response is initially unsuccessful, you might need to wait a few minutes for the configuration to fully load and for your instances to be marked healthy before trying again. Each reload of the page may show the other instance. To simulate a user in a different geography, try using a web proxy to make the requests.

Alternatively, you can connect to one of your virtual machine instances in different region, then run a curl command from that instance to see the request go to an instance in the region closest to it.

Shutting off HTTP(S) access from everywhere but the load balancing service

Once everything is working, modify your firewall rules so HTTP(S) traffic to your instances can only come from your load balancing service.

Console


  1. Go to the Firewalls page in the Google Cloud Platform Console.
    Go to the Firewalls page
  2. Click Create firewall rule.
  3. Specify a Name of allow-lb-and-healthcheck.
  4. Select Network to be default.
  5. Leave Source filter set to IP ranges.
  6. Set Source IP Ranges to 130.211.0.0/22 and 35.191.0.0/16.
  7. Set Allowed protocols and ports to tcp:80 for HTTP, tcp:443 for HTTPS, or tcp:80,443 for both.
  8. Set Target tags to http-tag, https-tag, or both. If specifying both, enter one, then press the Tab key, then enter the other.
  9. Click Create. It might take a moment for the new firewall rule to be displayed on the Console.

gcloud: HTTP


gcloud compute firewall-rules create allow-lb-and-healthcheck \
    --source-ranges 130.211.0.0/22,35.191.0.0/16 \
    --target-tags http-tag \
    --allow tcp:80

gcloud: HTTPS


gcloud compute firewall-rules create allow-lb-and-healthcheck \
    --source-ranges 130.211.0.0/22,35.191.0.0/16 \
    --target-tags https-tag \
    --allow tcp:443

Then, remove the rule that allows HTTP(S) traffic from other sources.

Console


  1. Go to the Firewalls page in the Google Cloud Platform Console.
    Go to the Firewalls page
  2. Select the checkbox next to the www-firewall firewall rule.
  3. Click Delete.

gcloud: HTTP


gcloud compute firewall-rules delete www-firewall

gcloud: HTTPS


gcloud compute firewall-rules delete www-firewall

Lastly, test that the load balancer can reach the instances, but that other sources can't.

Console


  1. Go to the Load balancing page in the Google Cloud Platform Console.
    Go to the Load balancing page
  2. Click on web-map to expand the load balancer you just created. It will show the IP and port under the Frontend section. Copy and paste that into your browser.
    You should see your page.
  3. Go to the VM instances page in the Google Cloud Platform Console.
    Go to the VM instances page
  4. Click the link under External IP for each individual instance. If the instance was set up for HTTPS only, add https:// to the front of IP address in the browser. In either case, connection should time out. You should not be able to reach the instance.

gcloud: HTTP


  1. Find the IP address of your global forwarding rule.

    gcloud compute addresses list
    
  2. Use the curl command to test the response for your load balancing service. This command should work.

    curl http://IP_ADDRESS
    
  3. Find the IP address of your individual instances and note the addresses in the EXTERNAL_IP column.

    gcloud compute instances list
    
  4. Use the curl command to test the response for individual instances. For each curl command, use the EXTERNAL_IP of the appropriate instance. All instances should time out.

    curl http://EXTERNAL_IP
    

gcloud: HTTPS


  1. Find the IP address of your global forwarding rule.

    gcloud compute addresses list
    
  2. Use the curl command to test the response for your load balancing service. This command should work.

    curl -k https://IP_ADDRESS
    
  3. Find the IP address of your individual instances and note the addresses in the EXTERNAL_IP column.

    gcloud compute instances list
    
  4. Use the curl command to test the response for individual instances. For each curl command, use the EXTERNAL_IP of the appropriate instance. All instances should time out.

    curl -k https://EXTERNAL_IP
    

Optional: Removing external IPs except for a bastion host

HTTP(S) load balancing makes use of the targets' internal IPs, not their external IPs. Once you have load balancing working, you can increase security by removing the external IPs from your load balancing targets, then connect through an intermediary instance to perform tasks on the load balanced instances. That way, no one outside your network can access them in any way, except through the load balancer.

You'll need to keep at least one instance in your network with an external IP address, normally one designated for this purpose. See Connecting from one instance to another for instructions on connecting from an instance with an external IP address to one without.

If you accidentally delete all external IP addresses, you can use the Google Cloud Platform Console to create a new one.

Remove the external IP address from an instance.

Console


  1. Go to the VM instances page in the Google Cloud Platform Console.
    Go to the VM instances page
  2. Click the Name of the instance you wish to change.
  3. Under External IP, click Edit.
  4. Change the value in the drop-down to None.
  5. Click Save.
  6. Return to the VM Instances page. The External IP field will be blank and the SSH button will be grayed out.
  7. Make sure the page still appears when accessed via the load balancer from your browser.

gcloud: HTTP


  1. Run the following command. Make a note of the name of the instance as shown in the NAME field.

    gcloud compute instances list
    
  2. Delete the access config for the instance. For NAME, put the name of the instance.

    gcloud compute instances delete-access-config NAME
    

gcloud: HTTPS


  1. Run the following command. Make a note of the name of the instance as shown in the NAME field.

    gcloud compute instances list
    
  2. Delete the access config for the instance. For NAME, put the name of the instance.

    gcloud compute instances delete-access-config NAME
    

What's next

Send feedback about...

Compute Engine Documentation