Building internet connectivity for private VMs

This document describes options for connecting to and from the internet using Compute Engine resources that have private IP addresses. This is helpful for developers who create Google Cloud Platform (GCP) services and for network administrators of GCP environments.

This tutorial assumes you are familiar with deploying VPCs, with Compute Engine, and with basic TCP/IP networking.

Objectives

  • Learn about the options available for connecting between private VMs outside their VPC.
  • Create an instance of Cloud Identity-Aware Proxy (Cloud IAP) for TCP tunnels that's appropriate for interactive services such as SSH.
  • Create a Cloud NAT instance to enable VMs to make outbound connections to the internet.
  • Configure an HTTP load balancer to support inbound connections from the internet to your VMs.

Costs

This tutorial uses billable components of Google Cloud Platform, including:

Use the pricing calculator to generate a cost estimate based on your projected usage. We calculate that the total to run this tutorial is less than US$5 per day.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Select or create a GCP project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Google Cloud Platform project.

    Learn how to enable billing

Introduction

Private IP addresses provide a number of advantages over public (external) IP addresses, including:

  • Reduced attack surface. Removing external IP addresses from VMs makes it more difficult for attackers to reach the VMs and exploit potential vulnerabilities.
  • Increased flexibility. Introducing a layer of abstraction, such as a load balancer or a NAT service, allows more reliable and flexible service delivery when compared with static, external IP addresses.

This solution discusses three scenarios, as described in the following table:

Interactive Fetching Serving
An SSH connection is initiated from a remote host directly to a VM using IAP for TCP.

Example: Remote administration using SSH or RDP

A connection is initiated by a VM to an external host on the internet using Cloud NAT.

Example: OS updates, external APIs

A connection is initiated by a remote host to a VM through a global GCP load balancer.

Example: Application frontends, WordPress

Some environments might involve only one of these scenarios. However, many environments require all of these scenarios, and this is fully supported in GCP.

The following sections describe a multi-region environment with an HTTP load-balanced service backed by two VMs in two regions. These VMs use Cloud NAT for outgoing communications. For administration, the VMs are accessible through SSH tunneled over IAP.

The following diagram provides an overview of all three use cases and the relevant components.

Architecture of solution showing flow from client through load balancer to VM instances, Cloud NAT for access from the instances to the internet, and IAP to allow direct SSH access from a client to the instances.

Creating VM instances

To begin the tutorial, you create a total of four virtual machine (VM) instances—two instances per region in two different regions. You give all of the instances the same tag, which is used later by a firewall rule to allow incoming traffic to reach your instances.

The following diagram shows the VM instances and instance groups you create, distributed in two zones.

Architecture of solution highlighting the four VM instances in 2 zones.

The startup script that you add to each instance installs Apache and creates a unique home page for each instance.

The procedure includes instructions for using both the GCP Console and gcloud commands. The easiest way to use gcloud commands is to use Cloud Shell.

Console

  1. In the GCP Console, go to the VM instances page:

    GO TO THE VM INSTANCES PAGE

  2. Click Create instance.

  3. Set Name to www-1.

  4. Set the Zone to us-central1-b.

  5. Click Management, Security, Disks, Networking, Sole Tenancy.

  6. Click Networking and make the following settings:

    • For HTTP traffic, in the Network tags box, enter http-tag.
    • Under Network Interfaces, click edit.
    • Under External IP, select None.
  7. Click Management and set Startup script to the following:

    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. Click Create.

  9. Create www-2 with the same settings, except set Startup script to the following:

    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
    
  10. Create www-3 with the same settings, except set Zone to europe-west1-b and set Startup script to the following:

    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
    
  11. Create www-4 with the same settings, except set Zone to europe-west1-b and set Startup script to the following:

    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

  1. Open Cloud Shell:

    OPEN Cloud Shell

  2. Create an instance named www-1 in us-central1-bwith a basic startup script:

    gcloud compute instances create www-1 \
        --image-family debian-9 \
        --image-project debian-cloud \
        --zone us-central1-b \
        --tags http-tag \
        --network-interface=no-address \
        --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"
    
  3. Create an instance named www-2 in us-central1-b:

    gcloud compute instances create www-2 \
        --image-family debian-9 \
        --image-project debian-cloud \
        --zone us-central1-b \
        --tags http-tag \
        --network-interface=no-address \
        --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"
    
  4. Create an instance named www-3, this time in europe-west1-b:

    gcloud compute instances create www-3 \
        --image-family debian-9 \
        --image-project debian-cloud \
        --zone europe-west1-b \
        --tags http-tag \
        --network-interface=no-address \
        --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"
    
  5. Create an instance named www-4, this one also in europe-west1-b:

    gcloud compute instances create www-4 \
        --image-family debian-9 \
        --image-project debian-cloud \
        --zone europe-west1-b \
        --tags http-tag \
        --network-interface=no-address \
        --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"
    

