Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Virtual Private Cloud (VPC) - Google Cloud

Introduction

A Virtual Private Cloud (VPC) is a private network that you can create within Google Cloud. It provides a secure and isolated environment for your Google Cloud resources. VPCs enable you to have full control over network configuration, including IP address ranges, subnets, route tables, and gateways.

Creating a VPC

To create a VPC in Google Cloud, follow these steps:

  1. Go to the Google Cloud Console.
  2. Navigate to the VPC network section under the "Networking" category.
  3. Click on "Create VPC network".
  4. Provide a name for your VPC.
  5. Specify the subnet creation mode (e.g., "Custom" or "Automatic").
  6. Define the IP range for your subnets.
  7. Click "Create" to finalize the VPC creation.
Example: Creating a VPC named "my-vpc" with a custom subnet.

Creating Subnets

After creating a VPC, you need to create subnets to allocate IP ranges for different regions.

To create a subnet:

  1. Go to the VPC network section in the Google Cloud Console.
  2. Select the VPC you created.
  3. Click on "Add subnet".
  4. Provide a name for the subnet.
  5. Select the region for the subnet.
  6. Specify the IP range for the subnet.
  7. Click "Create" to finalize the subnet creation.
Example: Creating a subnet named "subnet-1" in the "us-central1" region with the IP range "10.0.0.0/24".

Firewall Rules

Firewall rules allow you to control the traffic to and from your VPC networks. You can create and manage firewall rules to allow or deny traffic based on specified conditions.

To create a firewall rule:

  1. Go to the VPC network section in the Google Cloud Console.
  2. Select "Firewall rules" from the navigation menu.
  3. Click on "Create firewall rule".
  4. Provide a name for the firewall rule.
  5. Specify the network to which the rule will apply.
  6. Define the targets, source IP ranges, and protocols/ports.
  7. Set the action to "Allow" or "Deny".
  8. Click "Create" to finalize the firewall rule creation.
Example: Creating a firewall rule named "allow-ssh" to allow SSH traffic from any IP address to instances in the "my-vpc" network.

Routes

Routes define the paths that network traffic takes from your instances to other destinations. Google Cloud automatically creates routes for each subnet within a VPC network.

To create a custom route:

  1. Go to the VPC network section in the Google Cloud Console.
  2. Select "Routes" from the navigation menu.
  3. Click on "Create route".
  4. Provide a name for the route.
  5. Specify the destination IP range.
  6. Define the next hop for the route.
  7. Click "Create" to finalize the route creation.
Example: Creating a route named "custom-route" to direct traffic to the IP range "192.168.1.0/24" via a specific instance.

Peering

VPC peering allows you to connect VPC networks to enable communication between resources across different VPCs. This provides a way to share resources without the need for external IP addresses or VPNs.

To create a VPC peering connection:

  1. Go to the VPC network section in the Google Cloud Console.
  2. Select "VPC network peering" from the navigation menu.
  3. Click on "Create connection".
  4. Provide a name for the peering connection.
  5. Select the VPC networks to peer.
  6. Click "Create" to finalize the peering connection.
Example: Creating a peering connection between "my-vpc" and "other-vpc".

Conclusion

Virtual Private Cloud (VPC) is a powerful feature in Google Cloud that enables you to create and manage isolated networks for your cloud resources. By understanding and utilizing VPCs, subnets, firewall rules, routes, and peering, you can build secure, scalable, and flexible network architectures that meet your specific needs.