Setting a maximum number of container instances

This page describes how to set the maximum number of container instances that can be used for your Cloud Run service. Specifying maximum instances in Cloud Run allows you to limit the scaling of your service in response to incoming requests. Use this setting as a way to control your costs or to limit the number of connections to a backing service, such as to a database.

Note that to specify a maximum number of instances greater than 1000 for Cloud Run (fully managed), you must first request a quota increase from GCP Support.

For more information on the way Cloud Run autoscales container instances, refer to Instance autoscaling.

Setting and updating maximum instances

Like any configuration change, setting a maximum number of container instances leads to the creation of a new revision. Subsequent revisions will also automatically get this maximum number of container instances unless you make explicit updates to change it.

By default, container instances can scale up to 1000 instances. You can change this default using the GCP Console or the gcloud command line when you create a new service or deploy a new revision:

Console

Not available yet

Command line

You can update the maximum number of container instances of a given service by using the following command:

gcloud beta run services update SERVICE --max-instances MAX-VALUE

Replace

  • SERVICE with the name of your service and
  • MAX-VALUE with the desired maximum number of container instances, using any integer value from 1 to 1000 or more if you requested a quota increase. Specify default to clear any maximum instance setting.

You can also set memory limits during deployment using the command:

gcloud beta run deploy --image gcr.io/PROJECT-ID/IMAGE --max-instances MAX-VALUE

Replace

  • PROJECT-ID with your GCP project ID.
  • IMAGE with the name of your image.
  • MAX-VALUE with the desired maximum number of container instances, using any integer value from 1 to 1000or more if you requested a quota increase. Specify default to clear any maximum instance setting.
Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Run Documentation