Exercises and Projects
1 - Hands-on exercises
Exercise 1: Initial setup
Objective: Configure a GCP project for DevOps.
Tasks:
- Create a GCP project
- Enable the required APIs
- Create an Artifact Registry repository
- Configure the gcloud CLI
Solution
# Create the project
gcloud projects create mon-projet-devops \
--name="Mon Projet DevOps"
# Set as active project
gcloud config set project mon-projet-devops
# Enable the APIs
gcloud services enable \
cloudbuild.googleapis.com \
artifactregistry.googleapis.com \
run.googleapis.com \
container.googleapis.com \
monitoring.googleapis.com \
logging.googleapis.com
# Create the Artifact Registry repo
gcloud artifacts repositories create images \
--repository-format=docker \
--location=europe-west1
# Configure Docker
gcloud auth configure-docker europe-west1-docker.pkg.dev
Exercise 2: Cloud Build pipeline
Objective: Create a CI/CD pipeline for a Node.js application.
Solution
# cloudbuild.yaml
steps:
- name: 'node:18'
entrypoint: 'npm'
args: ['ci']
- name: 'node:18'
entrypoint: 'npm'
args: ['run', 'lint']
- name: 'node:18'
entrypoint: 'npm'
args: ['test']
- name: 'gcr.io/cloud-builders/docker'
args:
- 'build'
- '-t'
- 'europe-west1-docker.pkg.dev/$PROJECT_ID/images/app:$COMMIT_SHA'
- '-t'
- 'europe-west1-docker.pkg.dev/$PROJECT_ID/images/app:latest'
- '.'
- name: 'gcr.io/cloud-builders/docker'
args:
- 'push'
- '--all-tags'
- 'europe-west1-docker.pkg.dev/$PROJECT_ID/images/app'
images:
- 'europe-west1-docker.pkg.dev/$PROJECT_ID/images/app:$COMMIT_SHA'
- 'europe-west1-docker.pkg.dev/$PROJECT_ID/images/app:latest'
options:
machineType: 'E2_HIGHCPU_8'
Exercise 3: Cloud Run deployment
Objective: Deploy an application to Cloud Run with traffic splitting.
Solution
# Deploy v1
gcloud run deploy my-app \
--image=europe-west1-docker.pkg.dev/mon-projet/images/app:v1 \
--region=europe-west1 \
--allow-unauthenticated \
--tag=v1
# Deploy v2 without traffic
gcloud run deploy my-app \
--image=europe-west1-docker.pkg.dev/mon-projet/images/app:v2 \
--region=europe-west1 \
--no-traffic \
--tag=v2
# Canary: 10% on v2
gcloud run services update-traffic my-app \
--to-tags=v2=10,v1=90 \
--region=europe-west1
# Promote v2 to 100%
gcloud run services update-traffic my-app \
--to-tags=v2=100 \
--region=europe-west1
Exercise 4: Monitoring and alerts
Objective: Configure monitoring and alerts.
Solution
# Create an uptime check
gcloud monitoring uptime-checks create http app-health \
--display-name="App Health Check" \
--resource-type=uptime-url \
--monitored-resource-labels=host=my-app-xxx.run.app \
--path=/health \
--check-interval=60s
# Create a notification channel (email)
gcloud alpha monitoring channels create \
--display-name="Team Email" \
--type=email \
[email protected]
# Create an alert
gcloud alpha monitoring policies create \
--display-name="High Error Rate" \
--condition-display-name="Error rate > 1%" \
--condition-filter='resource.type="cloud_run_revision" AND metric.type="run.googleapis.com/request_count" AND metric.labels.response_code_class="5xx"' \
--condition-threshold-value=1 \
--condition-threshold-comparison=COMPARISON_GT \
--notification-channels=<channel-id>
2 - Complete project: Microservices Application
Architecture
Project structure
my-microservices/
├── .cloudbuild/
│ ├── ci.yaml
│ └── cd.yaml
├── clouddeploy/
│ ├── delivery-pipeline.yaml
│ └── targets.yaml
├── services/
│ ├── frontend/
│ │ ├── Dockerfile
│ │ ├── package.json
│ │ └── kubernetes/
│ ├── api/
│ │ ├── Dockerfile
│ │ ├── package.json
│ │ └── kubernetes/
│ └── worker/
│ ├── Dockerfile
│ └── kubernetes/
├── skaffold.yaml
└── README.md
CI pipeline
# .cloudbuild/ci.yaml
steps:
# Build all services
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', '${_REGION}-docker.pkg.dev/$PROJECT_ID/images/frontend:$COMMIT_SHA', './services/frontend']
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', '${_REGION}-docker.pkg.dev/$PROJECT_ID/images/api:$COMMIT_SHA', './services/api']
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', '${_REGION}-docker.pkg.dev/$PROJECT_ID/images/worker:$COMMIT_SHA', './services/worker']
# Push all
- name: 'gcr.io/cloud-builders/docker'
args: ['push', '${_REGION}-docker.pkg.dev/$PROJECT_ID/images/frontend:$COMMIT_SHA']
- name: 'gcr.io/cloud-builders/docker'
args: ['push', '${_REGION}-docker.pkg.dev/$PROJECT_ID/images/api:$COMMIT_SHA']
- name: 'gcr.io/cloud-builders/docker'
args: ['push', '${_REGION}-docker.pkg.dev/$PROJECT_ID/images/worker:$COMMIT_SHA']
# Create release
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: 'gcloud'
args:
- 'deploy'
- 'releases'
- 'create'
- 'release-$SHORT_SHA'
- '--delivery-pipeline=microservices-pipeline'
- '--region=${_REGION}'
- '--images=frontend=${_REGION}-docker.pkg.dev/$PROJECT_ID/images/frontend:$COMMIT_SHA,api=${_REGION}-docker.pkg.dev/$PROJECT_ID/images/api:$COMMIT_SHA,worker=${_REGION}-docker.pkg.dev/$PROJECT_ID/images/worker:$COMMIT_SHA'
substitutions:
_REGION: 'europe-west1'
options:
machineType: 'E2_HIGHCPU_8'
Cloud Deploy Pipeline
# clouddeploy/delivery-pipeline.yaml
apiVersion: deploy.cloud.google.com/v1
kind: DeliveryPipeline
metadata:
name: microservices-pipeline
serialPipeline:
stages:
- targetId: dev
profiles: [dev]
- targetId: staging
profiles: [staging]
- targetId: production
profiles: [production]
strategy:
canary:
canaryDeployment:
percentages: [25, 50, 75]
verify: true
3 - Review quiz
-
What is the difference between Cloud Build and Cloud Deploy?
-
When should you use GKE Autopilot vs Standard?
-
How do you secure secrets in Cloud Run?
-
What is Workload Identity?
-
How do you configure a canary deployment on Cloud Run?
Answers
-
Cloud Build runs the builds (CI). Cloud Deploy manages the delivery (CD) to environments.
-
Autopilot: zero management, pay-per-pod. Standard: full control, GPU/TPU, customization.
-
Use Secret Manager and mount the secrets with
--set-secrets. -
A secure method to allow GKE pods to access GCP APIs without service account keys.
-
Deploy with
--no-trafficthen useupdate-trafficto gradually increase the percentage.
4 - Google Cloud Certification
Professional Cloud DevOps Engineer
| Domain | Weight |
|---|---|
| Bootstrapping a Google Cloud organization | 17% |
| Building and implementing CI/CD pipelines | 24% |
| Applying SRE practices to a service | 23% |
| Implementing service monitoring strategies | 21% |
| Optimizing service performance | 15% |
Resources
Course summary
Congratulations! You have completed the GCP DevOps course.
You now have a solid grasp of:
- Cloud Source Repositories and triggers
- Cloud Build for CI
- Artifact Registry for artifacts
- Cloud Deploy for CD
- GKE and Cloud Run for execution
- Cloud Monitoring and Logging
Next steps
- Practice with real projects
- Take the Professional Cloud DevOps Engineer certification
- Explore advanced services (Cloud Functions, Anthos)