I need to route my cloud run services using api gateway or ALB . While creating the load balancer and creating advanced host and path rules I was able to do this. But I am doubted whether I could do it more easily or efficiently using api gateways in gcp. While I tried to do it using the api gateways I got some error while accessing the internal apis with in the services, hence I am not configuring the base path while creating this api gateway I think it is not getting it. In the load balancer I am replacing the load balancer path but here there is no such things. So guys which is the best solution for this, is it load balancer or Api gateways. If it is api gateways please provide me the steps for it.
Hi @AnanduGCP,
Welcome to Google Cloud Community!
Both Google Cloud Load Balancer (ALB) and API Gateway offer powerful routing capabilities, but they serve different primary purposes and excel in different scenarios. For routing your Cloud Run services, especially when dealing with internal APIs and pathing, Google Cloud API Gateway is generally more efficient compared to an Application Load Balancer (ALB). While ALBs are excellent for broad traffic distribution and basic path rules, API Gateway is purpose-built for managing and securing APIs, which aligns well with the need to route requests to internal APIs within your services.
Given your concern about the errors encountered when accessing internal APIs, by default, API Gateway cannot directly reach Cloud Run services configured for internal ingress (--ingress=internal). You need to use a Serverless VPC Access Connector. This connector acts as a bridge, allowing API Gateway to securely communicate with your internal Cloud Run services within your Virtual Private Cloud (VPC) network using internal IP addresses.
Additionally, since you are unable to configure the base path while setting up the API Gateway, the requests are not being resolved correctly. This suggests that the API Gateway isn’t properly translating the incoming request path to the expected path on your Cloud Run service. Ensure that the “x-google-backend
” configuration in the OpenAPI spec points to the root URL of your Cloud Run service, as API Gateway appends the incoming path by default.
You can also check the following resources related to your use cases:
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.