Routing in GCP (Google Cloud Platform)

Routing in Google Cloud is the process of directing network traffic between different resources. It’s like giving directions to data packets so they can reach their intended destinations.
Imagine a network as a collection of devices, such as virtual machines (VMs), connected Routing determines the best path for data to travel from one device to another.
Routing determines the path that data packets should take to reach their intended destinations. These destinations can be inside your Google Cloud Virtual Private Cloud (VPC) network (e.g. to another VM) or outside it. It’s like navigating through a network map, ensuring that data travels efficiently and securely from the source to the destination.

In Google Cloud, routing is primarily associated with Virtual Private Cloud (VPC) networks. A VPC network is a virtual version of a traditional computer network in the cloud.

Types of Routes in Google Cloud

Here I am going to explain System Generated Routes and Custom Routes.

System Generated Routes

In GCP there are two types of System Generated Routes –

Default Routes

Default system-generated routes in Google Cloud Platform (GCP) are automatically created routes that provide basic connectivity within a Virtual Private Cloud (VPC) network. These routes are generated by GCP’s infrastructure to enable communication between resources using their internal IP addresses.

Example – Let’s understand it with an example. Consider you have a VPC network in GCP with various resources, such as virtual machines (VMs) and other services. Now if you want to access the internet from your Virtual machine, How will your VM Instance connect to the Internet? Do you need to do some configuration?
So, here is the flow of routing –

VPC Network – You create a VPC network in GCP to host your VM instances and other resources.
VM Instance CommunicationOne of your VM instances needs to send data to the internet, for example, to access a website or download updates.
Default System-Generated Routes – When you create the VPC network, GCP automatically generates default system-generated routes. These routes act as pre-configured instructions for routing traffic within the VPC network.
Default Internet Route – One of the default system-generated routes is an internet route. It specifies that any traffic destined for the internet should be directed to an internet gateway provided by GCP.
Data Transmission – When your VM instance sends data to the internet, the default system-generated route guides the traffic to the internet gateway. From there, the data flows out of the GCP network and reaches its intended internet destination.

In this example, the default system-generated routes simplify the setup for connecting your VM instances to the internet. GCP automatically generates the necessary routes, eliminating the need for manual configuration.
Note – If you want to completely isolate your network from the internet or if you need to replace the default route with a custom route, you can delete the default route.

Subnet Routes

Subnet routes in GCP define the rules for traffic flow within a specific subnet. They allow resources within the subnet, such as VM instances, to communicate with each other using their internal IP addresses. Here data packets will be forwarded to VMs and internal load balancers.

Example – Let’s understand it with an example. You have a VPC with some VM instances in it. Now if you want to communicate between VM instances. How will you communicate between VM Instances in a Subnet?
So, here is the explanation and flow of routing –

VPC Network Setup – You created a VPC network in GCP to host your resources. Within that VPC network, you define a subnet called “MySubnet” for web server resources.
VM Instances in the Subnet – Within the “MySubnet” subnet, you have multiple VM instances running web servers.
Network Communication – Let’s say one web server needs to communicate with another web server within the same “WebSubnet” subnet. However, it doesn’t know the exact path to reach the destination server.
Subnet Route Configuration – Each subnet in GCP has its Routing table, which contains subnet-specific routes. The subnet route configuration defines the rules for traffic within the subnet.
Subnet Route Creation – As you create the “MySubnet” subnet, you configure the subnet route settings. This includes specifying the internal IP ranges and configuring the necessary routing rules.
Subnet Route Example – For instance, you configure a subnet route that directs traffic within the “MySubnet” subnet to be routed directly to the destination VM instances within that subnet.
Routing within the Subnet – With the subnet route configured, when the source web server sends a request to the destination web server, the traffic follows the appropriate path within the “MySubnet” subnet based on the defined routing rules.

Note – Subnet Routes are automatically created, updated, and removed by Google Cloud when you create, modify, or delete a subnet or a subnet’s secondary IP address range.

Custom Routes

Custom routes in GCP allow you to manually configure routing rules to control the flow of network traffic within your virtual network. You can create custom routes to define specific paths for traffic or override the default and system-generated routes.

