gcloud compute backend-services add-backend

NAME
gcloud compute backend-services add-backend - add a backend to a backend service
SYNOPSIS
gcloud compute backend-services add-backendBACKEND_SERVICE_NAME([--instance-group=INSTANCE_GROUP :--instance-group-region=INSTANCE_GROUP_REGION |--instance-group-zone=INSTANCE_GROUP_ZONE]    | [--network-endpoint-group=NETWORK_ENDPOINT_GROUP :--global-network-endpoint-group |--network-endpoint-group-region=NETWORK_ENDPOINT_GROUP_REGION |--network-endpoint-group-zone=NETWORK_ENDPOINT_GROUP_ZONE])[--balancing-mode=BALANCING_MODE][--capacity-scaler=CAPACITY_SCALER][--description=DESCRIPTION][--failover][--max-utilization=MAX_UTILIZATION][--preference=PREFERENCE][--custom-metrics=[CUSTOM_METRICS,…]    |--custom-metrics-file=[CUSTOM_METRICS,…]][--global    |--region=REGION][--max-connections=MAX_CONNECTIONS    |--max-connections-per-endpoint=MAX_CONNECTIONS_PER_ENDPOINT    |--max-connections-per-instance=MAX_CONNECTIONS_PER_INSTANCE    |--max-rate=MAX_RATE    |--max-rate-per-endpoint=MAX_RATE_PER_ENDPOINT    |--max-rate-per-instance=MAX_RATE_PER_INSTANCE][GCLOUD_WIDE_FLAG]
DESCRIPTION
gcloud compute backend-services add-backend adds a backend to aGoogle Cloud load balancer or Traffic Director. Depending on the load balancingscheme of the backend service, backends can be instance groups (managed orunmanaged), zonal network endpoint groups (zonal NEGs), serverless NEGs, or aninternet NEG. For more information, see thebackendservices overview.

For most load balancers, you can define how Google Cloud measures capacity byselecting a balancing mode. For more information, seetrafficdistribution.

To modify a backend, use thegcloudcompute backend-services update-backend orgcloud computebackend-services edit command.

POSITIONAL ARGUMENTS
BACKEND_SERVICE_NAME
Name of the backend service to operate on.
REQUIRED FLAGS
Exactly one of these must be specified:
Instance Group
--instance-group=INSTANCE_GROUP
Name of the instance group to add to the backend service. For details on validinstance names, refer to the criteria documented under the field 'name' at:https://cloud.google.com/compute/docs/reference/rest/v1/instances

This flag argument must be specified if any of the other arguments in this groupare specified.

At most one of these can be specified:
--instance-group-region=INSTANCE_GROUP_REGION
Region of the instance group to add to the backend service. If not specified,you might be prompted to select a region (interactive mode only).

To avoid prompting when this flag is omitted, you can set thecompute/region property:

gcloudconfigsetcompute/regionREGION

A list of regions can be fetched by running:

gcloudcomputeregionslist

To unset the property, run:

gcloudconfigunsetcompute/region

Alternatively, the region can be stored in the environment variableCLOUDSDK_COMPUTE_REGION.

--instance-group-zone=INSTANCE_GROUP_ZONE
Zone of the instance group to add to the backend service. If not specified andthecompute/zone property isn't set, youmight be prompted to select a zone (interactive mode only).

To avoid prompting when this flag is omitted, you can set thecompute/zone property:

gcloudconfigsetcompute/zoneZONE

A list of zones can be fetched by running:

gcloudcomputezoneslist

To unset the property, run:

gcloudconfigunsetcompute/zone

Alternatively, the zone can be stored in the environment variableCLOUDSDK_COMPUTE_ZONE.

Network Endpoint Group
--network-endpoint-group=NETWORK_ENDPOINT_GROUP
Name of the network endpoint group to add to the backend service.

This flag argument must be specified if any of the other arguments in this groupare specified.

At most one of these can be specified:
--global-network-endpoint-group
If set, the network endpoint group is global.
--network-endpoint-group-region=NETWORK_ENDPOINT_GROUP_REGION
Region of the network endpoint group to add to the backend service. If notspecified, you might be prompted to select a region (interactive mode only).

To avoid prompting when this flag is omitted, you can set thecompute/region property:

gcloudconfigsetcompute/regionREGION

A list of regions can be fetched by running:

gcloudcomputeregionslist

To unset the property, run:

gcloudconfigunsetcompute/region

Alternatively, the region can be stored in the environment variableCLOUDSDK_COMPUTE_REGION.

--network-endpoint-group-zone=NETWORK_ENDPOINT_GROUP_ZONE
Zone of the network endpoint group to add to the backend service. If notspecified and thecompute/zone propertyisn't set, you might be prompted to select a zone (interactive mode only).

