
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
In this lab, you learn to:
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.
In this lab you will learn how to use Cloud Run features. The lab features three high level sections that resolve a technical problem:
These labs are based on intermediate knowledge of Google Cloud. While the steps required are covered in the content, it would be helpful to have familiarity with any of the following products:
This Qwiklabs hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is a panel populated with the temporary credentials that you must use for this lab.
Copy the username, and then click Open Google Console. The lab spins up resources, and then opens another tab that shows the Choose an account page.
On the Choose an account page, click Use Another Account. The Sign in page opens.
Paste the username that you copied from the Connection Details panel. Then copy and paste the password.
After a few moments, the Cloud console opens in this tab.
Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.
Google Cloud Shell provides command-line access to your Google Cloud resources.
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Example output:
Output:
Example output:
In this lab, you will help the development team at Critter Junction investigate Cloud Run revisions. The team would like to explore how revision management can be incorporated into their existing development workflow.
The operations team at Critter Junction would like to create a status page for their services without introducing additional complexity to their existing systems. Experimentation with Serverless products has led them to select Cloud Run due to the wealth of features supported.
The operations team at Critter Junction are keen to define a solution that can be implemented quickly. After discussions with the engineering team, they discovered that serverless may be a good option. To move forward, a series of meetings are held with stakeholders to ascertain the key priorities. The results of which are shown below:
Ref |
User Story |
1 |
As a product lead, I want to ensure the website remains responsive, so customers face minimal wait times. |
2 |
As a developer lead, I want to increase the velocity of service deployments. |
3 |
As an ops lead, I want to ensure system stability is observed, so the system performance is not degraded through the deployment of new revisions. |
The team leads follow up the meetings and agree the following high level tasks would indicate the project requirements have been met:
Ref |
Definition of Done |
1 |
User base are not impacted by the rollout of new features |
2 |
Revision management enabled for service deployments |
3 |
New revision retains existing level of operational stability by deployment to a reduced user base |
In consideration of the requirements, the development team decide to look in to the following:
Feature |
Description |
|
Revision Tags |
"Appropriate for use cases where a task producer needs to defer or control the execution timing of a specific webhook or remote procedure call." |
|
Traffic Migration |
"Cloud Run allows you to specify which revisions should receive traffic and to specify traffic percentages that are received by a revision.." |
|
The following high level architecture diagram summaries the minimal viable product they wish to investigate.
In the proposed solution, the product service is used to demonstrate how traffic migration and revision tagging can be used with Cloud Run.
Critter Junction has a backend product status service that they would like integrated with Cloud Run. To build an MVP the following activities are required:
Cloud Run requires some environmental settings. In this section, enable the API and deploy the service.
Before deploying the application, config the environment.
Cloud Run requires knowledge of the region in which it will be deployed. In addition the Cloud Run service should be enabled to allow API access.
The development team needs to configure the product status service. To test the process, the development team decided to look at the deployment patterns for Cloud Run.
An example series of container images has been created by the development team. Use these images to configure and deploy within the project:
Example output:
Example output:
Note: Traffic management
The Cloud Run service has been successfully deployed and is responding to requests. In the next section explore how to utilise Traffic Migration to specify which revision receives traffic.
Each new Cloud Run revision can be assigned a tag. Doing this allows access to a URL without serving traffic. An approach like this can be useful to handle the traffic profile across multiple revisions.
The main uses cases for revision tags are shown in the following table:
Use Case |
Description |
Integration testing |
Run containers revisions during the development phase |
Tagged revision migration |
Migrate traffic to a tagged revision |
Tagged revision rollback |
Rollback to prior version based on tagged revision |
In this section deploy a new revision and learn how to control the traffic to direct to the correct destination.
Cloud Run provides the ability to deploy a new revision with redirecting traffic. A deployment of this kind is useful for integration testing of components.
test2
) with redirection of traffic:Observe the name of the Tagged Revision
in the command output.
Create an environment variable for the new URL:
Example output:
The new revision can be used to independently test the deployment. At this point the original revision is still serving 100% of the traffic.
There are now two versions available. However only one revision is serving traffic. Alter the deployed revisions to share the traffic profile.
test2
:Observe the name of the Tagged Revision
in the command output.
Confirm the original test
endpoint is distributing traffic:
Example output:
At this point observe the traffic pattern is distributed between the original (TEST1) and new revision (TEST2).
In the event an issue is found, the traffic migration can be rolled back by resetting the percentage.
test1
service:Observe the name of the Tagged Revision
in the command output.
Test the endpoint is distributing traffic to TEST1
only:
Example output:
In this section a second Cloud Run revision was deployed and used to migrate traffic.
The second revision was labelled with the tag test2
and used to migrate a percentage of the traffic determined at deployment.
Migration of traffic provides a simple mechanism on which to direct communication to a deployed service. Cloud Run provides the ability to have multiple revisions to be deployed without a cost penalty. Remember Cloud Run only charges where traffic is handled by the service.
The main uses cases for traffic migration are shown in the following table:
Use Case |
Description |
Traffic migration |
Enable traffic to be sent to the latest version of the deployed service |
Traffic splitting |
Perform a ratio traffic split between defined deployed services |
Rollout migration |
Deploy a service and gradually enable traffic at a predetermined time |
In this section multiple revisions will be deployed. Learn how to split traffic to a specific host.
When splitting traffic between two or more revisions, a comma separated list can be used. The list represents the revisions deployed.
test3
) with redirection of traffic:test4
) with redirection of traffic:revisionNames
:LIST
environment variable:Observe the name of the Tagged Revision
in the command output.
Test the endpoint is distributing traffic:
Example output:
In this section a Cloud Run deployment was performed. Traffic was then diverted to the new deployment.
Observe the name of the Tagged Revision
in the command output.
Create an environment variable for the new URL:
Example output:
Critter Junction have now updated their solution to take advantage of Cloud Run traffic management.
Over this course of this lab, you have seen how to incorporate Cloud Run traffic management within your Google Cloud infrastructure.
Follow the Serverless Expeditions video series to learn more about how to utilise these products within your project.
Manual Last Updated: February 21, 2024
Lab Last Tested: February 21, 2024
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one