Application LoadBalancer in GCP

110 views Asked by At

In GCP, I am running three NodeJS APIs in a single instance with three different port numbers (3000, 3001, and 3002), and I created an external application load balancer using the HTTPS front end. I also created a backend service for the three port numbers. The load balancer is attached to the instance group.

If I am requesting the URL "https://example.com/" reaching port 3000 This is working well for me for the single-backend service. but I need to pass this same URL, "https://example.com/" with different HTTP headers and values. For example, if I request the URL "https://example.com/" port 3000 needs to be reached, but if I request the same URL "https://example.com/" with the "mydealsapi" HTTP headers, port 3001 needs to be reached, and again, if I request the same URL "https://example.com/" with the "appapi" HTTP headers, port 3002 needs to be reached.

2

There are 2 answers

1
Patrick Bentley On

You need to use forwarding rules in Google Cloud. It depends on if you have a global or regional load balancer what you have available. But you can create forwarding rules that route traffic to a specific port.

Here are the docs for more info: https://cloud.google.com/load-balancing/docs/forwarding-rule-concepts#external_fr

You can create forwarding rules through the GC console or you can create them using the gcloud cli using the

gcloud compute forwarding-rules create

Depending on the load blancer type, you can use ths "--ports==" flag.

Here is a doc for that: https://cloud.google.com/sdk/gcloud/reference/compute/forwarding-rules/create

Note: Port specification requirements vary depending on the load-balancing scheme and target. For more information, refer to https://cloud.google.com/load-balancing/docs/forwarding-rule-concepts#port_specifications.

0
Yvan G. On

Posting Mr. @JohnHanley comment as answer. I agree with the link provided. Just to elaborate on this concern the link is composed on how you can add custom HTTP headers, validating the URL and updating URL map.

Since backend service is not indicated from the post, let me also share this link wherein various backend types are supported.