To avoid prompting when this flag is omitted, you can set thecompute/zone property:

gcloudconfigsetcompute/zoneZONE

A list of zones can be fetched by running:

gcloudcomputezoneslist

To unset the property, run:

gcloudconfigunsetcompute/zone

Alternatively, the zone can be stored in the environment variableCLOUDSDK_COMPUTE_ZONE.

OPTIONAL FLAGS
--balancing-mode=BALANCING_MODE
Defines how to measure whether a backend can handle additional traffic or isfully loaded. For more information, seehttps://cloud.google.com/load-balancing/docs/backend-service#balancing-mode.

This cannot be used when the endpoint type of an attached network endpoint groupis INTERNET_IP_PORT, INTERNET_FQDN_PORT, or SERVERLESS.

BALANCING_MODE must be one of:

CONNECTION
Available if the backend service's load balancing scheme is eitherINTERNAL orEXTERNAL. Available if the backendservice's protocol is one ofSSL,TCP, orUDP.

Spreads load based on how many concurrent connections the backend can handle.

For backend services with --load-balancing-schemeEXTERNAL, youmust specify exactly one of these additional parameters:--max-connections,--max-connections-per-instance, or--max-connections-per-endpoint.

For backend services where--load-balancing-scheme isINTERNAL, you must omit all of these parameters.

CUSTOM_METRICS
Spreads load based on custom defined and reported metrics.
RATE
Available if the backend service's load balancing scheme isINTERNAL_MANAGED,INTERNAL_SELF_MANAGED, orEXTERNAL. Available if the backend service's protocol is one ofHTTP, HTTPS, or HTTP/2.

Spreads load based on how many HTTP requests per second (RPS) the backend canhandle.

You must specify exactly one of these additional parameters:--max-rate,--max-rate-per-instance, or--max-rate-per-endpoint.

UTILIZATION
Available if the backend service's load balancing scheme isINTERNAL_MANAGED,INTERNAL_SELF_MANAGED, orEXTERNAL. Available only for managed or unmanaged instance groupbackends.

Spreads load based on the backend utilization of instances in a backend instancegroup.

The following additional parameters may be specified:--max-utilization,--max-rate,--max-rate-per-instance,--max-connections,--max-connections-per-instance. For valid combinations, see--max-utilization.

--capacity-scaler=CAPACITY_SCALER
Scales down the target capacity (max utilization, max rate, or max connections)without changing the target capacity. For usage guidelines and examples, seeCapacityscaler.

This cannot be used when the endpoint type of an attached network endpoint groupis INTERNET_IP_PORT, INTERNET_FQDN_PORT, or SERVERLESS.

--description=DESCRIPTION
An optional, textual description for the backend.
--failover
Designates whether this is a failover backend. More than one failover backendcan be configured for a given BackendService. Not compatible with the --globalflag
--max-utilization=MAX_UTILIZATION
Defines the maximum target for average utilization of the backend instancegroup. Supported values are0.0 (0%) through1.0(100%). This is an optional parameter for theUTILIZATION balancingmode.

You can use this parameter with other parameters for defining target capacity.For usage guidelines, seeBalancingmode combinations.

--preference=PREFERENCE
This parameter specifies whether a backend should be fully utilized beforesending traffic to backends with the default preference. This parameter cannotbe used with regional managed instance groups and when the endpoint type of anattached network endpoint group is INTERNET_IP_PORT, INTERNET_FQDN_PORT, orSERVERLESS.PREFERENCE must be one of:
DEFAULT
This is the default setting. If the designated preferred backends don't haveenough capacity, backends in the default category are used. Traffic isdistributed between default backends based on the load balancing algorithm used.
PREFERRED
Backends with this preference setting are used up to their capacity limitsfirst, while optimizing overall network latency.
At most one of these can be specified:
--custom-metrics=[CUSTOM_METRICS,…]
List of custom metrics that are used for CUSTOM_METRICS balancing mode andWEIGHTED_ROUND_ROBIN locality load balancing policy.

Example:

gcloudcomputebackend-servicesadd-backend--custom-metrics='name=my-signal,maxUtilization=0.8,dryRun=true'gcloudcomputebackend-servicesadd-backend--custom-metrics='name=my-signal,maxUtilization=0.8,dryRun=true'--custom-metrics='name=my-signal2,maxUtilization=0.2'gcloudcomputebackend-servicesadd-backend--custom-metrics='[{"name" : "my-signal", "maxUtilization" : 0.8, "dryRun" : true}, {"name" : "my-signal2", "maxUtilization" : 0.1}]'

Setscustom_metrics value.

dryRun
SetsdryRun value.
maxUtilization
SetsmaxUtilization value.
name
Required, setsname value.
Shorthand Example:
--custom-metrics=dryRun=boolean,maxUtilization=float,name=string--custom-metrics=dryRun=boolean,maxUtilization=float,name=string