Configuring IAP tunnels for interacting with instances

To log in to VM instances, you connect to the instances using tools like SSH or RDP. In the configuration you're creating in this tutorial, you can't directly connect to instances. However, you can use TCP forwarding in Cloud IAP, which enables remote access for these interactive patterns.

For this tutorial, you use SSH.

In this section you do the following:

  1. Connect to a Compute Engine instance using the Cloud IAP tunnel.
  2. Add a second user with IAP tunneling permission in Cloud IAM.

The following diagram illustrates the architecture that you build in this section. The grey areas are discussed in other parts of this tutorial.

Architecture of solution showing Cloud IAP providing access for SSH access between a client and the instances.

Limitations of Cloud IAP

  • Bandwidth: The Cloud IAP TCP forwarding feature isn't intended for bulk transfer of data. Cloud IAP reserves the right to rate-limit users who are deemed to be abusing this service.
  • Connection length: Cloud IAP won't disconnect active sessions unless required for maintenance.
  • Protocol: Cloud IAP for TCP doesn't support UDP.

Create firewall rules to allow tunneling

In order to connect to your instances using SSH, you need to open an appropriate port on the firewall. IAP connections come from a specific set of IP addresses (35.235.240.0/20). Therefore, you can limit the rule to this CIDR range.

Console

  1. In the GCP Console, go to the Firewalls page:

    GO TO THE FIREWALLS PAGE

  2. Click Create firewall rule.

  3. Set Name to allow-ssh-from-iap.

  4. Leave VPC network as default.

  5. Under Targets, select Specified target tags.

  6. Set Target tags to http-tag.

  7. Leave Source filter set to IP ranges.

  8. Set Source IP Ranges to 35.235.240.0/20.

  9. Set Allowed protocols and ports to tcp:22.

  10. Click Create.

    It might take a moment for the new firewall rule to be displayed in the console.

gcloud

  • Create a firewall rule named allow-ssh-from-iap:

    gcloud compute firewall-rules create allow-ssh-from-iap \
        --source-ranges 35.235.240.0/20 \
        --target-tags http-tag \
        --allow tcp:22
    

Test tunneling

  • In Cloud Shell, connect to instance www-1 using Cloud IAP:

    gcloud beta compute ssh www-1 \
        --zone us-central1-b \
        --tunnel-through-iap
    

If the connection succeeds, you have an SSH session that is tunneled through Cloud IAP directly to your private VM.

Grant access to additional users

Cloud IAP uses your existing project roles and permissions when you connect to VM instances. By default, instance owners are the only users that have the IAP Secured Tunnel User role. If you want to allow other users to access your VMs using IAP tunneling, you need to grant this role to those users.

  1. In the GCP Console, go to Security > Identity-Aware Proxy:

    IAP option in the Security page of the GCP Console.

    If you see a message that tells you that you need to configure the OAuth consent screen, disregard the message; it's not relevant to Cloud IAP for TCP.

  2. Select the SSH and TCP Resources tab.

  3. Select the VMs you've created:

    Console showing all 4 instances selected.

  4. On the right-hand side, click Add Member.

  5. Add the users you want to grant permissions to, select the IAP-secured Tunnel User role, and then click Save:

    "Add Members" dialog box with a new member name added and the "IAP-secured Tunnel User" role selected.

