0
0
GCPcloud~10 mins

URL maps for routing in GCP - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - URL maps for routing
Client sends HTTP request
Load Balancer receives request
URL Map checks request URL
Match path rule 1
Route to backend 1
Backend serves response
Response sent to client
The URL map receives the request URL from the load balancer and matches it against defined path rules to route traffic to the correct backend service.
Execution Sample
GCP
urlMap:
  defaultService: backendServiceA
  hostRules:
  - hosts: ["example.com"]
    pathMatcher: pathMatcher1
  pathMatchers:
  - name: pathMatcher1
    defaultService: backendServiceA
    pathRules:
    - paths: ["/images/*"]
      service: backendServiceImages
    - paths: ["/videos/*"]
      service: backendServiceVideos
This URL map routes requests for example.com. Requests to /images/* go to backendServiceImages, /videos/* to backendServiceVideos, and all others to backendServiceA.
Process Table
StepRequest URLMatched HostMatched Path RuleRouted Backend ServiceAction
1http://example.com/images/cat.pngexample.com/images/*backendServiceImagesRoute to images backend
2http://example.com/videos/movie.mp4example.com/videos/*backendServiceVideosRoute to videos backend
3http://example.com/aboutexample.comdefaultbackendServiceARoute to default backend
4http://other.com/homeno matchno matchdefaultService (backendServiceA)Route to default backend because host not matched
💡 Routing completes after matching host and path rules or falls back to default service.
Status Tracker
VariableStartAfter 1After 2After 3After 4
Request URLnonehttp://example.com/images/cat.pnghttp://example.com/videos/movie.mp4http://example.com/abouthttp://other.com/home
Matched Hostnoneexample.comexample.comexample.comno match
Matched Path Rulenone/images/*/videos/*defaultno match
Routed Backend ServicenonebackendServiceImagesbackendServiceVideosbackendServiceAbackendServiceA
Key Moments - 2 Insights
What happens if the request host does not match any host rule?
If the host does not match any host rule (see step 4 in execution_table), the URL map routes the request to the defaultService backend.
How does the URL map decide which backend to route to when multiple path rules exist?
The URL map checks path rules in order and routes to the backend of the first matching path pattern (see steps 1 and 2). If none match, it uses the defaultService.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, which backend service handles the request to 'http://example.com/videos/movie.mp4'?
AbackendServiceA
BbackendServiceImages
CbackendServiceVideos
DNo backend matched
💡 Hint
Check row 2 under 'Routed Backend Service' in execution_table.
At which step does the URL map route to the default backend because no path rule matched?
AStep 3
BStep 1
CStep 2
DStep 4
💡 Hint
Look at the 'Matched Path Rule' column for 'default' in execution_table.
If the host 'other.com' was added to hostRules with a pathMatcher, how would step 4 change?
ARequest would be rejected
BMatched Host would be 'other.com' and routing would follow path rules
CMatched Host remains 'no match' and routes to defaultService
DRouting would fail with error
💡 Hint
Refer to variable_tracker for 'Matched Host' changes and execution_table step 4.
Concept Snapshot
URL maps route incoming requests based on host and path.
Define hostRules to match domains.
Use pathMatchers with pathRules to route paths.
Requests not matching any rule go to defaultService.
This controls traffic flow in GCP load balancing.
Full Transcript
URL maps in GCP load balancing receive client requests and check the URL's host and path. First, the load balancer passes the request to the URL map. The URL map looks for a host rule matching the request's domain. If found, it uses the associated path matcher to check path rules. If a path matches, the request routes to the specified backend service. If no path matches, it routes to the default backend service. If no host matches, the request also routes to the default backend. This process ensures requests go to the right backend based on URL patterns.