JSON Example:

--custom-metrics='[{"dryRun": boolean, "maxUtilization": float, "name": "string"}]'

File Example:

--custom-metrics=path_to_file.(yaml|json)
--custom-metrics-file=[CUSTOM_METRICS,…]
File path to json file with custom metrics that are used for CUSTOM_METRICSbalancing mode and WEIGHTED_ROUND_ROBIN locality load balancing policy.

Example:

gcloudcomputebackend-servicesadd-backend--custom-metrics-file='customMetric.json'

Setscustom_metrics_file value.

dryRun
SetsdryRun value.
maxUtilization
SetsmaxUtilization value.
name
Required, setsname value.
Shorthand Example:
--custom-metrics-file=dryRun=boolean,maxUtilization=float,name=string--custom-metrics-file=dryRun=boolean,maxUtilization=float,name=string

JSON Example:

--custom-metrics-file='[{"dryRun": boolean, "maxUtilization": float, "name": "string"}]'

File Example:

--custom-metrics-file=path_to_file.(yaml|json)
At most one of these can be specified:
--global
If set, the backend service is global.
--region=REGION
Region of the backend service to operate on. Overrides the defaultcompute/region property value for this command invocation.
At most one of these can be specified:
--max-connections=MAX_CONNECTIONS
Maximum concurrent connections that the backend can handle. Valid for networkendpoint group and instance group backends (except for regional managed instancegroups).

This cannot be used when the endpoint type of an attached network endpoint groupis INTERNET_IP_PORT, INTERNET_FQDN_PORT, or SERVERLESS.

--max-connections-per-endpoint=MAX_CONNECTIONS_PER_ENDPOINT
Only valid for network endpoint group backends. Defines a maximum number ofconnections per endpoint if all endpoints are healthy. When one or moreendpoints are unhealthy, an effective maximum average number of connections perhealthy endpoint is calculated by multiplyingMAX_CONNECTIONS_PER_ENDPOINT by the number of endpoints in thenetwork endpoint group, and then dividing by the number of healthy endpoints.

This cannot be used when the endpoint type of an attached network endpoint groupis INTERNET_IP_PORT, INTERNET_FQDN_PORT, or SERVERLESS.

--max-connections-per-instance=MAX_CONNECTIONS_PER_INSTANCE
Only valid for instance group backends. Defines a maximum number of concurrentconnections per instance if all instances in the instance group are healthy.When one or more instances are unhealthy, an effective average maximum number ofconnections per healthy instance is calculated by multiplyingMAX_CONNECTIONS_PER_INSTANCE by the number of instances in theinstance group, and then dividing by the number of healthy instances.
--max-rate=MAX_RATE
Maximum number of HTTP requests per second (RPS) that the backend can handle.Valid for network endpoint group and instance group backends (except forregional managed instance groups). Must not be defined if the backend is amanaged instance group using load balancing-based autoscaling.

This cannot be used when the endpoint type of an attached network endpoint groupis INTERNET_IP_PORT, INTERNET_FQDN_PORT, or SERVERLESS.

--max-rate-per-endpoint=MAX_RATE_PER_ENDPOINT
Only valid for network endpoint group backends. Defines a maximum number of HTTPrequests per second (RPS) per endpoint if all endpoints are healthy. When one ormore endpoints are unhealthy, an effective maximum rate per healthy endpoint iscalculated by multiplyingMAX_RATE_PER_ENDPOINT by the number ofendpoints in the network endpoint group, and then dividing by the number ofhealthy endpoints.

This cannot be used when the endpoint type of an attached network endpoint groupis INTERNET_IP_PORT, INTERNET_FQDN_PORT, or SERVERLESS.

--max-rate-per-instance=MAX_RATE_PER_INSTANCE
Only valid for instance group backends. Defines a maximum number of HTTPrequests per second (RPS) per instance if all instances in the instance groupare healthy. When one or more instances are unhealthy, an effective maximum RPSper healthy instance is calculated by multiplyingMAX_RATE_PER_INSTANCE by the number of instances in the instancegroup, and then dividing by the number of healthy instances. This parameter iscompatible with managed instance group backends that use autoscaling based onload balancing.
GCLOUD WIDE FLAGS
These flags are available to all commands:--access-token-file,--account,--billing-project,--configuration,--flags-file,--flatten,--format,--help,--impersonate-service-account,--log-http,--project,--quiet,--trace-token,--user-output-enabled,--verbosity.

Run$gcloud help for details.

NOTES
These variants are also available:
gcloudalphacomputebackend-servicesadd-backend
gcloudbetacomputebackend-servicesadd-backend

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-22 UTC.