0
0
GCPcloud~30 mins

URL maps for routing in GCP - Mini Project: Build & Apply

Choose your learning style9 modes available
URL Maps for Routing in GCP
📖 Scenario: You are setting up a simple web application on Google Cloud Platform (GCP). You want to route incoming web traffic to different backend services based on the URL path. For example, requests to /app1 should go to one backend, and requests to /app2 should go to another.
🎯 Goal: Create a URL map configuration that routes traffic to two backend services based on URL paths /app1/* and /app2/*. This URL map will be used by a load balancer to direct traffic correctly.
📋 What You'll Learn
Create a URL map resource named my-url-map.
Define a path matcher with rules for /app1/* and /app2/*.
Route /app1/* traffic to backend service backend-service-app1.
Route /app2/* traffic to backend service backend-service-app2.
Set a default backend service backend-service-default for all other traffic.
💡 Why This Matters
🌍 Real World
URL maps are used in GCP load balancers to route web traffic to different backend services based on URL paths or hostnames. This helps organize and scale web applications.
💼 Career
Understanding URL maps is essential for cloud engineers and architects managing traffic routing and load balancing in GCP environments.
Progress0 / 4 steps
1
Create the basic URL map structure
Create a YAML file named url-map.yaml with a resource of kind compute.v1.urlMap and name it my-url-map. Include an empty pathMatchers list and a defaultService field set to backend-service-default.
GCP
Need a hint?

Start by defining the URL map resource with the required name and default backend service.

2
Add path matcher for /app1/*
Add a path matcher to the pathMatchers list with name main-matcher. Set defaultService to backend-service-default and add a pathRules entry that matches /app1/* and routes to backend-service-app1.
GCP
Need a hint?

Define a path matcher with the correct name, default service backend-service-default, and a path rule for /app1/* to backend-service-app1.

3
Add path rule for /app2/*
Add another pathRules entry to the main-matcher that matches /app2/* and routes to backend-service-app2.
GCP
Need a hint?

Add a second path rule for /app2/* to the pathRules list in main-matcher.

4
Set host rules to use path matcher
Add a hostRules section to the URL map spec. Create one host rule with hosts set to ['*'] and pathMatcher set to main-matcher. This will route all hosts to the path matcher.
GCP
Need a hint?

Host rules connect hosts to path matchers. Use wildcard host '*' to route all traffic to main-matcher.