I have two Cloud Run services - one named "ui" and one named "api". I'd like my serverless NEG to direct requests to the "ui" service unless they have "/api" in their path, in which case they should go to the "api" Cloud Run service. Does the url mask feature of serverless NEGs allow for me to set a default service like this? Or should I look into a different way of doing this?
Like John Hanley
said, you can use the URL masking feature of Serverless NEGs for this purpose.
URL Masking: A serverless NEG backend can point to either a single Cloud Run service, or a URL mask that points to multiple services. A URL mask is a template of your URL schema. The serverless NEG uses this template to map the request to the appropriate service. (Source: Google docs)
You can use a combination of URL masks and load balancer for mapping the requests in your case, the path validations can be handled by the load balancer. The below diagram shows how a request is forwarded to your cloud run instance.
In your case there will be two Cloud Run instances under the same serverless NEG using the rules mentioned in the URL map backend will route your requests.
In the URL map you should write the path matcher rules which specify to route traffic to your /api path and UI separately. In the UI rule write a condition stating that route traffic only if it contains /api.
Note: The image and a part of content is taken from the official google docs.