MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Google Cloud Platform Assignment & Excercise

This page is a Google Cloud Platform (GCP) assignment: hands-on exercises for creating a project, assigning IAM roles and launching a labelled Compute Engine VM, followed by review questions on regions, resource hierarchy, IAM, labels, networking, GKE and Anthos. Below the assignment you will find the full gcloud commands for each lab, how to check your results, fixes for answers that are wrong or out of date, and the current names of products that Google has renamed.



Before you start the exercises

The exercise and solution links in the tables above are relative paths from a GitHub repository, so they do not work on this page. The labs below replace them. You can run everything in Cloud Shell, which already has gcloud installed and signed in, or on a local machine with the Google Cloud CLI installed.

  • A Google account and a Cloud Billing account. The free trial is enough, and an e2-micro VM costs very little.
  • The Google Cloud CLI. Run gcloud init once to sign in and choose defaults.
  • Permission to create projects. If your account belongs to an organization, you need the Project Creator role (roles/resourcemanager.projectCreator).
gcloud version
gcloud auth list
gcloud config listCode language: PHP (php)

Lab 1: Create a project and link billing

A project ID must be globally unique, 6 to 30 characters long, made of lowercase letters, digits and hyphens, and it must start with a letter. The display name (--name) does not need to be unique. Most APIs, including Compute Engine, will not work until the project is linked to a billing account.

export PROJECT_ID=dso-gcp-lab-$RANDOM

gcloud projects create $PROJECT_ID --name="DevOpsSchool GCP Lab"

# Find your billing account ID (format XXXXXX-XXXXXX-XXXXXX)
gcloud billing accounts list
gcloud billing projects link $PROJECT_ID --billing-account=XXXXXX-XXXXXX-XXXXXX

# Make it the default project and enable Compute Engine
gcloud config set project $PROJECT_ID
gcloud services enable compute.googleapis.com

# Verify
gcloud projects describe $PROJECT_ID --format="value(projectId,name,lifecycleState)"Code language: PHP (php)

The last command should print your project ID, its name and ACTIVE. In older versions of the CLI, the billing commands lived under gcloud beta billing. If gcloud billing is not recognised, update the CLI.

Lab 2: Assign and verify IAM roles

Roles are granted by adding a binding (a member plus a role) to a resource's allow policy. Where you can, grant a narrow predefined role instead of the basic Owner, Editor or Viewer roles.

# Grant read-only Compute Engine access to a user
gcloud projects add-iam-policy-binding $PROJECT_ID \
  --member="user:alice@example.com" \
  --role="roles/compute.viewer"

# Show which roles that user holds on the project
gcloud projects get-iam-policy $PROJECT_ID \
  --flatten="bindings[].members" \
  --filter="bindings.members:user:alice@example.com" \
  --format="table(bindings.role)"

# Revoke the role
gcloud projects remove-iam-policy-binding $PROJECT_ID \
  --member="user:alice@example.com" \
  --role="roles/compute.viewer"Code language: PHP (php)

Use the prefix that matches the kind of member: user:, group:, serviceAccount: or domain:. Granting a role to a group is easier to manage than granting it to many individual users.

Lab 3: Create a labelled instance with a startup script

This lab extends the instance question above. It adds a zone, an image, a network tag and a startup script so that the VM serves a web page you can open to check the result.

cat > startup.sh <<'EOF'
#!/bin/bash
apt-get update
apt-get install -y nginx
echo "Hello from $(hostname)" > /var/www/html/index.html
EOF

gcloud compute instances create instance-1 \
  --zone=us-central1-a \
  --machine-type=e2-micro \
  --image-family=debian-12 --image-project=debian-cloud \
  --labels=app=web,env=dev \
  --tags=http-server \
  --metadata-from-file=startup-script=startup.sh

# Firewall rule that applies only to VMs with the http-server tag
gcloud compute firewall-rules create allow-http \
  --network=default --allow=tcp:80 \
  --target-tags=http-server --source-ranges=0.0.0.0/0Code language: PHP (php)

Check labels, filter by label and test the web server:

gcloud compute instances describe instance-1 --zone=us-central1-a --format="yaml(labels)"
gcloud compute instances list --filter="labels.env=dev"
gcloud compute instances update instance-1 --zone=us-central1-a --update-labels=app=db
gcloud compute instances update instance-1 --zone=us-central1-a --remove-labels=env

IP=$(gcloud compute instances describe instance-1 --zone=us-central1-a \
  --format="value(networkInterfaces[0].accessConfigs[0].natIP)")
curl http://$IPCode language: JavaScript (javascript)

Give the startup script a minute or two to finish, then curl should return Hello from instance-1. This exercise shows the difference between the two kinds of metadata: labels (app, env) help you organise resources and report costs but change nothing about how the VM behaves, while the network tag http-server decides which firewall rule applies to it.

Note: Commands that leave out --zone either use your compute/zone default or ask you to pick a zone. Set a default with gcloud config set compute/zone us-central1-a so you do not have to repeat the flag.

Corrections to the answers above