Summary

You can now connect to your instances using SSH to administer the instances or troubleshoot them.

Many applications need to make outgoing connections in order to download patches, connect with partners, or download resources. In the next section, you configure Cloud NAT to allow your VMs to reach these resources.

Deploying Cloud NAT for fetching

The Cloud NAT service allows GCP VM instances that don't have external IP addresses to connect to the internet. Cloud NAT implements outbound NAT in conjunction with a default route to allow your instances to reach the internet. It doesn't implement inbound NAT. Hosts outside of your VPC network can respond only to established connections initiated by your instances; they cannot initiate their own connections to your instances using Cloud NAT.

Cloud NAT is a regional resource. You can configure it to allow traffic from all primary and secondary IP address ranges of subnets in a region, or you can configure it to apply to only some of those ranges.

In this section, you configure a Cloud NAT gateway in each region that you used earlier. The following diagram illustrates the architecture that you build in this section. The grey areas are discussed in other parts of this tutorial.

Architecture of solution showing Cloud NAT instances between the instances and the internet.

Create a NAT configuration using Cloud Router

You must create the Cloud Router instance in the same region as the instances that need to use Cloud NAT. Cloud NAT is only used to place NAT information onto the VMs; it's not used as part of the actual Cloud NAT gateway.

This configuration allows all instances in the region to use Cloud NAT for all primary and alias IP ranges. It also automatically allocates the external IP addresses for the NAT gateway. For more options, see the gcloud compute routers documentation.

Console

  1. Go to the Cloud NAT page:

    GO TO THE CLOUD NAT PAGE

  2. Click Get started or Create NAT gateway.

  3. Set Gateway name to nat-config.

  4. Set VPC network to default.

  5. Set Region to us-central1.

  6. Under Cloud Router, select Create new router, and then do the following:

    • Set Name to nat-router-us-central1.
    • Click Create.
  7. Click Create.

  8. Repeat the procedure, but substitute these values:

    • Name: nat-router-europe-west1
    • Region: europe-west1

gcloud

  1. Create Cloud Router instances in each region:

    gcloud compute routers create nat-router-us-central1 \
        --network default \
        --region us-central1
    
    gcloud compute routers create nat-router-europe-west1 \
        --network default \
        --region europe-west1
    
  2. Configure the routers for Cloud NAT:

    gcloud compute routers nats create nat-config \
        --router-region us-central1 \
        --router nat-router-us-central1 \
        --nat-all-subnet-ip-ranges \
         --auto-allocate-nat-external-ips
    
    gcloud compute routers nats create nat-config \
        --router-region europe-west1 \
        --router nat-router-europe-west1 \
        --nat-all-subnet-ip-ranges \
        --auto-allocate-nat-external-ips
    

Test Cloud NAT configuration

You can now test that you're able to make outbound requests from your VM instances to the internet.

  1. Wait up to 3 minutes for the NAT configuration to propagate to the VM.
  2. In Cloud Shell, connect to your instance using the tunnel you created:

    gcloud beta compute ssh www-1 --tunnel-through-iap
    
  3. When you're logged in to the instance, use the curl command to make an outbound request:

    curl example.com
    

    You see the following output:

    <html>
    <head>
    <title>Example Domain</title>
    ...
    ...
    ...
    </head>
    
    <body>
    <div>
        <h1>Example Domain</h1>
        <p>This domain is established to be used for illustrative examples in documents.
            You may use this domain in examples without prior coordination or asking for
            permission.
        </p>
        <p><a href="http://www.iana.org/domains/example">More information...</a></p>
    </div>
    </body>
    </html>
    
    

