GCP Practice
Exercises
Exercise 1: Compute Engine VM
- Create a Compute Engine VM using
gcloud compute instances create
- SSH into the VM:
gcloud compute ssh my-vm --zone=us-central1-a
- Install nginx on the VM
- Open port 80 in the firewall:
gcloud compute firewall-rules create allow-http --allow=tcp:80
- Visit the VM’s external IP in a browser
- Clean up: delete the VM and firewall rule
Reference: https://cloud.google.com/compute/docs/instances/create-start-instance
Exercise 2: GKE Autopilot Cluster
- Create a GKE Autopilot cluster in
us-central1
- Configure
kubectl to use the new cluster
- Deploy the Google sample app:
kubectl create deployment hello-app --image=us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0
- Expose it with a LoadBalancer service
- Access the app via the external IP
- Scale the deployment to 3 replicas
- Clean up: delete the cluster
Reference: https://cloud.google.com/kubernetes-engine/docs/quickstarts/autopilot
Exercise 3: Cloud Run Deployment
- Create a simple Dockerfile for a “Hello World” HTTP server
- Build and push it to Artifact Registry
- Deploy to Cloud Run with
--allow-unauthenticated
- Test the URL that Cloud Run provides
- Update the service with a new image revision
- Split traffic 50/50 between two revisions
Reference: https://cloud.google.com/run/docs/quickstarts/build-and-deploy
Exercise 4: Cloud Build CI/CD Pipeline
- Fork a sample application repository
- Create a
cloudbuild.yaml that:
- Builds a Docker image
- Runs tests
- Pushes to Artifact Registry
- Deploys to Cloud Run
- Connect Cloud Build to your repository
- Trigger a build by pushing a commit
- Observe the build logs in Cloud Console
Reference: https://cloud.google.com/build/docs/quickstart-build
- Create a Terraform configuration that provisions:
- A VPC network with a subnet
- A GCS bucket
- A Compute Engine VM in the VPC
- Store Terraform state in a GCS backend
- Run
tofu init, tofu plan, tofu apply
- Verify resources in GCP Console
- Run
tofu destroy to clean up
Reference: https://registry.terraform.io/providers/hashicorp/google/latest/docs