Lộ trình
Google CloudAssociateTuần 1: Nền tảngBài 5 / 30

Ngày 5: Cài đặt gcloud CLI

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 5
hoàn thành5 / 30 bài
Bối cảnh bài học

Dùng gcloud CLI an toàn qua named configuration, account/project context, format/filter và dry-run/read-only workflow.

đọ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

Dùng gcloud CLI an toàn qua named configuration, account/project context, format/filter và dry-run/read-only workflow.

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

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

  • Cài đặt và cấu hình gcloud SDK trên máy local
  • Thực hành các lệnh gcloud config, gcloud projects list
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 lệnh gcloud tạo VM chạy nhầm project vì default context cũ; output dài khiến người học không nhìn thấy target. Bài học xây habit kiểm tra context và chọn output có thể audit trước mutating command.

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ế
  • gcloud configuration lưu account/project/region/zone và có thể chuyển context; default context không phải bằng chứng target đúng.
  • Explicit `--project`, `--region`, `--zone` làm command dễ review hơn; named configuration tách lab/prod.
  • `--format` và `--filter` giúp output nhỏ, machine-readable và kiểm tra invariant.
  • Read-only describe/list trước create/update/delete là safety pattern; dry-run/validate tùy command không thay review.

gcloud là control surface

Trước lệnh mutating: identity → configuration → target → permission → cost → rollback. Named configuration giúp tách lab/prod, nhưng vẫn phải đọc output; explicit --project/--region/--zone làm intent rõ hơn.

Output có thể audit

Dùng --format để chỉ hiển thị project/zone/status cần kiểm tra; dùng --filter để tránh đọc nhầm item. Ghi command và expected result, không ghi token. list/describe trước create/update/delete giúp phát hiện target sai.

Credential

User ADC, service account impersonation và key file có risk/lifecycle khác nhau. Ưu tiên short-lived/impersonation/workload identity; không commit key hoặc dùng account admin chung.

Bài tập

Viết hai configuration design và command runbook tạo lab VM (design-only): preflight context, explicit flags, expected output, failure/rollback và cleanup. Chạy read-only commands nếu environment cho phép.

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 config configurations list
gcloud config list --format="yaml(core.account,core.project,compute.region,compute.zone)"
gcloud projects list --filter="labels.environment=lab" --format="table(projectId,name)"
Hands-on lab

Thực hành theo scenario

  1. Tạo design cho `lab` và `prod-readonly` configuration; không lưu token trong shell history/repo.
  2. Chạy `gcloud auth list`, `gcloud config configurations list`, `gcloud config list` và project list; kiểm tra account/project/region/zone.
  3. Viết command plan có explicit `--project` và `--format`; preview target bằng describe/list trước mutating action.
  4. Tạo command safety checklist: target, permission, cost, blast radius, rollback, cleanup và verification.
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:

  • Named config/context hiển thị đúng target.
  • Command plan có explicit target hoặc confirmation.
  • Output filter/format hiển thị evidence cần thiết.
  • Không dùng credential/key dài hạn.
  • Có preflight/rollback/cleanup cho mutating command.
Transfer to exam / production

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

ACE thực hành cần tốc độ nhưng không được nhầm project/zone. Hãy dùng gcloud config và explicit flags, rồi verify output sau lệnh.

Checkpoint · 3 phút

Kiểm tra nhanh

Câu hỏi: Cách nào giảm nguy cơ gcloud tạo resource nhầm project nhất?

Kết thúc bài

Checklist trước khi sang Ngày 2