If the command is successful, you've validated that your VMs can connect to the internet using Cloud NAT.

Summary

Your instances can now make outgoing connections in order to download patches, connect with partners, or download resources.

In the next section, you add load balancing to your deployment and configure it to allow remote clients to initiate requests to your servers.

Creating an HTTP load-balanced service for serving

Using Cloud Load Balancing for your application has many advantages. It can provide seamless, scalable load balancing for over a million queries per second. It can also offload SSL overhead from your VMs, route queries to the best region for your users based on both location and availability, and support modern protocols such as HTTP/2 and QUIC.

For this tutorial, you take advantage of another key feature: global anycast IP connection proxying. This feature provides a single public IP address that's terminated on Google's globally distributed edge. Clients can then connect to resources hosted on private IP addresses anywhere in GCP. This configuration helps protect instances from DDoS attacks and direct attacks. It also enables features such as Google Cloud Armor for even more security.

In this section of the tutorial, you do the following:

  1. Create a firewall rule to allow access from load balancers.
  2. Allocate static, global IPv4 and IPv6 addresses for the load balancer.
  3. Create an instance group for your instances.
  4. Start sending traffic to your instances.

The following diagram illustrates the architecture that you build in this section. The grey areas are discussed in other parts of this tutorial.

Architecture highlighting 4 instances in 2 instance groups.

Open the firewall

The next task is to create a firewall rule to allow traffic from the load balancers to your VM instances. This rule allows traffic from the GCP address range that's used both by load balancers and health checks. The firewall rule uses the http-tag tag that you created earlier; the firewall rule allows traffic to the designated port to reach instances that have the tag.

Console

  1. In the GCP Console, go to the Firewalls page:

    GO TO THE FIREWALLS PAGE

  2. Click Create firewall rule.

  3. Set Name to allow-lb-and-healthcheck.

  4. Leave the VPC network as default.

  5. Under Targets, select Specified target tags.

  6. Set Target tags to http-tag.

  7. Leave Source filter set to IP ranges.

  8. Set Source IP Ranges to 130.211.0.0/22 and 35.191.0.0/16.

  9. Set Allowed protocols and ports to tcp:80.

  10. Click Create.

    It might take a moment for the new firewall rule to be displayed in the console.

gcloud

  • Create a firewall rule named allow-lb-and-healthcheck:

    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
    

Allocate an external IP address for load balancers

If you're serving traffic to the internet, you need to allocate an external address for the load balancer. You can allocate an IPv4 address, an IPv6 address, or both. In this section, you reserve static IPv4 and IPv6 addresses suitable for adding to DNS.

There is no additional charge for public IP addresses, because they are used with a load balancer.

Console

  1. In the GCP Console, go to the External IP addresses page:

    GO TO THE EXTERNAL IP ADDRESSES PAGE

  2. Click Reserve static address to reserve an IPv4 address.

  3. Set Name to lb-ip-cr.

  4. Leave Type set to Global.

  5. Click Reserve.

  6. Click Reserve static address again to reserve an IPv6 address.

  7. Set Name to lb-ipv6-cr.

  8. Set IP version to IPv6.

  9. Leave Type set to Global.

  10. Click Reserve.

gcloud

  1. Create a static IP address named lb-ip-cr for IPv4:

    gcloud compute addresses create lb-ip-cr \
        --ip-version=IPV4 \
        --global
    
  2. Create a static IP address named lb-ipv6-cr for IPv6:

    gcloud compute addresses create lb-ipv6-cr \
        --ip-version=IPV6 \
        --global
    

Create instance groups and add instances

GCP load balancers require instance groups to act as backends for traffic. In this tutorial, you use unmanaged instance groups for simplicity. However, you could also use managed instance groups to take advantage of features such as autoscaling, autohealing, regional (multi-zone) deployment, and auto-updating.

