问题
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