Search code examples
google-cloud-platformload-balancing

Google Cloud load balancer routing roles not working


enter image description here

I have two backend services(X backend service and Y backend service) for which I have configured a load balancer and created some routing rules as can be seen in the photo. My goal:

  • Access dev.somedomain.io -> redirects to X backend service
  • Access dev.somedomain.io/shopify -> redirects to Y backend service
  • Access dev.somedomain.io/api -> redirects to X backend service

Actual result:

  • When I try to load: dev.somedomain.io everything seems to work fine and I get can see swagger as in dev.somedomain.io/swagger/index.html.
  • When I try to load: dev.somedomain.io/api I get a 404 and nothing loads.
  • When I try to load: dev.somedomain.io/shopify I get a 404 and nothing loads.

From what I can see only the last route seems to get matched (the one with /* as a path). Not sure what am I missing here.


Solution

  • So it turns out I needed to specify the action and url rewrite for the above routes to work. But since there is no option to specify those from the UI I needed to select the advanced route configuration and need to provide it as YAML as the following:

    defaultService: projects/some-project/global/backendServices/x-api-dev-backend-service
    name: path-matcher-1
    pathRules:
    - paths:
      - /shopify/*
      service: projects/some-project/global/backendServices/y-dev-backend-service
      routeAction:
        urlRewrite:
          pathPrefixRewrite: /
    - paths:
      - /api/*
      service: projects/some-project/global/backendServices/x-dev-backend-service
      routeAction:
        urlRewrite:
          pathPrefixRewrite: /