Checkpoints
Create the lab resources
/ 25
Create the repository in Cloud Source Repositories
/ 15
Create the Cloud Build Triggers
/ 20
Deploy the first versions of the application
/ 20
Deploy the second versions of the application
/ 10
Roll back the production deployment
/ 10
Implement DevOps in Google Cloud: Challenge Lab
GSP330
Overview
In a challenge lab you’re given a scenario and a set of tasks. Instead of following step-by-step instructions, you will use the skills learned from the labs in the quest to figure out how to complete the tasks on your own! An automated scoring system (shown on this page) will provide feedback on whether you have completed your tasks correctly.
When you take a challenge lab, you will not be taught new Google Cloud concepts. You are expected to extend your learned skills, like changing default values and reading and researching error messages to fix your own mistakes.
To score 100% you must successfully complete all tasks within the time period!
This lab is recommended for students enrolled in the Implement DevOps in Google Cloud Quest. Are you ready for the challenge?
Before you click the Start Lab button
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 will be made available to you.
This 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:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
Challenge scenario
As a recent hire as a DevOps Engineer for Cymbal Superstore a few months ago, you have learned the ins and outs of how the company operates its e-commerce website. Specifically, the DevOps team is working on a large scale CI/CD pipeline that they would like your assistance with building. This will allow the company to help developers automate tasks, collaborate more effectively with other teams, and release software more frequently and reliably. Your experience with Cloud Source Repositories, Artifact Registry, Docker, and Cloud Build is going to be a large help since Cymbal Superstore would like to use all native Google Cloud Services for their pipeline.
Before you start this project, the DevOps team would like you to demonstrate your new skills. As part of this demonstration, they have a list of tasks they would like to see you do in an allotted period of time in a sandbox environment.
Your challenge
Your tasks will include the following:
- Creating a GKE cluster based on a set of configurations provided.
- Creating a Google Source Repository to host your Go application code.
- Creating Cloud Build Triggers that deploy a production and development application.
- Pushing updates to the app and creating new builds.
- Rolling back the production application to a previous version.
Overall, you will be creating a simple CI/CD pipeline using Cloud Source Repositories, Artifact Registry, and Cloud Build.
Task 1. Create the lab resources
In this section, you will initialize your Google Cloud project for the demo environment. You will enable the required APIs, configure Git in Cloud Shell, create an Artifact Registry Docker repository, and create a GKE cluster to run your production and development applications on.
- Run the following command to enable the APIs for GKE, Cloud Build, and Cloud Source Repositories:
- Add the Kubernetes Developer role for the Cloud Build service account:
- Run the following to configure Git in Cloud Shell, replacing
<email>
with your generated lab email address and<name>
with your name.
-
Create an Artifact Registry Docker repository named my-repository in the
us-central1
region to store your container images. -
Create a GKE cluster named
hello-cluster
with the following configuration:
Setting | Value |
---|---|
Zone | us-central1-a |
Release channel | Regular |
Cluster version |
1.25.5-gke.2000 or newer
|
Cluster autoscaler | Enabled |
Number of nodes | 3 |
Minimum nodes | 2 |
Maximum nodes | 6 |
- Create the
prod
anddev
namespaces on your cluster.
Click Check my progress to verify the objective.
Task 2. Create a repository in Cloud Source Repositories
In this task, you will create a repository sample-app in Cloud Source Repositories and will initialize it with some sample code. This repository will hold your Go application code, and be the primary source for triggering builds.
-
Create an empty repository named sample-app in Cloud Source Repositories.
-
Clone the sample-app Cloud Source Repository in Cloud Shell.
-
Use the following command to copy the sample code into your
sample-app
directory:
-
Make your first commit with the sample code added to your
sample-app
directory, and push the changes to the master branch. -
Create a branch named dev. Make a commit with the sample code added to your
sample-app
directory and push the changes to the dev branch. -
Verify you have the sample code and branches stored in the Source Repository.
The code you just cloned contains a simple Go application that has two entry points: Red and Blue. Each will display a simple colored square on the web page depending on the entry point you go to.
Click Check my progress to verify the objective.
Task 3. Create the Cloud Build Triggers
In this section you will create two Cloud Build Triggers. The first trigger listens for changes on the master
branch and builds a Docker image of your application, pushes it to Google Artifact Registry, and deploys the latest version of the image to the prod namespace in your GKE cluster. The second trigger will listen for changes on the dev
branch and build a Docker image of your application and push it to Google Artifact Registry, and deploy the latest version of the image to the dev namespace in your GKE cluster.
-
Create a Cloud Build Trigger named sample-app-prod-deploy that with the following configurations:
- Event: Push to a branch
- Source Repository:
sample-app
- Branch:
^master$
- Cloud Build Configuration File:
cloudbuild.yaml
-
Create a Cloud Build Trigger named sample-app-dev-deploy that with the following configurations:
- Event: Push to a branch
- Source Repository:
sample-app
- Branch:
^dev$
- Cloud Build Configuration File:
cloudbuild-dev.yaml
After setting up the triggers, any changes to the branches will trigger the corresponding Cloud Build pipeline, which will build and deploy the application as specified in the cloudbuild.yaml
files.
Click Check my progress to verify the objective.
Task 4. Deploy the first versions of the application
In this section, you will build the first version of the production application and the development application.
Build the first development deployment
-
In Cloud Shell, inspect the
cloudbuild-dev.yaml
file to see the steps in the build process. Fill in the<version>
on lines 10 and 15 withv1.0
. -
Navigate to the
dev/deployment.yaml
file and fill in the<todo>
on line 17 with the correct container image name.
-
Make a commit with your changes on the
dev
branch and push changes to trigger the sample-app-dev-deploy build job. -
Verify your build executed successfully, and verify the development-deployment application was deployed onto the
dev
namespace of the cluster. -
Expose the development-deployment deployment to a LoadBalancer service named
dev-deployment-service
on port 8080, and set the target port of the container to the one specified in the Dockerfile. -
Navigate to the Load Balancer IP of the service and add the
/blue
entry point at the end of the URL to verify the application is up and running. It should resemble something like the following:http://34.135.97.199:8080/blue
.
Build the first production deployment
-
Inspect the
cloudbuild.yaml
file to see the steps in the build process. Fill in the<version>
on lines 10 and 15 withv1.0
. -
Navigate to the
prod/deployment.yaml
file and fill in the<todo>
on line 17 with the correct container image name.
-
Make a commit with your changes on the
master
branch and push changes to trigger the sample-app-prod-deploy build job. -
Verify your build executed successfully, and verify the production-deployment application was deployed onto the
prod
namespace of the cluster. -
Expose the production-deployment deployment on the
prod
namespace to a LoadBalancer service namedprod-deployment-service
on port 8080, and set the target port of the container to the one specified in the Dockerfile. -
Navigate to the Load Balancer IP of the service and add the
/blue
entry point at the end of the URL to verify the application is up and running. It should resemble something like the following:http://34.135.245.19:8080/blue
.
Click Check my progress to verify the objective.
Task 5. Deploy the second versions of the application
In this section, you will build the second version of the production application and the development application.
Build the second development deployment
-
Switch back to the dev branch.
-
In the
main.go
file, update themain()
function to the following:
- Add the following function inside of the
main.go
file:
-
Inspect the
cloudbuild-dev.yaml
file to see the steps in the build process. Update the version of the Docker image tov2.0
. -
Navigate to the
dev/deployment.yaml
file and update the container image name to the new version (v2.0
). -
Make a commit with your changes on the
dev
branch and push changes to trigger the sample-app-dev-deploy build job. -
Verify your build executed successfully, and verify the development-deployment application was deployed onto the
dev
namespace of the cluster and is using thev2.0
image. -
Navigate to the Load Balancer IP of the service and add the
/red
entry point at the end of the URL to verify the application is up and running. It should resemble something like the following:http://34.135.97.199:8080/red
.
Build the second production deployment
-
Switch to the master branch.
-
In the
main.go
file, update themain()
function to the following:
- Add the following function inside of the
main.go
file:
-
Inspect the
cloudbuild.yaml
file to see the steps in the build process. Update the version of the Docker image tov2.0
. -
Navigate to the
prod/deployment.yaml
file and update the container image name to the new version (v2.0
). -
Make a commit with your changes on the
master
branch and push changes to trigger the sample-app-prod-deploy build job. -
Verify your build executed successfully, and verify the production-deployment application was deployed onto the
prod
namespace of the cluster and is using thev2.0
image. -
Navigate to the Load Balancer IP of the service and add the
/red
entry point at the end of the URL to verify the application is up and running. It should resemble something like the following:http://34.135.245.19:8080/red
.
Great! You have successfully created fully functioning production and development CI/CD pipelines.
Click Check my progress to verify the objective.
Task 6. Roll back the production deployment
In this section, you will roll back the production deployment to a previous version.
- Roll back the production-deployment to use the
v1.0
version of the application.
Click Check my progress to verify the objective.
Congratulations!
Congratulations! In this lab you verified your skills on implementing DevOps workflow in Google Cloud. You first created a GKE cluster to run your application and a git repository to host your code base. You then created Cloud Build Triggers, modified the code and the templates, and pushed updates to the repo that created your first development and production application builds. You then pushed updates to the application to create new builds, and rolled back the production application to a previous version. You are now ready to start DevOps work in your own environment!
Earn your next skill badge
This self-paced lab is part of the Implement DevOps in Google Cloud skill badge quest. Completing this skill badge quest earns you the badge above, to recognize your achievement. Share your badge on your resume and social platforms, and announce your accomplishment using #GoogleCloudBadge.
This skill badge is part of Google Cloud’s Cloud Devops Engineer learning path. Continue your learning journey by enrolling in the Monitor and Log with Google Cloud Operations Suite quest.
Google Cloud training and certification
...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 February 16, 2023
Lab Last Tested February 28, 2023
Copyright 2023 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.