Puntos de control
Create three GKE clusters
/ 10
Create the web-app repository
/ 10
Build and deploy the container images to the Artifact Registry
/ 10
Create the delivery pipeline
/ 10
Configure the deployment targets
/ 20
Create a release
/ 20
Promote the application to staging
/ 10
Promote the application to prod
/ 10
Continuous Delivery with Google Cloud Deploy
- GSP1079
- Overview
- Objectives
- Setup
- Task 1. Set variables
- Task 2. Create three GKE clusters
- Task 3. Prepare the web application container image
- Task 4. Build and deploy the container images to the Artifact Registry
- Task 5. Create the delivery pipeline
- Task 6. Configure the deployment targets
- Task 7. Create a release
- Task 8. Promote the application to staging
- Task 9. Promote the application to prod
- Congratulations!
GSP1079
Overview
Google Cloud Deploy is a managed service that automates delivery of your applications to a series of target environments in a defined promotion sequence. When you want to deploy your updated application, you create a release, whose lifecycle is managed by a delivery pipeline.
In this lab, you will create a delivery pipeline using Google Cloud Deploy. You will then create a release for a basic application and promote the application through a series of Google Kubernetes Engine (GKE) targets.
The sample application is a simple web app that listens to a port, provides an HTTP response code and adds a log entry. This lab is derived from a tutorial published by Google: https://cloud.google.com/deploy/docs/tutorials.
Objectives
In this lab, you learn how to perform the following tasks:
- Deploy a container image to Google Cloud Artifact Registry using Skaffold
- Create a Google Cloud Deploy delivery pipeline
- Create a release for the delivery pipeline
- Promote the application through the targets in the delivery pipeline
Setup
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.
How to start your lab and sign in to the Google Cloud console
-
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 the Lab Details panel with the following:
- The Open Google Cloud console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
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.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}} You can also find the Username in the Lab Details panel.
-
Click Next.
-
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}} You can also find the Password in the Lab Details panel.
-
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Google Cloud console opens in this tab.
Activate Cloud Shell
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.
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.
- (Optional) You can list the active account name with this command:
- Click Authorize.
Output:
- (Optional) You can list the project ID with this command:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Task 1. Set variables
- Declare the environment variables that will be used by various commands:
Task 2. Create three GKE clusters
In this task you will create the three GKE clusters that will be targets for the delivery pipeline.
Three GKE clusters will be created, denoting the three targets for the delivery pipeline:
- test
- staging
- prod
- Enable the Google Kubernetes Engine API:
- Create the three GKE clusters:
- Check the status of the three clusters:
Output
Creating the clusters can take a few minutes. You don't need to wait for the clusters to be ready. Continue the lab.
Click Check my progress to verify the objective.
Task 3. Prepare the web application container image
In this task you'll create a repository in Artifact Registry to hold the web application's container images.
- Enable the Artifact Registry API:
- Create the web-app repository for holding container images:
Click Check my progress to verify the objective.
Task 4. Build and deploy the container images to the Artifact Registry
In this task you will clone the git repository containing the web application and deploy the application's container images to Artifact Registry.
Prepare the application configuration
- Clone the repository for the lab into your home directory:
- Create the
skaffold.yaml
configuration:
The web directory now contains the skaffold.yaml
configuration file, which provides instructions for Skaffold to build a container image for your application. This configuration describes the following items.
The build section configures:
- The two container images that will be built (artifacts)
- The Google Cloud Build project used to build the images
The deploy
section configures the Kubernetes manifests needed in deploying the workload to a cluster.
The portForward
configuration is used to define the Kubernetes service for the deployment.
Output
Build the web application
The skaffold tool will handle submission of the codebase to Cloud Build.
- Enable the Cloud Build API:
- Run the skaffold command to build the application and deploy the container image to the Artifact Registry repository previously created:
- Once the skaffold build has completed, check for the container images in Artifact Registry:
The --format
yaml parameter returns the output as YAML for readability. The output should look like this:
Output
By default, Skaffold sets the tag for an image to its related git tag if one is available. Similar information can be found in the artifacts.json
file that was created by the skaffold command.
Skaffold generates the web/artifacts.json
file with details of the deployed images:
Output
Click Check my progress to verify the objective.
Task 5. Create the delivery pipeline
In this task you will set up the delivery pipeline.
- Enable the Google Cloud Deploy API:
- Create the delivery-pipeline resource using the
delivery-pipeline.yaml
file:
- Verify the delivery pipeline was created:
The delivery pipeline will appear similar to the following output:
Output
Notice the first three lines of the output. The delivery pipeline currently references three target environments that haven't been created yet. In the next task you will create those targets.
Click Check my progress to verify the objective.
Task 6. Configure the deployment targets
Three delivery pipeline targets will be created - one for each of the GKE clusters.
Ensure that the clusters are ready
The three GKE clusters should now be running, but it's useful to verify this.
- Run the following to get the status of the clusters:
All three clusters should be in the RUNNING state, as indicated in the output below. If they are not yet marked as RUNNING, retry the command above until their status has changed to RUNNING.
Output
Once all the clusters have the "RUNNING" status continue the lab.
Create a context for each cluster
Use the commands below to get the credentials for each cluster and create an easy-to-use kubectl
context for referencing the clusters later:
Create a namespace in each cluster
Use the commands below to create a Kubernetes namespace (web-app) in each of the three clusters:
The application will be deployed to the (web-app) namespace.
Create the delivery pipeline targets
- Submit a target definition for each of the targets:
The targets are described in a yaml file. Each target configures the relevant cluster information for the target. The test and staging target configurations are mostly the same.
- Display the details for the test Target:
Output
The prod target is slightly different as it requires approval (see the requireApproval
setting in the output) before a release can be promoted to the cluster.
- Display the details for the prod Target:
Output
- Verify the three targets (test, staging, prod) have been created:
All Google Cloud Deploy targets for the delivery pipeline have now been created.
Click Check my progress to verify the objective.
Task 7. Create a release
In this task you create a release of the application.
A Google Cloud Deploy release is a specific version of one or more container images associated with a specific delivery pipeline. Once a release is created, it can be promoted through multiple targets (the promotion sequence). Additionally, creating a release renders your application using skaffold and saves the output as a point-in-time reference that's used for the duration of that release.
Since this is the first release of your application, you'll name it web-app-001
.
- Run the following command to create the release:
The --build-artifacts
parameter references the artifacts.json
file created by skaffold earlier. The --source parameter
references the application source directory where skaffold.yaml can be found.
When a release is created, it will also be automatically rolled out to the first target in the pipeline (unless approval is required, which will be covered in a later step of this lab).
- To confirm the test target has your application deployed, run the following command:
Output
The first rollout of a release will take several minutes because Google Cloud Deploy renders the manifests for all targets when the release is created. The GKE cluster may also take a few minutes to provide the resources required by the deployment.
If you do not see state: SUCCESS
in the output from the previous command, please wait and periodically re-run the command until the rollout completes.
- Confirm your application was deployed to the test GKE cluster by running the following commands:
Output
Click Check my progress to verify the objective.
Task 8. Promote the application to staging
In this task you will promote the application from test and into the staging target.
- Promote the application to the staging target:
You will be prompted to continue before the promotion commences.
- Press ENTER to accept the default (Y = yes).
- To confirm the staging Target has your application deployed, run the following command:
Review the output
Look for the section marked targetId: staging
. As before, if you do not see state: SUCCEEDED
in the output from the previous command, wait and periodically re-run the command until the rollout completes.
Output
Click Check my progress to verify the objective.
Task 9. Promote the application to prod
In this task you will again promote the application but will also provide approval.
- Promote the application to the prod target:
You will be prompted to continue before the promotion commences.
- Press ENTER to accept the default (Y = yes).
- To review the status of the prod target, run the following command:
In the output, note that the approvalState
is NEEDS_APPROVAL
and the state is PENDING_APPROVAL
.
Output
- Approve the rollout with the following:
You will be prompted to approve the rollout before the promotion commences.
- Press ENTER to accept the default (Y = yes).
- To confirm the prod target has your application deployed, run the following command:
As for previous rollouts, locate the entry for the target (targetId: prod
) and check that the rollout has completed (state: SUCCEEDED
). Periodically re-run the command until the rollout completes.
- Use
kubectl
to check on the status of the deployed application:
Click Check my progress to verify the objective.
Congratulations!
Congratulations! In this lab, you learned how to create a delivery pipeline using Google Cloud Deploy. You created a release for a basic application and promoted the application through a series of Google Kubernetes Engine (GKE) targets. You first deployed the application to the test target, then promoted it to the staging target, and finally to the prod target. Now you can use Cloud Deploy to create continuous delivery pipelines!
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 5, 2024
Lab Last Tested July 12, 2023
Copyright 2024 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.