Loading...
No results found.
Get access to 700+ labs and courses

Google Cloud Fundamentals: Getting Started with Deployment Manager and Cloud Monitoring

Lab 45 minutes universal_currency_alt 5 Credits show_chart Introductory
info This lab may incorporate AI tools to support your learning.
Get access to 700+ labs and courses

Overview

In this lab, you create a deployment using Deployment Manager and use it to maintain a consistent state of your deployment. You will also view resource usage in a VM instance using Cloud Monitoring.

Objectives

In this lab, you will learn how to perform the following tasks:

  • Create a Deployment Manager deployment.
  • Update a Deployment Manager deployment.
  • View the load on a VM instance using Cloud Monitoring.

Task 1. Sign in to the Google Cloud Platform (GCP) Console

For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.

  1. Sign in to Qwiklabs using an incognito window.

  2. Note the lab's access time (for example, 1:15:00), and make sure you can finish within that time.
    There is no pause feature. You can restart if needed, but you have to start at the beginning.

  3. When ready, click Start lab.

  4. Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.

  5. Click Open Google Console.

  6. Click Use another account and copy/paste credentials for this lab into the prompts.
    If you use other credentials, you'll receive errors or incur charges.

  7. Accept the terms and skip the recovery resource page.

Task 2. Confirm that needed APIs are enabled

  1. Make a note of the name of your GCP project. This value is shown in the top bar of the Google Cloud Platform Console. It will be of the form qwiklabs-gcp- followed by hexadecimal numbers.

  2. In the GCP Console, on the Navigation menu (Navigation menu icon), click APIs & services.

  3. Scroll down in the list of enabled APIs, and confirm that these APIs are enabled:

  • Cloud Deployment Manager v2 API
  • Cloud Runtime Configuration API
  • Stackdriver monitoring API
  1. If one or more APIs is missing, click the Enable APIs and Services button at top. Search for the above APIs by name and enable each for your current project. (You noted the name of your GCP project above.)

Task 3. Create a Deployment Manager deployment

  1. In GCP console, on the top right toolbar, click the Activate Cloud Shell button (Activate Cloud Shell icon). Click Continue.

  2. For your convenience, place the zone that Qwiklabs assigned you to into an environment variable called MY_ZONE. At the Cloud Shell prompt, type this partial command:

export MY_ZONE=

followed by the zone that Qwiklabs assigned you to. Your complete command will look similar to this:

export MY_ZONE={{{project_0.default_zone|Zone}}}
  1. At the Cloud Shell prompt, download an editable Deployment Manager template:
gsutil cp gs://cloud-training/gcpfcoreinfra/mydeploy.yaml mydeploy.yaml
  1. In the Cloud Shell, use the sed command to replace the PROJECT_ID placeholder string with your Google Cloud Platform project ID using this command:
sed -i -e "s/PROJECT_ID/$DEVSHELL_PROJECT_ID/" mydeploy.yaml
  1. In the Cloud Shell, use the sed command to replace the ZONE placeholder string with your Google Cloud Platform zone using this command:
sed -i -e "s/ZONE/$MY_ZONE/" mydeploy.yaml
  1. In the Cloud Shell, use the sed command to replace the n1-standard-1 machine type to e2-medium using this command:
sed -i -e "s/n1-standard-1/e2-medium/" mydeploy.yaml
  1. View the mydeploy.yaml file, with your modifications, with this command:
cat mydeploy.yaml

The file will look something like this:

resources: - name: my-vm type: compute.v1.instance properties: zone: {{{project_0.default_zone|Zone}}} machineType: zones/{{{project_0.default_zone|Zone}}}/machineTypes/e2-medium metadata: items: - key: startup-script value: "apt-get update" disks: - deviceName: boot type: PERSISTENT boot: true autoDelete: true initializeParams: sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-9-stretch-v20180806 networkInterfaces: - network: https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-dcdf854d278b50cd/global/networks/default accessConfigs: - name: External NAT type: ONE_TO_ONE_NAT Note: Do not use the above text literally in your own mydeploy.yaml file. Be sure that the zone that is named on the zone: and machineType: lines in your file matches the zone to which Google Cloud Skills Boost assigned you. Be sure that the GCP project ID on the network: line in your file matches the project ID to which Google Cloud Skills Boost assigned you, not the one in this example.
  1. Build a deployment from the template:
gcloud deployment-manager deployments create my-first-depl --config mydeploy.yaml

When the deployment operation is complete, the gcloud command displays a list of the resources named in the template and their current state.

  1. Confirm that the deployment was successful. In the GCP Console, on the Navigation menu (Navigation menu icon), click Compute Engine > VM instances. You will see that a VM instance called my-vm has been created, as specified by the template.

  2. Click on the VM instance's name to open its VM instance details screen.

  3. Scroll down to the Custom metadata section. Confirm that the startup script you specified in your Deployment Manager template has been installed.

