
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
Create a Kubernetes cluster and deployments (Auth, Hello, and Frontend)
/ 50
Canary Deployment
/ 50
Dev Ops practices will regularly make use of multiple deployments to manage application deployment scenarios such as "Continuous deployment", "Blue-Green deployments", "Canary deployments" and more. This lab teaches you how to scale and manage containers so you can accomplish these common scenarios where multiple heterogeneous deployments are being used.
In this lab, you will learn how to perform the following tasks:
kubectl
toolyaml
filesTo maximize your learning, the following is recommended for this lab:
Heterogeneous deployments typically involve connecting two or more distinct infrastructure environments or regions to address a specific technical or operational need. Heterogeneous deployments are called "hybrid", "multi-cloud", or "public-private", depending upon the specifics of the deployment.
For this lab, heterogeneous deployments include those that span regions within a single cloud environment, multiple public cloud environments (multi-cloud), or a combination of on-premises and public cloud environments (hybrid or public-private).
Various business and technical challenges can arise in deployments that are limited to a single environment or region:
Heterogeneous deployments can help address these challenges, but they must be architected using programmatic and deterministic processes and procedures. One-off or ad-hoc deployment procedures can cause deployments or processes to be brittle and intolerant of failures. Ad-hoc processes can lose data or drop traffic. Good deployment processes must be repeatable and use proven approaches for managing provisioning, configuration, and maintenance.
Three common scenarios for heterogeneous deployment are:
The following exercises practice some common use cases for heterogeneous deployments, along with well-architected approaches using Kubernetes and other infrastructure resources to accomplish them.
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials 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 dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
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. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Set your working Google Cloud zone by running the following command, substituting the local zone as
To get started, take a look at the deployment object.
explain
command in kubectl
can tell us about the deployment object:--recursive
option:deployments/auth.yaml
configuration file:image
in the containers section of the deployment to the following:auth.yaml
file: press <Esc>
then type:<Enter>
. Now create a simple deployment. Examine the deployment configuration file:Output:
Notice how the deployment is creating one replica and it's using version 1.0.0 of the auth container.
When you run the kubectl create
command to create the auth deployment, it will make one pod that conforms to the data in the deployment manifest. This means you can scale the number of Pods by changing the number specified in the replicas
field.
kubectl create
:ReplicaSet
for the deployment. You can verify that a ReplicaSet
was created for the deployment:You should see a ReplicaSet
with a name like auth-xxxxxxx
ReplicaSet
is created:It's time to create a service for the auth deployment. You've already seen service manifest files, so the details won't be shared here.
kubectl create
command to create the auth service:hello
deployment:frontend
deployment:ConfigMap
for the frontend.And you get the hello response back.
kubectl
to use curl as a one-liner:Click Check my progress below to check your lab progress. If you successfully created Kubernetes cluster and Auth, Hello and Frontend deployments, you'll see an assessment score.
Now that you have a deployment created, you can scale it. Do this by updating the spec.replicas
field.
kubectl explain
command again:kubectl scale
command:After the deployment is updated, Kubernetes will automatically update the associated ReplicaSet
and start new Pods to make the total number of Pods equal 5.
hello
Pods running:Now you know about Kubernetes deployments and how to manage & scale a group of Pods.
Deployments support updating images to a new version through a rolling update mechanism. When a deployment is updated with a new version, it creates a new ReplicaSet
and slowly increases the number of replicas in the new ReplicaSet
as it decreases the replicas in the old ReplicaSet
.
image
in the containers section of the deployment to the following:The updated deployment will be saved to your cluster and Kubernetes will begin a rolling update.
ReplicaSet
that Kubernetes creates.:If you detect problems with a running rollout, pause it to stop the update.
The rollout is paused which means that some pods are at the new version and some pods are at the older version.
resume
command:status
command:Output:
Assume that a bug was detected in your new version. Since the new version is presumed to have problems, any users connected to the new Pods will experience those issues.
You will want to roll back to the previous version so you can investigate and then release a version that is fixed properly.
rollout
command to roll back to the previous version:Great! You learned how to do a rolling update for Kubernetes deployments and how to update applications without downtime.
When you want to test a new deployment in production with a subset of your users, use a canary deployment. Canary deployments allow you to release a change to a small subset of your users to mitigate risk associated with new releases.
A canary deployment consists of a separate deployment with your new version and a service that targets both your normal, stable deployment as well as your canary deployment.
Output:
hello
and hello-canary
. Verify it with this kubectl
command:On the hello
service, the app:hello
selector will match pods in both the prod deployment and canary deployment. However, because the canary deployment has a fewer number of pods, it will be visible to fewer users.
hello
version being served by the request:Click Check my progress below to check your lab progress. If you successfully created Canary deployment, you'll see an assessment score.
In this lab, each request sent to the Nginx service had a chance to be served by the canary deployment. But what if you wanted to ensure that a user didn't get served by the canary deployment? A use case could be that the UI for an application changed, and you don't want to confuse the user. In a case like this, you want the user to "stick" to one deployment or the other.
You can do this by creating a service with session affinity. This way the same user will always be served from the same version. In the example below, the service is the same as before, but a new sessionAffinity
field has been added, and set to ClientIP
. All clients with the same IP address will have their requests sent to the same version of the hello
application.
Due to it being difficult to set up an environment to test this, you don't need to here, but you may want to use sessionAffinity
for canary deployments in production.
Rolling updates are ideal because they allow you to deploy an application slowly with minimal overhead, minimal performance impact, and minimal downtime. There are instances where it is beneficial to modify the load balancers to point to that new version only after it has been fully deployed. In this case, blue-green deployments are the way to go.
Kubernetes achieves this by creating two separate deployments; one for the old "blue" version and one for the new "green" version. Use your existing hello
deployment for the "blue" version. The deployments will be accessed via a service which will act as the router. Once the new "green" version is up and running, you'll switch over to using that version by updating the service.
Use the existing hello service, but update it so that it has a selector app:hello
, version: 1.0.0
. The selector will match the existing "blue" deployment. But it will not match the "green" deployment because it will use a different version.
resource service/hello is missing
as this is patched automatically.In order to support a blue-green deployment style, you will create a new "green" deployment for the new version. The green deployment updates the version label and the image path.
If necessary, you can roll back to the old version in the same way.
You did it! You learned about blue-green deployments and how to deploy updates to applications that need to switch versions all at once.
You've had the opportunity to work more with the kubectl
command-line tool, and many styles of deployment configurations set up in YAML files to launch, update, and scale your deployments. With this foundation of practice you should feel comfortable applying these skills to your own DevOps practice.
DevOps Solutions and DevOps Guides in the Google Cloud documentation.
On the Kubernetes website, connect with the Kubernetes Community!
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual last updated April 2, 2024
Lab last tested August 14, 2023
Copyright 2025 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