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

风流意气都作罢 提交于 2019-12-10 16:42:38

问题


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:

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


回答1:


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



来源:https://stackoverflow.com/questions/38052318/how-to-add-update-the-port-of-a-backend-in-a-backend-service-of-an-http-load-bal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!