Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add/update the port of a backend in a Backend Service of an HTTP Load Balancer in GCP using gcloud CLI

I can create a Backen Service using the following commands:

# health check
gcloud compute http-health-checks create "$HEALTH_CHECK_NAME"                                       

# backend service
gcloud compute backend-services create "$BACKEND_SERVICE_NAME" --http-health-check "$HEALTH_CHECK_NAME" --port-name "http" --timeout "30"
gcloud compute backend-services add-backend "$BACKEND_SERVICE_NAME" --instance-group "$GROUP_NAME" --balancing-mode "UTILIZATION" --capacity-scaler "1" --max-utilization "1"

But I have to add also the port the backend will get the requests. In the GCP Console, this configuration looks like this:

enter image description here

How can I set that port (or port numbers) using the gcloud CLI?

I can not find any reference to ports in any of the help pages of the commands gcloud compute backend-services update-backend --help and gcloud compute backend-services add-backend --help

like image 923
4 revs, 2 users 76% Avatar asked Jun 27 '16 11:06

4 revs, 2 users 76%


People also ask

Which backend options are available when configuring a load balancer?

You have two backend services: external-https-backend-service for an external HTTP(S) load balancer and internal-tcp-backend-service for an internal TCP/UDP load balancer. You're using an instance group called instance-group-a in internal-tcp-backend-service .

What is backend service in load balancer?

Load balancing refers to efficiently distributing incoming network traffic across a group of backend servers, also known as a server farm or server pool.

How do I create a backend service?

​To create a backend service or snippet, aside from the code for the app's functionality that need to live on your server, you need to provide log in, configure, and manage capabilities at an external web site (if needed). Once you've created those sites and your app, follow the steps for developing an app.

How long to wait for the backend service to respond before considering it a failed request?

The default timeout for Google HTTPS Load Balancers is 30 seconds for the backend to respond before considering it a failed request. For normal HTTP GET requests, 30 seconds should be plenty of time.


1 Answers

Ports are actually supplied at the instance-group level:

# Named Ports for Instance Group
gcloud compute instance-groups managed set-named-ports "$GROUP_NAME" --named-ports "[NAME:PORT,...]" --zone "$ZONE"

In your case, your backend-service tries to look for the port with the name http. Also your desired port is 32656, thus the command would be:

gcloud compute instance-groups managed set-named-ports "$GROUP_NAME" --named-ports "http:32656" --zone "$ZONE"

You can easily choose the name of the port used by the backend-service via argument --port-name of command gcloud compute backend-services create.

See documentation: https://cloud.google.com/sdk/gcloud/reference/compute/backend-services/create

like image 115
KirbyDee Avatar answered Sep 24 '22 21:09

KirbyDee