This page describes how to set the maximum number of instances that can be used for your Cloud Run service using the default Cloud Run autoscaling behavior. To manually scale your service, see Manual scaling.
Specifying maximum instances in Cloud Run lets you limit the scaling of your service in response to incoming requests, although this maximum setting can be exceeded for a brief period due to circumstances such as traffic spikes.
You can 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.
For information about the maximum instance limits that might apply to your service, refer to Maximum instances limits.
For more information on the way Cloud Run autoscales container instances, refer to Instance autoscaling.
Apply maximum instances at service-level versus revision-levelPreview — Service-level maximum instances for Cloud Run services
This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the Service Specific Terms. Pre-GA features are available "as is" and might have limited support. For more information, see the launch stage descriptions.
You can configure maximum instances at the service level or at the revision level. Google recommends that you use service-level maximum instances unless you have a specific need to limit instances at the revision level.
When applying maximum instances, the settings go into effect as follows:
Tagged revisions are started, but only count toward the service-level maximum instances if they are a part of a traffic split.
Required rolesTo get the permissions that you need to configure and deploy Cloud Run services, ask your administrator to grant you the following IAM roles:
roles/run.developer
) on the Cloud Run serviceroles/iam.serviceAccountUser
) on the service identityFor a list of IAM roles and permissions that are associated with Cloud Run, see Cloud Run IAM roles and Cloud Run IAM permissions. If your Cloud Run service interfaces with Google Cloud APIs, such as Cloud Client Libraries, see the service identity configuration guide. For more information about granting roles, see deployment permissions and manage access.
Configure service-level maximum instances Note: Disable service-level maximum instances by setting the value to0
(Preview).
You can change the maximum instances setting using the Google Cloud console, the Google Cloud CLI, or a YAML file when you create a new service or deploy a new revision.
ConsoleIn the Google Cloud console, go to Cloud Run:
If you are configuring a new service, select Services and click Deploy container to display the Create service form. Locate the Service scaling form.
If you are configuring an existing service, click the service to display its detail panel, then click the edit Edit service level scaling settings at the top right of the detail panel.
In the field labelled Maximum number of instances, specify the required maximum number of container instances, using any integer value from 1
to the maximum limit possible for your service.
Click Create for a new service or Deploy for an existing service.
gcloud run deploy
, and have the required roles granted to you.
You can update the maximum number of instances of a given service by using the following command:
gcloud beta run services update SERVICE --max MAX-VALUE
Replace the following:
1
to the maximum limit possible for your service.You can also set the maximum number of instances during deployment using the command:
gcloud beta run deploy --image IMAGE_URL --max MAX-VALUE
Replace the following:
us-docker.pkg.dev/cloudrun/container/hello:latest
. If you use Artifact Registry, the repository REPO_NAME must already be created. The URL follows the format of LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG
.1
to the maximum limit.Any configuration change leads to the creation of a new revision. Subsequent revisions will also automatically get this configuration setting unless you make explicit updates to change it.
If you are creating a new service, skip this step. If you are updating an existing service, download its YAML configuration:
gcloud run services describe SERVICE --format export > service.yaml
Update the run.googleapis.com/maxScale:
attribute:
apiVersion: serving.knative.dev/v1 kind: Service metadata: name: SERVICE annotations: run.googleapis.com/launch-stage: BETA run.googleapis.com/maxScale: 'MAX-INSTANCE'
Replace the following:
1
to the maximum limit possible for your service.Create or update the service using the following command:
gcloud run services replace service.yaml
To view the current service-level maximum instances settings for your Cloud Run service:
ConsoleIn the Google Cloud console, go to Cloud Run:
Click that service to open its Service details panel.
View the current setting in the upper right of the service details panel, next to Scaling.
Use the following command:
gcloud run services describe SERVICE
Locate the value for Scaling: Auto (Min: MIN_VALUE, Max: MAX_VALUE) in the returned configuration.
Any configuration change leads to the creation of a new revision. Subsequent revisions will also automatically get this configuration setting unless you make explicit updates to change it.
By default, Cloud Run revisions are configured to scale up to a maximum of 100 instances.
You can change the maximum instances setting using the Google Cloud console, the Google Cloud CLI, or a YAML file when you create a new service or deploy a new revision.
ConsoleIn the Google Cloud console, go to Cloud Run:
Find and click the service you want to update in the services list to open that service's details.
Click Edit and deploy new revision to display the revision deployment form.
Click the Container tab.
Locate the Revision scaling section. In the field labelled Maximum number of instances, specify the maximum number of container instances.
Click Deploy.
gcloud run deploy
, and have the required roles granted to you.
You can update the maximum number of instances of a given service by using the following command:
gcloud beta run services update SERVICE --max-instances MAX-VALUE
Replace the following:
1
to the maximum limit.If you are creating a new service, skip this step. If you are updating an existing service, download its YAML configuration:
gcloud run services describe SERVICE --format export > service.yaml
Update the autoscaling.knative.dev/maxScale:
attribute:
apiVersion: serving.knative.dev/v1 kind: Service metadata: name: SERVICE annotations: run.googleapis.com/launch-stage: BETA spec: template: metadata: annotations: autoscaling.knative.dev/maxScale: 'MAX-INSTANCE' name: REVISION
Replace the following:
1
to the maximum limit.SERVICE-
-
-
Create or update the service using the following command:
gcloud run services replace service.yaml
To view the current revision-level maximum instances settings for your Cloud Run service:
ConsoleIn the Google Cloud console, go to Cloud Run:
Click that service to open its Service details panel.
Click the Revisions tab.
In the details panel at the right, view the Revision max. instances setting listed under the Container tab.
Use the following command:
gcloud run services describe SERVICE
Locate the value for Max instances: in the returned configuration.
The following table shows the behavior if you combine service-level maximum instances with revision-level minimum or maximum instances:
Service-level setting Revision-level setting Behavior Service-level maximum instances set Revision-level maximum instances set Effective maximum instance limit is the lesser value between revision-level maximum instances and service-level maximum instances. Service-level maximum instances set Revision-level minimum instances set If service-level maximum instances is set to a value lower than revision-level minimum instances, then the revision starts instances up to the service-level maximum instances, and won't reach the configured revision-level minimum instances. Use service-level maximum instances with traffic splittingIf you use traffic splitting, the service-level maximum instances are distributed across the revisions based on the proportion of the traffic split. For example, if the service-level maximum instances = 100, a 50/50 traffic split allocates 50 service-level maximum instances to each revision. The following table shows a sample configuration scenario:
Sample configuration Resulting behavior Service-level maximum instances set (scenario where there are no revision-level settings): 100No available container instances
error, even if the service as a whole, hasn't reached the service-level maximum instances limit.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4