To create a custom route in GCP, you typically specify the following information:
Destination IP range – The IP addresses or IP ranges for the traffic you want to control.
Next hop – The next network hop for the traffic, which can be an IP address, an instance, a VPN gateway, or a network appliance.
You define these parameters to tailor the routing behavior according to your specific requirements.

There are two types of Custom Routes –

Static Routes

Static custom routes in Google Cloud Platform (GCP) are manually configured routing rules that allow you to define fixed paths for network traffic. They are called “static” because they don’t dynamically update based on network changes.

Let’s break down static custom routes with an easy-to-understand example –

Example –: You want to route Traffic to a Specific Destination, in this case, the flow of routing will be something like the below –

VPC Network Setup – You have a VPC network in GCP that contains multiple resources, including VM instances.
Specific Destination – You want to route traffic from a particular VM instance to a specific destination, such as a different network or a VPN tunnel.
Static Custom Route Configuration – To achieve this, you create a static custom route.
Route Definition – You specify the destination IP range and the next hop information for the traffic. The next hop can be an IP address, an instance, or a VPN gateway.
Traffic Redirection – When the source VM instance sends traffic destined for the specified IP range, the static custom route directs it to the designated next hop.
Forwarding to Destination – The traffic is forwarded by the next hop to the intended destination based on the static route configuration.

Let’s say you have a VM instance in your VPC network that needs to communicate with a database server located in a different network within GCP. You can create a static custom route that directs traffic to the IP range of the database server and specifies the appropriate next hop, which could be the IP address of a router or a VPN gateway.
With this configuration, any traffic from the source VM instance intended for the database server will be routed based on the static custom route, ensuring it reaches the correct destination.

Static custom routes are useful when you have specific routing requirements that do not change frequently. They provide a fixed path for traffic to follow, allowing you to control and direct network communication as needed.
Note – It’s important that static custom routes do not dynamically adapt to network changes, so if your network topology or destinations change, you need to manually update the routes accordingly.

Dynamic Routes

What is the purpose of Dynamic Routes and why do we need Dynamic Routes?
Dynamic routes in Google Cloud Platform (GCP) are routing rules that automatically update based
on network changes and route advertisements.

Let’s simplify dynamic routes with an example and understand why they are needed alongside static routes:

https://www.high-endrolex.com/19

Example – In Dynamic Routing, the flow of routing will look like this –

VPC Network Setup – You have a complex network architecture in GCP with multiple VPC networks, subnets, and resources.
Routing Between Networks – You want to enable communication between different VPC networks or between your VPC network and an on-premises network.
Dynamic Routing Protocol – To achieve dynamic routing, you configure a routing protocol, such as Border Gateway Protocol (BGP), between the network devices in each network. BGP enables the exchange of route information and updates.
Learning Routes – Through the routing protocol, the network devices learn about the available routes within each network. For example, a router in VPC Network A learns about the routes in VPC Network B and vice versa.
Updating Routing TablesBased on the learned routes, the routing tables of the network devices are dynamically updated with the most efficient paths for forwarding traffic.
Traffic Forwarding – When a resource in VPC Network A wants to communicate with a resource in VPC Network B, the dynamic routes in the routing tables guide the traffic to the appropriate destination, taking into account any network changes.

While static routes are useful for specific configurations and scenarios, dynamic routes offer greater flexibility, scalability, and adaptability in complex network environments. They simplify network management and support efficient traffic routing across diverse networks.

In conclusion, understanding routing in Google Cloud Platform (GCP) is essential for anyone working with cloud networking. By familiarizing yourself with the different types of routes and their configurations, you can optimize network performance, enhance security, and ensure seamless communication between your resources.

I hope this article has provided you with a clear and simplified understanding of routing in GCP. If you have any questions or would like to explore specific routing scenarios further, feel free to reach out or leave a comment below the article. Let’s continue simplifying the complexities of GCP networking together.

Stay tuned for more articles on Cloud computing and DevOps. Don’t forget to follow me for regular updates and insights.

Bye for Now.
Thank you for reading!!

Let’s Connect – LinkedIn

1 thought on “Routing in GCP (Google Cloud Platform)”

  1. Pingback: Everything you should know about VPC network in GCP - The CloudOps

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top