In this section, you create an instance group for each of the zones that you're using.

Console

  1. In the GCP Console, go to the Instance groups page:

    GO TO THE INSTANCE GROUPS PAGE

  2. Click Create instance group.

  3. On the left-hand side, click New unmanaged instance group.

  4. Set Name to us-resources-w.

  5. Set Region to us-central1

  6. Set Zone to us-central1-b.

  7. Select Network (default) and Subnetwork (default).

  8. Under VM instances, do the following:

    • Click Add an instance, and then select www-1.
    • Click Add an instance again, and then select www-2.
    • Click Create.
  9. Repeat this procedure to create a second instance group, but use the following values:

    • Name: europe-resources-w
    • Zone: europe-west1-b
    • Instances: www-3 and www-4
  10. In the Instance groups page, confirm that you have two instance groups, each with two instances.

gcloud

  1. Create the us-resources-w instance group:

    gcloud compute instance-groups unmanaged create us-resources-w \
        --zone us-central1-b
    
  2. Add the www-1 and www-2 instances:

    gcloud compute instance-groups unmanaged add-instances us-resources-w \
        --instances www-1,www-2 \
        --zone us-central1-b
    
  3. Create the europe-resources-w instance group:

    gcloud compute instance-groups unmanaged create europe-resources-w \
        --zone europe-west1-b
    
  4. Add the www-3 and www-4 instances:

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

Configure the load balancing service

Load balancer functionality involves several connected services. In this section, you 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.
  • A health check, which polls your instances to see if they are healthy. The load balancer sends traffic only to healthy instances.
  • Backend services, which monitor instance usage and health. Backend services know whether the instances in the instance group can receive traffic. If the instances can't receive traffic, the load balancer redirects traffic, provided that instances elsewhere have sufficient capacity. A backend defines the capacity of the instance groups that it contains (maximum CPU utilization or maximum queries per second).
  • A URL map, which parses the URL of the request and can forward requests to specific backend services based on the host and path of the request URL. In this tutorial, because you aren't using content-based forwarding, the URL map contains only the default mapping.
  • A target proxy, which receives the request from the user and forwards it to the URL map.
  • Two global forwarding rules, one each for IPv4 and IPv6, that hold the global external IP address resources. Global forwarding rules forward the incoming request to the target proxy.

Create the load balancer

In this section you create the load balancer and configure a default backend service to handle your traffic. You also create a health check.

Console

  1. In the GCP Console, go to the Create load balancer page:

    GO TO THE CREATE LOAD BALANCER PAGE

  2. Under HTTP(S) load balancing, click Start configuration.

  3. Set Name to web-map.

  4. In the left panel of the New HTTP(S) load balancer page, click Backend configuration.

  5. In the Create or select backend services & backend buckets list, select Backend services, and then Create a backend service. You see the Create Backend Service dialog box.

  6. Set Name to web-map-backend-service.

  7. Set the Protocol. For HTTP protocol, leave the values set to the defaults.

  8. For Backend type, select Instance Groups.

  9. Under Backends, set Instance group to us-resources-w.

  10. Click Add backend.

  11. Select the europe-resources-w instance group and then do the following:

    • For HTTP traffic between the load balancer and the instances, make sure that Port numbers is set to 80.
    • Leave the default values for the rest of the fields.
  12. Click Done.

  13. Under Health check, select Create a health check or Create another health check.

  14. Set the following health check parameters:

    • Name: http-basic-check
    • Protocol: HTTP
    • Port: 80
  15. Click Create.

gcloud

  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 health check:

    gcloud compute health-checks create http http-basic-check \
        --port 80
    
  3. Create a backend service:

    gcloud compute backend-services create web-map-backend-service \
        --protocol HTTP \
        --health-checks http-basic-check \
        --global
    

    You set the --protocol flag to HTTP because you're using HTTP to go to the instances. For the health check, you use the http-basic-check health check that you created earlier.

  4. Add your instance groups as backends to the backend services:

    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
    

