Lộ trình
Google CloudAssociateTuần 2: Đào sâu dịch vụ cốt lõiBài 10 / 30

Ngày 10: Instance Groups & Autoscaling

Thời lượng: 45 phút
Mục tiêu: 2 nhiệm vụ chính
Tiến độ lộ trình
gcp-acengày 10
hoàn thành10 / 30 bài
Bối cảnh bài học

Thiết kế Managed Instance Group và autoscaling theo template, health signal, desired/min/max, multi-zone failure và state externalization.

đọc hiểuthực hànhcheckpoint
Bài giảng hôm nay

Học hiểu, rồi mới thực hành

Thiết kế Managed Instance Group và autoscaling theo template, health signal, desired/min/max, multi-zone failure và state externalization.

Bắt đầu đọc bài giảng

Nhiệm vụ bài học hôm nay

  • Tìm hiểu Managed Instance Group
  • Thực hành cấu hình Autoscaler theo CPU
Instructor walkthrough

Bài giảng chi tiết: từ bài toán đến bằng chứng

Scenario xuyên suốt

Một web service chạy một VM và tăng tải bằng cách resize thủ công. Khi VM lỗi, team không có replacement; khi autoscaler tạo instance mới, image/config lại không nhất quán. Bài học nối instance template, MIG, health check và scaling policy thành một control loop có thể kiểm chứng.

01Đọc bài toán

Xác định actor, workload, constraint và trạng thái cuối cần đạt.

02Vẽ luồng / boundary

Chỉ ra request, dependency, identity và failure domain trước khi chọn công cụ.

03Chọn và thực hành

Thay đổi nhỏ nhất trong lab cô lập; command nào cũng phải nói rõ nó kiểm tra điều gì.

04Kiểm chứng / recovery

Đối chiếu trạng thái thực tế, tạo một failure variant và ghi cách hoàn tác.

Cách nối lý thuyết với thực tế
  • Instance template là immutable-ish blueprint cho image, machine, network, service account, metadata và startup; MIG dùng template để tạo instance nhất quán.
  • Regional MIG trải workload qua zones và giảm single-zone failure, nhưng cần capacity/quota và application state phù hợp.
  • Autoscaler dùng signal như CPU, load-balancing capacity hoặc custom metric; target tracking không thay health check.
  • Health check của load balancer và autohealing có mục đích khác nhau; unhealthy target cần evidence trước replacement.

Từ blueprint đến control loop

MIG không chỉ là “nhiều VM”. Instance template định nghĩa baseline; group giữ desired capacity; health check/autohealing xử lý instance không phục vụ; autoscaler thay đổi target size theo signal. Hãy viết expected state cho từng thành phần trước khi thao tác.

Scaling và failure

CPU phù hợp khi CPU là proxy tốt cho load; load-balancing capacity hoặc custom metric phù hợp hơn khi latency/request concurrency mới là bottleneck. Regional MIG giảm rủi ro mất một zone nhưng cần quota, capacity và network path. Khi instance bị thay, local session/file biến mất; state phải ở hệ thống phù hợp bên ngoài group.

Rollout và cleanup

Template mới cần rollout strategy, health evidence, canary/rollback và version tracking. Khi dọn lab, xóa group/autoscaler trước template; kiểm tra firewall, address, disk/snapshot còn lại và billing impact.

Bài tập

Thiết kế regional MIG cho web API qua hai zone với min/desired/max, health endpoint và autoscaling signal. Viết failure matrix cho instance unhealthy, zone down, traffic spike và bad template; mỗi dòng có evidence, action, rollback và cleanup.

Terminal reference

Command list và cách dùng

Chạy từng lệnh theo đúng thứ tự. Trước các lệnh có thể tạo hoặc thay đổi tài nguyên, hãy kiểm tra profile, account và region.

Commands · read-only checkpoints
gcloud compute instance-templates list --project=LAB_PROJECT_ID --format="table(name,properties.machineType,properties.disks[0].initializeParams.sourceImage)"
gcloud compute instance-groups managed list --project=LAB_PROJECT_ID --format="table(name,scope,instanceTemplate,targetSize)"
gcloud compute instance-groups managed describe MIG_NAME --region=REGION --project=LAB_PROJECT_ID
gcloud compute autoscaler describe AUTOSCALER_NAME --region=REGION --project=LAB_PROJECT_ID
Hands-on lab

Thực hành theo scenario

  1. Vẽ flow client → load balancer → regional MIG qua hai zone; ghi template, target size, min/max, health check, autoscaling signal và failure domain.
  2. Dùng read-only commands để inspect instance templates, instance groups, autoscalers và target pools; không bật autoscaling trên production.
  3. Nếu có lab, dùng regional MIG nhỏ, startup script idempotent, health endpoint rõ, max thấp và cost/TTL; tạo failure scenario rồi kiểm tra replacement evidence.
  4. Verify expected state: instance count, zones, template version, health status, autoscaler recommendation và logs. Cleanup MIG trước template/firewall/IP theo dependency.
Evidence checkpoint

Kiểm chứng kết quả

Không coi lệnh chạy thành công là đủ. Hãy đối chiếu output với trạng thái mong đợi:

  • Phân biệt template, MIG, health check và autoscaler.
  • Chọn signal/policy theo workload, không dùng CPU mặc định vô điều kiện.
  • Giải thích regional failure và quota/capacity trade-off.
  • Nhận diện session/data local không phù hợp với replacement.
  • Có rollout, rollback, cost limit và cleanup verification.
Transfer to exam / production

Bẫy thường gặp và trade-off

ACE hay đánh lừa giữa managed instance group và unmanaged group, autohealing và autoscaling, zonal và regional. Đọc requirement về replacement, distribution, metric và state trước khi chọn.

Checkpoint · 3 phút

Kiểm tra nhanh

Câu hỏi: Một regional MIG tạo instance mới nhưng request vẫn lỗi vì user session biến mất sau replacement. Điều cần sửa ở kiến trúc là gì?

Kết thúc bài

Checklist trước khi sang Ngày 2