Rollbacks, gradual rollouts, and traffic migration Stay organized with collections Save and categorize content based on your preferences.
Cloud Run lets you specify which revisions should receive trafficand to specify traffic percentages that are received by a revision. Thisfeature lets you rollback to a previous revision, gradually deploy arevision, and split traffic betweenmultiple revisions. This page describes how to use this feature to managetraffic to your Cloud Run revisions.
Note that traffic routing adjustments are not instantaneous. When you change traffic forrevisions, all requests being processed will continue to completion. In flightrequests won't be dropped and may be directed to either a new revision or a previousrevision during the transition period.
Traffic splitting and session affinity
If you are splitting traffic between multiple revisions withsession affinity enabled, seeSession affinity and traffic splittingfor details on the effect of session affinity on traffic splitting.
Lifecycle of traffic splits
If you split traffic between multiple revisions or assigned traffic to a previous revision,all subsequent deployments use that traffic split pattern going forward. To return tojust using the latest revision without traffic splitting,send all traffic to the latest revision.
Required roles
To get the permissions that you need to manage Cloud Run services andrevisions, ask your administrator to grant you the following IAMroles:
- If you are managing a service that was deployed from a container image:
- Cloud Run Developer(
roles/run.developer) on the Cloud Run service - Service Account User(
roles/iam.serviceAccountUser) on the service identity - Artifact Registry Reader(
roles/artifactregistry.reader) on the Artifact Registry repository of thecontainer images of the service (if applicable)
- Cloud Run Developer(
- If you are managing a service that was deployed from source code:
- Cloud Run Source Developer(
roles/run.sourceDeveloper) on your project - Service Usage Consumer(
roles/serviceusage.serviceUsageConsumer) on your project - Service Account User(
roles/iam.serviceAccountUser) on the service identity - Additionally, grant theCloud Run Builder(
roles/run.builder) role to the Cloud Build service account on theproject. The build service account is responsible for building your service,and defaults to the Compute Engine default service account.
- Cloud Run Source Developer(
For a list of IAM roles and permissions that are associated withCloud Run, seeCloud Run IAM rolesandCloud Run IAM permissions.If your Cloud Run service interfaces withGoogle Cloud APIs, such as Cloud Client Libraries, see theservice identity configuration guide.For more information about granting roles, seedeployment permissionsandmanage access.
Roll back to a previous revision
To roll back to a previous revision:
Console
In the Google Cloud console, go to the Cloud RunServices page:
Locate the service in the services list, and click it.
Click theRevisions tab to show the list of current revisions for thatservice.
In the list of revisions, click the ellipsis icon to the right of therevision you are rolling back:

ClickManage Traffic to display the manage traffic form:
- Select the previous revision you want to roll back to in the drop-downlist.
- Set that previous revision's traffic percentage to 100.
- Set the currently serving revision's percentage to 0.
- ClickSave.
gcloud
Use the following command:
gcloudrunservicesupdate-trafficSERVICE--to-revisionsREVISION=100
- ReplaceSERVICE with the name of the service.
- ReplaceREVISION with the name of the revision you are rolling back to.
YAML
If you are creating a new service, skip this step.If you are updating an existing service, download itsYAML configuration:
gcloudrunservicesdescribeSERVICE--formatexport>service.yamlBelow the
specattribute, locate and update thetrafficattribute tothe following:apiVersion:serving.knative.dev/v1kind:Servicemetadata:name:SERVICEspec:...traffic:-revisionName:REVISIONpercent:100Replace
- REVISION with the name of the revision you are rolling back to.
Replace the service with its new configuration using the following command:
gcloudrunservicesreplaceservice.yaml
Wait for the update to complete: you should see a message that therevision you are rolling backfrom has been deployed and is serving
0percent of traffic.
Terraform
To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.
Add the following to agoogle_cloud_run_v2_service resource in your Terraform configuration:resource"google_cloud_run_v2_service""default"{name="my-service"location="us-central1"deletion_protection=false # set to true to prevent destruction of the resourcetemplate{}traffic{percent=100 # This revision needs to already existrevision="green"type="TRAFFIC_TARGET_ALLOCATION_TYPE_REVISION"}}Error creating Service: googleapi: Error 400: spec.template.spec: Revision template was empty.Gradual roll out for revisions
To roll out a new revision gradually:
Console
In the Google Cloud console, go to the Cloud RunServices page:
Select a service in the services list.
ClickDeploy New Revision.
Fill out the deploy form as needed, but make sure the checkbox labelledServe this revision immediately is UNCHECKED.
ClickDeploy.
ClickManage Traffic.
The new revision is listed but with a 0 percentage set: it is currentlynot serving any traffic. In the form:
- Set it to the desired percentage, forexample, 5. Note that the currently serving version's percentage isautomatically reduced by that same amount.
- ClickSave.
- Repeat theseManage Traffic steps but with changed percentages,increasing the percentage as needed for the new revision. You do notneed to redeploy to change the traffic percentages.
gcloud
To deploy a service from a container image:
Deploy the revision you want to roll out gradually, initially settingit to receive no traffic:
To deploy a service from source code:
gcloudrundeploy--imageIMAGE--no-traffic
ReplaceIMAGE with the image you are deploying.
To deploy a service from source code:
gcloudrundeploySERVICE--source.--no-traffic
ReplaceSERVICE with the name of your service.
Specify the percentage of traffic you want the new revision to handle,for example, 5 percent:
gcloudrunservicesupdate-trafficSERVICE--to-revisionsREVISION=PERCENTAGE
- ReplaceSERVICE with the name of the service.
- ReplaceREVISION with the name of the revision you arerolling out gradually. To specify the latest revision, you can use
LATEST, for example,LATEST=5. - ReplacePERCENTAGE with the percentage of traffic you wantto send to the new revision, for example,
5to send it 5% of traffic.
After the revision's performance is satisfactory, repeat the preceding
update-trafficstep, but increase the percentage value as desired.
YAML
If you are creating a new service, skip this step.If you are updating an existing service, download itsYAML configuration:
gcloudrunservicesdescribeSERVICE--formatexport>service.yamlMake any desired configuration changes to the service, and specify therevision name you want for the new revision:
apiVersion:serving.knative.dev/v1kind:Servicemetadata:name:SERVICEspec:template:metadata:annotations:...name:REVISION-NAMEReplace
- REVISION-NAME with the name you want the new revision tohave.
Below the
specattribute, locateand update thetrafficattribute so that the new revision serves only asmall amount of traffic:apiVersion:serving.knative.dev/v1kind:Servicemetadata:name:SERVICEspec:...traffic:-revisionName:REVISION-NEWpercent:PERCENT-NEW-revisionName:REVISION-FORMERpercent:PERCENT-FORMERNote that the percentages must add up to 100. Replace
- REVISION-NEW with the name of the revision you are rolling outgradually.
- REVISION-FORMER with the name of the currently serving revision.
- PERCENT-NEW with the traffic percentage you want to send to the new revision,for example use
10to send 10% of the traffic to that revision. - PERCENT-FORMER with the traffic percentage you want to send to the old revision
Wait for the update to complete: you should see a message that thenew revision you are gradually rolling out has been deployed and is servingthe traffic percentage value you used.
Terraform
Add the following to your.tf file and gradually update the traffic percentage from previous revision to thelatest revision.Keep in mind that every traffic change will require anotherterraform apply to be executed.
resource"google_cloud_run_v2_service""default"{name="my-service"location="us-central1"deletion_protection=false # set to true to prevent destruction of the resourcetemplate{containers{ # Image or image tag must be different from previous revisionimage="us-docker.pkg.dev/cloudrun/container/hello"}} # Define the traffic split for each revision # https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_v2_service#traffictraffic{percent=100 # This revision needs to already existrevision="green"type="TRAFFIC_TARGET_ALLOCATION_TYPE_REVISION"}traffic{ # Deploy new revision with 0% trafficpercent=0type="TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST"}}Apply the changes by enteringterraform apply.
Split traffic between multiple revisions
To split traffic between two or more revisions:
Console
In the Google Cloud console, go to the Cloud RunServices page:
Locate the service in the services list, and click on it.
ClickManage Traffic.
The currently serving new revision is listed. In the form:
- Set the currently serving revision percentage to the desired split.
- Select one of the previous revisions using the dropdown list and setit to the desired percentage split.
- To split traffic between more revisions, clickAdd Revision,select the desired revision, and set the percentage to the desired split.
- ClickSave.
gcloud
Specify the revisions and the percentage of traffic for each revision in acomma delimited list:
gcloudrunservicesupdate-trafficSERVICE--to-revisionsLIST
- ReplaceSERVICE with the name of the service.
- ReplaceLIST with a comma delimited list of revisions andpercentages:
REVISION1=PERCENTAGE1,REVISION2=PERCENTAGE2,REVISIONn=PERCENTAGEx
for example,hello2-00005-red=25,hello2-00001-bod=25,hello2-00002-nan=50.
YAML
If you are creating a new service, skip this step.If you are updating an existing service, download itsYAML configuration:
gcloudrunservicesdescribeSERVICE--formatexport>service.yamlBelow the
specattribute, locateand update thetrafficattribute so that the new revision serves only asmall amount of traffic:apiVersion:serving.knative.dev/v1kind:Servicemetadata:name:SERVICEspec:...traffic:-revisionName:REVISION-Apercent:PERCENT-A-revisionName:REVISION-Bpercent:PERCENT-B-revisionName:REVISION-Cpercent:PERCENT-CNote that percentages must add up to 100. Replace
- REVISION-A,REVISION-B,REVISION-Cwith the revisions you are allotting traffic to.
- PERCENT-A,PERCENT-B,PERCENT-C withthe percentage for the corresponding revision.
Replace the service with its new configuration using the following command:
gcloudrunservicesreplaceservice.yaml
Wait for the update to complete: you should see a message that thenew revision you are gradually rolling out has been deployed and is serving
5percent (or whatever gradual value you used) of traffic.
Terraform
Add the following to your.tf file:
resource"google_cloud_run_v2_service""default"{name="my-service"location="us-central1"deletion_protection=false # set to true to prevent destruction of the resourcetemplate{containers{image="us-docker.pkg.dev/cloudrun/container/hello"}revision="green"} # Define the traffic split for each revision # https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_v2_service#traffictraffic{percent=25revision="green"type="TRAFFIC_TARGET_ALLOCATION_TYPE_REVISION"}traffic{percent=75 # This revision needs to already existrevision="blue"type="TRAFFIC_TARGET_ALLOCATION_TYPE_REVISION"}}Apply the changes by enteringterraform apply.
Send all traffic to the latest revision
When you deploy a new revision, you can make this revision and all future onesserve 100% of the traffic as soon as possible, overriding any establishedtraffic split:
Console
In the Google Cloud console, go to the Cloud RunServices page:
Locate the service in the services list, and click it.
ClickDeploy New Revision.
Fill out the deploy form as needed, making sure you check thecheckbox labelledServe this revision immediately. This will override anyexisting traffic splitting, with the new revision serving 100 percent oftraffic.
ClickDeploy.
gcloud
To send all traffic to the most recently deployed revision:
gcloudrunservicesupdate-trafficSERVICE--to-latest
ReplaceSERVICE with the name of the service.
YAML
If you are creating a new service, skip this step.If you are updating an existing service, download itsYAML configuration:
gcloudrunservicesdescribeSERVICE--formatexport>service.yamlBelow the
specattribute, locateand update thetrafficattribute to the followingapiVersion:serving.knative.dev/v1kind:Servicemetadata:name:SERVICEspec:...traffic:-latestRevision:truepercent:100Replace the service with its new configuration using the following command:
gcloudrunservicesreplaceservice.yaml
Wait for the update to complete: you should see a message that the(latest) revision is deployed and is serving
100percent of traffic.
Terraform
Add the following to your.tf file:
resource"google_cloud_run_v2_service""default"{name="my-service"location="us-central1"deletion_protection=false # set to true to prevent destruction of the resourcetemplate{}traffic{percent=100type="TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST"}}Apply the changes by enteringterraform apply.
Use tags for testing, traffic migration and rollbacks
Important: If you have minimum instances configured at theservice-level,traffic tags do not allocate minimum instances for tagged revisions.If you have minimum instances configured at therevision-level,traffic tags allocate minimum instances for tagged revisions.To avoid incurring billing costs for tagged revisions, useservice-levelminimum instances orremove tags on revisions when you don't need them anymore.
A common use case for this feature is to use it for testing and vetting of anew service revision before it serves any traffic, in this typical sequence:
- Run integration tests on a container during development.
- Deploy the container to a Google Cloud project that you use only forstaging, serving no traffic, and test against a tagged revision.
- Deploy it to production, without serving traffic, and testagainst a tagged revision in production.
- Migrate traffic to the tagged revision.
Deploy a new tagged revision
To deploy a new revision of an existing service to production:
gcloud
Note: If you are using the gcloud CLI to deploying from source, make sure to have therequired roles granted to you and to use--source instead of--image, and add--function if deploying a function.gcloudrundeploymyservice--imageIMAGE_URL--no-traffic--tagTAG_NAME
Replace:
- IMAGE_URL with the URL for your image.
- TAG_NAME with your lowercase tag name.
The tag lets you directly test the new revision at a specific URL, withoutserving traffic. The URL starts with the tag name you provided: for exampleif you used the tag namegreen on the servicemyservice, you wouldtest the tagged revision at the URLhttps://green---myservice-abcdef.a.run.app
YAML
If you are creating a new service, skip this step.If you are updating an existing service, download itsYAML configuration:
gcloudrunservicesdescribeSERVICE--formatexport>service.yamlBelow the
trafficattribute, locate and update thetagattributethat corresponds to the revision that you want to add a tag to:apiVersion:serving.knative.dev/v1kind:Servicemetadata:name:SERVICEspec:...traffic:-revisionName:REVISIONpercent:100-revisionName:REVISION-Atag:TAG-A-revisionName:REVISION-Btag:TAG-B-revisionName:REVISION-Ctag:TAG-CReplace:
- TAG-A,TAG-B,TAG-C with the tagassociated to each revision.
- REVISION with the name of an existing revision that youwant to send all of the traffic to.
Create or update the service using the following command:
gcloudrunservicesreplaceservice.yaml
Terraform
Add the following to your.tf file and gradually update the traffic percentage from old revision to the newest revision with the newtag.Keep in mind that every traffic change will require anotherterraform apply to be executed.
resource"google_cloud_run_v2_service""default"{name="my-service"location="us-central1"deletion_protection=false # set to "true" in productiontemplate{containers{ # image or tag must be different from previous revisionimage="us-docker.pkg.dev/cloudrun/container/hello"}revision="blue"} # Define the traffic split for each revision # https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_v2_service#traffictraffic{percent=100 # This revision needs to already existrevision="green"type="TRAFFIC_TARGET_ALLOCATION_TYPE_REVISION"}traffic{ # Deploy new revision with 0% trafficpercent=0revision="blue"tag="tag-name"type="TRAFFIC_TARGET_ALLOCATION_TYPE_REVISION"}}Apply the changes by enteringterraform apply.
Remove a tag
To remove a tag from a revision:
Console
In the Google Cloud console, go to the Cloud RunServices page:
Select a service in the services list.
Navigate to theRevisions section within your desired service and select the revision for which you would like to remove the existing tag.
Hold the pointer over theRevision URLs (tags) column and click the pencil icon:

In theRevision URLs dialog menu, click theBin icon to remove the current tag used in your revision.
ClickSave.
gcloud
To remove a revision tag:
gcloudrunservicesupdate-trafficSERVICE--remove-tagsTAG_NAME
Replace
- TAG_NAME with the name of the tag you are migrating traffic to
- SERVICE with the name of the service you are removing the tag from
YAML
If you are creating a new service, skip this step.If you are updating an existing service, download itsYAML configuration:
gcloudrunservicesdescribeSERVICE--formatexport>service.yamlMake any desired configuration changes to the service.
Below the
specattribute, locateand remove thetagattribute for the tagged revision:apiVersion:serving.knative.dev/v1kind:Servicemetadata:name:SERVICEspec:...traffic:-revisionName:REVISIONtag:TAG_NAMEpercent:PERCENT-NEWReplace the service with its new configuration using the following command:
gcloudrunservicesreplaceservice.yaml
Terraform
Add the following to your.tf file:
resource"google_cloud_run_v2_service""default"{name="my-service"location="us-central1"deletion_protection=false # set to true to prevent destruction of the resourcetemplate{} # Define the traffic split for each revision # https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_v2_service#traffictraffic{percent=100 # This revision needs to already existrevision="green"type="TRAFFIC_TARGET_ALLOCATION_TYPE_REVISION"}traffic{ # No tags for this revision # Keep revision at 0% trafficpercent=0 # This revision needs to already existrevision="blue"type="TRAFFIC_TARGET_ALLOCATION_TYPE_REVISION"}}Apply the changes by enteringterraform apply.
Error creating Service: googleapi: Error 400: spec.template.spec: Revision template was empty.Migrating traffic to a tagged revision
After confirming that the new revision works properly, you can start migratingtraffic to it using the Google Cloud console, the gcloudcommand line, Terraform, or a YAML file:
Console
In the Google Cloud console, go to the Cloud RunServices page:
Locate the service in the services list, and click it:
Select the tagged revision you want to send traffic to:

ClickManage Traffic.
Locate the tagged revision name: it is listed but with a 0 percentage set:it is currently not serving any traffic. In theManage traffic* form:
- Set it to the desired percentage, forexample, 5. Note that the currently serving version's percentage isautomatically reduced by that same amount.
- ClickSave.
- Over a period of hours or days, as needed, repeat theseManage Traffic steps but with changed percentages,increasing the percentage as needed for the tagged revision. You do notneed to redeploy to change the traffic percentages.
gcloud
To migrate traffic to a specific revision tag:
gcloudrunservicesupdate-trafficmyservice--to-tagsTAG_NAME=TRAFFIC_PERCENT
Replace
- TAG_NAME with the name of the tag you are migrating traffic to
- TRAFFIC_PERCENT with the percentage of traffic you want tothe tagged revision to serve, for example,
1.
YAML
If you are creating a new service, skip this step.If you are updating an existing service, download itsYAML configuration:
gcloudrunservicesdescribeSERVICE--formatexport>service.yamlMake any chosen configuration changes to the service.
Below the
specattribute, locateand update thetrafficattribute for the tagged revision so that the taggedrevision serves only a small amount of traffic:apiVersion:serving.knative.dev/v1kind:Servicemetadata:name:SERVICEspec:...traffic:-revisionName:REVISIONtag:TAG_NAMEpercent:PERCENT-NEW-revisionName:REVISION-FORMERpercent:PERCENT-FORMERNote that the percentages must add up to 100. Replace
- REVISION with the name of the tagged revision.
- TAG_NAME with the name of the tag you are rolling outgradually.
- PERCENT-NEW with the traffic percentage you want to send tothe tagged revision, for example use
10to send 10% of the traffic to that revision. - REVISION-FORMER with the name of the currently serving revision.
- PERCENT-FORMER with the traffic percentage you want to send to the old revision
Replace the service with its new configuration using the following command:
gcloudrunservicesreplaceservice.yaml
Wait for the update to complete: you should see a message that thenew revision you are gradually rolling out has been deployed and is servingthe traffic percentage value you used.
Terraform
Add the following to your.tf file:
resource"google_cloud_run_v2_service""default"{name="my-service"location="us-central1"deletion_protection=false # set to true to prevent destruction of the resourcetemplate{} # Define the traffic split for each revision # https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_v2_service#traffictraffic{ # Update revision to 50% trafficpercent=50 # This revision needs to already existrevision="green"type="TRAFFIC_TARGET_ALLOCATION_TYPE_REVISION"}traffic{ # Update tag to 50% trafficpercent=50 # This tag needs to already existtag="tag-name"}}Over a period of hours or days, as needed, gradually update from one tag to the other, increasing the percentage as needed for the tagged revision.
Apply by enteringterraform apply after every change.
Error creating Service: googleapi: Error 400: spec.template.spec: Revision template was empty.What's next
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 2026-02-18 UTC.