IPs

You must have noticed the presence of an internal and an external IP associated with our VMs. Each GCP project comes with a Virtual Private Cloud (VPC) network, which is automatically created with the project. A VPC is basically a private and isolated virtual network partition that enables your resources to talk to each other within a given project, while allowing control of external access to the VPC. Upon creation, each instance gets an internal IP address assigned to allow other resources within the project's VPC to communicate with the instance. To communicate with entities outside the VPC, including connections with the internet, the instance requires an external IP address.

IP addresses, both internal and external, can be ephemeral or static. Ephemeral IP addresses remain associated with the instance only as long as the instance is running. When the instance stops or is terminated, the IP address is released in the global GCP pool of IP addresses. For an instance to have a stable IP address, the IP address needs to become static. Static addresses generate extra costs.

Changing the nature of an IP address from ephemeral to static can be done via the console. Stop the VM and edit it. In the Network interface section, select the right type for the internal and external IPs of the VM:

The management of IPs and VPCs is accessible from the VPC network console at https://console.cloud.google.com/networking/networks/list.

You can create a new static IP address and then attach it to your instance directly from the External IP addresses page:

Click on Reserve a static address, select regional for region type, set the region to your instance's region, and attach it to your sparrow instance:

The command-line equivalent of creating a static IP and adding it to the instance is:

$ gcloud compute --project=packt-gcp addresses create sparrow-notebook --region=us-east1
$ gcloud compute --project=packt-gcp instances add-access-config sparrow --zone=us-east1-d --address=IP_OF_THE_NEWLY_CREATED_STATIC_ADDRESS

As static IPs are billed even when not used, it is important to release them when no longer needed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.253.2