Set host and path rules

Console

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

    For this tutorial, you don't need to configure any host or path rules, because all traffic will go to the default rule. Therefore, you can accept the pre-populated default values.

gcloud

  1. Create a default URL map that directs all incoming requests to all of your instances:

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

    gcloud compute target-http-proxies create http-lb-proxy \
        --url-map web-map
    

Configure the frontend

Console

  1. In the left panel of the New HTTP(S) load balancer page, click Frontend configuration.
  2. Set Name to http-cr-rule.
  3. Set Protocol to HTTP.
  4. Set IP version to IPv4.
  5. In the IP address list, select lb-ip-cr, the address that you created earlier.
  6. Confirm that Port is set to 80.
  7. Click Done.
  8. Click Add frontend IP and port.
  9. Set Name to http-cr-ipv6-rule.
  10. For Protocol, select HTTP.
  11. Set IP version to IPv6.
  12. In the IP address list, select lb-ipv6-cr, the other address that you created earlier.
  13. Confirm that Port is set to 80.
  14. Click Create.
  15. Click Done.

gcloud

  1. Get the static IP addresses that you created for your load balancer. Make a note of them, because you use them in the next step.

    gcloud compute addresses list
    
  2. Create two global forwarding rules to route incoming requests to the proxy, one for IPv4 and one for IPv6. Replace lb_ip_address in the command with the static IPv4 address you created, and replace lb_ipv6_address with the IPv6 address you created.

    gcloud compute forwarding-rules create http-cr-rule \
        --address lb_ip_address \
        --global \
        --target-http-proxy http-lb-proxy \
        --ports 80
    
    gcloud compute forwarding-rules create http-cr-ipv6-rule \
        --address lb_ipv6_address \
        --global \
        --target-http-proxy http-lb-proxy \
       --ports 80
    

Review and finalize

  1. In the GCP Console, go to the Create load balancer page:

    GO TO THE CREATE LOAD BALANCER PAGE

  2. In the left panel of the New HTTP(S) load balancer page, click Review and finalize.

  3. Compare your settings to what you intended to create.

  4. If the settings are correct, click Create.

    You are returned to the Load Balancing pages. After the load balancer is created, a green check mark next to it indicates that it's running.

After you create the global forwarding rules, it can take several minutes for your configuration to propagate.

Test the configuration

In this section, you send an HTTP request to your instance to verify that the load-balancing configuration is working.

Console

  1. In the GCP Console, go to the Load balancing page:

    GO TO THE LOAD BALANCING PAGE

  2. Select the load balancer named web-map to see details about the load balancer that you just created.

  3. In the Backend section of the page, confirm that instances are healthy by viewing the Healthy column.

    It can take a few moments for the display to indicate that the instances are healthy.

  4. When the display shows that the instances are healthy, copy the IP:Port value from the Frontend section and paste it into your browser.

    In your browser, you see your default content page.

gcloud

  1. Get the IP addresses of your global forwarding rules, and make a note of them for the next step:

    gcloud compute forwarding-rules list
    
  2. Use the curl command to test the response for various URLs for your services. Try both IPv4 and IPv6. For IPv6, you must put [] around the address, such as http://[2001:DB8::]/.

    curl http://ipv4-address
    
    curl -g -6 "http://[ipv6-address]/"
    

Summary

Your VMs can now serve traffic to the internet and can fetch data from the internet. You can also access them using SSH in order to perform administration tasks. All of this functionality is achieved using only private IP addresses, which helps protect them from direct attacks by not exposing IP addresses that are reachable from the internet.

Cleaning up

To avoid incurring charges to your Google Cloud Platform account for the resources used in this tutorial:

Delete the project

  1. In the GCP Console, go to the Projects page.

    Go to the Projects page

  2. In the project list, select the project you want to delete and click Delete .
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

What's next

Was this page helpful? Let us know how we did:

Send feedback about...