Click Check my progress to verify the objective. Create a Deployment Manager deployment

Task 4. Update a Deployment Manager deployment

  1. Return to your Cloud Shell prompt. Launch the nano text editor to edit the mydeploy.yaml file:
nano mydeploy.yaml
  1. Find the line that sets the value of the startup script, value: "apt-get update", and edit it so that it looks like this:
value: "apt-get update; apt-get install nginx-light -y"

Do not disturb the spaces at the beginning of the line. The YAML templating language relies on indented lines as part of its syntax. As you edit the file, be sure that the v in the word value in this new line is immediately below the k in the word key on the line above it.

  1. Press Ctrl+O and then press Enter to save your edited file.

  2. Press Ctrl+X to exit the nano text editor.

  3. Return to your Cloud Shell prompt. Enter this command to cause Deployment Manager to update your deployment to install the new startup script:

gcloud deployment-manager deployments update my-first-depl --config mydeploy.yaml

Wait for the gcloud command to display a message confirming that the update operation was completed successfully.

  1. In the GCP console, on the Navigation menu (Navigation menu icon), click Compute Engine > VM instances.

  2. Click on the my-vm VM instance's name to open its VM instance details pane.

  3. Scroll down to the Custom metadata section. Confirm that the startup script has been updated to the value you declared in your Deployment Manager template.

Click Check my progress to verify the objective. Update the Deployment Manager deployment

Task 5. View the Load on a VM using Cloud Monitoring

  1. In the GCP Console, on the Navigation menu (Navigation menu icon), click Compute Engine > VM instances.

  2. Select the checkbox for my-vm and click on STOP.

  3. Click on STOP again to confirm.

  4. Click on the VM instance's name to open its VM instance details screen.

  5. Click on EDIT (pencil icon).

  6. Scroll down to the bottom of the page and select Compute Engine default service account from Service account dropdown.

  7. Select Allow full access to all Cloud APIs for Access scopes.

  8. Click on Save.

  9. Now, restart the VM by clicking on Start at the top of the VM instance details screen page.

  10. Click on START again to confirm.

  11. In the GCP Console, on the Navigation menu (Navigation menu icon), click Compute Engine > VM instances.

  12. To open a command prompt on the my-vm instance, click SSH in its row in the VM instances list.

  13. In the ssh session on my-vm, execute this command to create a CPU load:

dd if=/dev/urandom | gzip -9 >> /dev/null &

This Linux pipeline forces the CPU to work on compressing a continuous stream of random data.

Note: Leave the window containing your SSH session open while you proceed with the lab.

Create a Monitoring workspace

You will now setup a Monitoring workspace that's tied to your Google Cloud Project. The following steps create a new account that has a free trial of Monitoring.

  1. In the Cloud Console, click on Navigation menu > Monitoring.

  2. Wait for your workspace to be provisioned.

When the Monitoring dashboard opens, your workspace is ready.

The Monitoring dashboard open on the Overview page

  1. Click on Settings option from the left panel and confirm that the GCP project created for you is shown under the GCP Projects section.

project list

  1. Run the commands shown on screen in the SSH window of your VM instance to install both the Monitoring and Logging agents.
curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh sudo bash install-monitoring-agent.sh curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh sudo bash install-logging-agent.sh
  1. Once both of the agents have been installed on your project's VM, click Metrics Explorer under the main Cloud Monitoring menu on the far left.

  2. In the Metrics Explorer pane, Click on Select a Metric dropdown under Resource & Metric and then select VM instance > Instance > CPU usage.

  3. Click Apply.

In the resulting graph, notice that CPU usage increased sharply a few minutes ago.

  1. Terminate your workload generator. Return to your ssh session on my-vm and enter this command:
kill %1

End your lab

When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.

You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.

The number of stars indicates the following:

  • 1 star = Very dissatisfied
  • 2 stars = Dissatisfied
  • 3 stars = Neutral
  • 4 stars = Satisfied
  • 5 stars = Very satisfied

You can close the dialog box if you don't want to provide feedback.

For feedback, suggestions, or corrections, please use the Support tab.

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.

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

Use private browsing

  1. Copy the provided Username and Password for the lab
  2. Click Open console in private mode

Sign in to the Console

  1. Sign in using your lab credentials. Using other credentials might cause errors or incur charges.
  2. Accept the terms, and skip the recovery resource page
  3. Don't click End lab unless you've finished the lab or want to restart it, as it will clear your work and remove the project

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

Use private browsing to run the lab

Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.