QuestionOriginal answerCorrect answer
Project name has to be globally uniqueTrueFalse. The project ID must be globally unique and can never be reused, even after the project is deleted. The project name is only a label you choose.
Permissive parent policy overrules restrictive child policyTrueTrue for allow policies only: access is inherited and added together, so a child cannot take away a role granted higher up. However, IAM deny policies can block permissions that an allow policy grants.
A resource has to be associated with at least one projectTrueA Compute Engine VM, bucket or similar resource belongs to exactly one project. Projects do not need an organization; one is only created when you use Google Workspace or Cloud Identity.
Network tags apply only to network resourcesNetwork resourcesNetwork tags are added to VM instances and instance templates. Firewall rules and routes then refer to those tags.
Metadata key to run code at startupstartap-scriptstartup-script (or startup-script-url for a script stored in Cloud Storage). On Windows VMs, use keys such as windows-startup-script-ps1.
How do you list buckets?gsutil ls, gcloud alpha storage lsgcloud storage ls is generally available and is the recommended command. gsutil is a legacy tool.
Enabling flow logsConsole steps onlyFlow logs are enabled per subnet. With the CLI: gcloud compute networks subnets update SUBNET --region=REGION --enable-flow-logs.

Products renamed since this assignment was written

Many of the Anthos and serverless questions use product names that Google has since changed. The ideas behind them still hold, but the documentation and the console use the current names.

Name used aboveCurrent name or status
AnthosGKE Enterprise
Anthos on AWSGKE on AWS (part of GKE Multi-Cloud)
Anthos Config ManagementConfig Sync and Policy Controller
Anthos Service Mesh, Traffic DirectorCloud Service Mesh
Ingress for AnthosMulti Cluster Ingress
Cloud Run for AnthosKnative serving
Cloud FunctionsCloud Run functions
Cloud DatastoreFirestore in Datastore mode
StackdriverGoogle Cloud Observability (Cloud Logging, Cloud Monitoring, Cloud Trace)
Deployment ManagerDeprecated. Google recommends Infrastructure Manager (Terraform-based) or Terraform.

Common errors and fixes

  • The project ID you specified is already in use: project IDs are global across all customers. Pick a different ID, for example by adding a random suffix.
  • Billing account for project is not found or billing must be enabled: link a billing account as shown in Lab 1.
  • Compute Engine API has not been used in project: run gcloud services enable compute.googleapis.com and wait a minute.
  • Required 'compute.instances.create' permission: your account needs a role such as roles/compute.instanceAdmin.v1 on the project.
  • ZONE_RESOURCE_POOL_EXHAUSTED: the zone has no capacity for that machine type right now. Try another zone in the same region.
  • curl times out: check that the VM has the http-server tag, that the firewall rule exists, and that the startup script has finished. Read the serial port output with gcloud compute instances get-serial-port-output instance-1 --zone=us-central1-a.

Clean up

Delete the lab resources so you are not billed after you finish. The quickest way is to delete the whole project. It stays in a pending-deletion state for about 30 days, during which you can restore it with gcloud projects undelete.

gcloud compute instances delete instance-1 --zone=us-central1-a --quiet
gcloud compute firewall-rules delete allow-http --quiet

# Or remove everything at once
gcloud projects delete $PROJECT_IDCode language: PHP (php)

Frequently asked questions

What is the difference between a GCP project name and a project ID?

The project ID is a permanent identifier that must be unique across all of Google Cloud and is used in commands and APIs. The project name is a display label that you can change and that other projects may share.

What is the difference between labels and network tags in GCP?

Labels are key-value pairs for organising resources, filtering them and breaking down billing, and they do not change how a resource behaves. Network tags are strings attached to VMs that firewall rules and routes use to decide which instances they apply to.

How do I list all GCP regions and zones with gcloud?

Run gcloud compute regions list for regions and gcloud compute zones list for zones. Add --filter="region:us-central1" to the zones command to show only the zones in one region.

Is Anthos still available?

Its features now ship under the name GKE Enterprise, and individual components have new names, for example Cloud Service Mesh and Config Sync. The concepts in the Anthos questions above still apply.

Should I use gsutil or gcloud storage?

Use gcloud storage for new work. It is generally available and is the command Google recommends, while gsutil is a legacy tool.

Related tutorials

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

GCP vs. On-Prem for DevOps Infrastructure: A Cost and Operational Maturity Comparison

Most engineering teams donโ€™t decide to keep DevOps tooling on-premises. They inherit the decision. A CI runner gets stood up on a spare server, an artifact store…

Read More

Google Cloud Professional DevOps Engineer: Skills and Career Guide

The world of software engineering has changed. A few years ago, knowing how to write code was enough. Today, the industry demands that you also know how…

Read More

Google Cloud: API Gateway Basic Tutorials

Below is a practical, step-by-step Google Cloud API Gateway setup using a dummy backend on Cloud Run (hello service), then testing via curl. This follows Googleโ€™s official…

Read More

Master Google Cloud in Kolkata: Your Path to a Professional Certification

The digital landscape is undergoing a seismic shift, and cloud computing is at its epicenter. For IT professionals and businesses in Kolkata, embracing this change is no…

Read More

Google Cloud: Google Cloud Run Complete Tutorials

Hereโ€™s a comprehensive overview of Google Cloud Run, its features, top 10 use cases, and its advantages over other equivalent GCP services: โœ… What is Google Cloud…

Read More

Google Cloud: gcloud run commands

Hereโ€™s a comprehensive guide to all gcloud run subcommands with examples and explanations: ๐Ÿ“ฆ 1. Deploying Services gcloud run deploy Create or update a fully-managed service. ๐Ÿ› ๏ธ…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x