Rollbacks, gradual rollouts, and traffic migration

Cloud Run allows you to specify which revisions should receive traffic and to specify traffic percentages that are received by a revision. This feature allows you to rollback to a previous revision, gradually roll out a revision, and split traffic between multiple revisions. This page describes how to use this feature to manage traffic to your Cloud Run revisions.

Rolling back to a previous revision

To roll back to a previous revision:

Console

  1. Go to Cloud Run

  2. Locate the service in the services list, and click on it.

  3. Click the Revisions tab to show the list of current revisions for that service.

  4. In the list of revisions, click the ellipsis icon to the right of the revision you are rolling back:

    manage-traffic

  5. Click Manage Traffic to display the manage traffic form:

    1. Select the previous revision you want to roll back to in the dropdown list.
    2. Set that previous revision's traffic percentage to 100.
    3. Set the currently serving revision's percentage to 0.
    4. Click Save.

Command line

Use the following command:

gcloud alpha run services update-traffic SERVICE --to-revisions REVISION=100

  • Replace SERVICE with the name of the service.
  • Replace REVISION with the name of the revision you are rolling back to.

Gradually rolling out a revision

To roll out a new revision gradually:

Console

  1. Go to Cloud Run

  2. Locate the service in the services list, and click on it.

  3. Click Deploy New Revision.

  4. Fill out the deploy form as needed, but make sure the checkbox labelled Serve this revision immediately is UNCHECKED.

  5. Click Deploy.

  6. Click Manage Traffic.

  7. The new revision is listed but with a 0 percentage set: it is currently not serving any traffic. In the form:

    1. Set it to the desired percentage, for example, 5. Note that the currently serving version's percentage is automatically reduced by that same amount.
    2. Click Save.
    3. Repeat these Manage Traffic steps but with changed percentages, increasing the percentage as needed for the new revision. You do not need to redeploy to change the traffic percentages.

Command line

  1. Deploy the revision you want to roll out gradually, initially setting it to receive no traffic:

    gcloud alpha run deploy --image IMAGE --no-traffic

    Replace IMAGE with the image you are deploying.

  2. Specify the percentage of traffic you want the new revision to handle, for example, 5 percent:

    gcloud alpha run services update-traffic SERVICE --to-revisions REVISION=PERCENTAGE
    • Replace SERVICE with the name of the service.
    • Replace REVISION with the name of the revision you are rolling out gradually. To specify the latest revision, you can use LATEST, for example, LATEST=5.
    • Replace PERCENTAGE with the percentage of traffic you want to send to the new revision, for example, 5 to send it 5% of traffic.
  3. After the revision's performance is satisfactory, repeat the preceding update-traffic step, but increase the percentage value as desired.

Splitting traffic between multiple revisions

To split traffic between two or more revisions:

Console

  1. Go to Cloud Run

  2. Locate the service in the services list, and click on it.

  3. Click Manage Traffic.

  4. The currently serving new revision is listed. In the form:

    1. Set the currently serving revision percentage to the desired split.
    2. Select one of the previous revisions using the dropdown list and set it to the desired percentage split.
    3. To split traffic between more revisions, click Add Revision, select the desired revision, and set the percentage to the desired split.
    4. Click Save.

Command line

Specify the revisions and the percentage of traffic for each revision in a comma delimited list:

gcloud alpha run services update-traffic SERVICE --to-revisions LIST

  • Replace SERVICE with the name of the service.
  • Replace LIST with a comma delimited list of revisions and percentages:
    REVISION1=PERCENTAGE1,REVISION2=PERCENTAGE2,REVISIONn=PERCENTAGEx
    for example, hello2-00005-red=25,hello2-00001-bod=25,hello2-00002-nan=50.

Sending all traffic to the latest revision

When you deploy a new revision, you can make this revision and all future ones serve 100% of the traffic as soon as possible, overriding any established traffic split:

Console

  1. Go to Cloud Run

  2. Locate the service in the services list, and click on it.

  3. Click Deploy New Revision.

  4. Fill out the deploy form as needed, making sure you check the checkbox labelled Serve this revision immediately. This will override any existing traffic splitting, with the new revision serving 100 percent of traffic.

  5. Click Deploy.

Command line

To send all traffic to the most recently deployed revision:

gcloud alpha run services update-traffic SERVICE --to-latest

Replace SERVICE with the name of the service.