Ngân hàng đề — Google Cloud Professional Cloud Developer

Tìm thấy 358 câu.

Câu 91 Chọn nhiều đáp án
Your team develops services that run on Google Kubernetes Engine. You need to standardize their log data using Google-recommended practices and make the data more useful in the fewest number of steps. What should you do? (Choose two.)
  1. A Create aggregated exports on application logs to BigQuery to facilitate log analytics.
  2. B Create aggregated exports on application logs to Cloud Storage to facilitate log analytics.
  3. C Write log output to standard output (stdout) as single-line JSON to be ingested into Cloud Logging as structured logs.
  4. D Mandate the use of the Logging API in the application code to write structured logs to Cloud Logging.
  5. E Mandate the use of the Pub/Sub API to write structured data to Pub/Sub and create a Dataflow streaming pipeline to normalize logs and write them to BigQuery for analytics.
Xem giải thích

🧩 Phân tích chi tiết nội dung câu hỏi

Câu hỏi tập trung vào việc chuẩn hóa dữ liệu log cho các dịch vụ chạy trên Google Kubernetes Engine (GKE), theo các thực hành được Google khuyến nghị. Mục tiêu là làm cho dữ liệu log trở nên hữu ích hơn (dễ phân tích, query) với số bước ít nhất (fewest number of steps). Đây là câu hỏi trắc nghiệm chọn hai đáp án đúng, liên quan đến Cloud Logging – dịch vụ quản lý log mặc định của GKE.

  • Bối cảnh: Trong GKE, log từ container (application logs) được tự động thu thập qua Fluentd/Fluent Bit và gửi đến Cloud Logging. Để chuẩn hóa, Google khuyến nghị sử dụng structured logging (log dạng JSON có cấu trúc) và xuất log (aggregated exports) đến các dịch vụ phân tích như BigQuery.
  • Yêu cầu chính:
    • ✅ Chuẩn hóa log theo best practices (structured, dễ query).
    • ✅ Tối ưu số bước: Không dùng pipeline phức tạp.
  • Kiến thức cập nhật 2026: Theo tài liệu Google Cloud mới nhất (Logging v2, GKE 1.29+), stdout JSON là cách đơn giản nhất cho structured logs; export trực tiếp từ Cloud Logging đến BigQuery là best practice cho analytics (không cần trung gian như Pub/Sub/Dataflow).

✅ Đáp án đúng (Chọn hai)

Các đáp án đúng là:

  1. Create aggregated exports on application logs to BigQuery to facilitate log analytics.
  2. Write log output to standard output (stdout) as single-line JSON to be ingested into Cloud Logging as structured logs.

Lý do lựa chọn:

  • 🛠️ Stdout JSON: Đây là cách đơn giản nhất (fewest steps) để tạo structured logs trong GKE. Cloud Logging tự động parse JSON từ stdout thành các trường có cấu trúc (như severity, message), giúp query/filter dễ dàng mà không cần thay đổi code nhiều.
  • 📊 Export to BigQuery: Google khuyến nghị xuất aggregated logs trực tiếp từ Cloud Logging đến BigQuery để phân tích (analytics). BigQuery hỗ trợ SQL query lớn, ML integration, và là "single pane of glass" cho log analytics – nhanh, scalable, không cần ETL phức tạp.

Kết hợp hai bước này: Log → stdout JSON → Cloud Logging (structured) → Export BigQuery → Analytics. Tổng 2 bước, chuẩn hóa hoàn chỉnh!

🔍 Giải thích tất cả các phương án

Dưới đây là phân tích từng lựa chọn giữ nguyên văn bản gốc bằng tiếng Anh. Mỗi phương án được đánh giá đúng/sai với lý do chi tiết bằng tiếng Việt, dựa trên best practices Google Cloud Logging/GKE (cập nhật 2026).

  • ✅ Create aggregated exports on application logs to BigQuery to facilitate log analytics.
    Đúng: Đây là best practice chính thức. Từ Cloud Logging, bạn tạo sink export logs (application logs từ GKE) trực tiếp đến BigQuery dataset. BigQuery biến log thành bảng phân tích, hỗ trợ query SQL thời gian thực, partitioning tự động theo timestamp. Ít bước nhất cho analytics quy mô lớn. (Fewest steps: Chỉ cần config sink một lần.)

  • ❌ Create aggregated exports on application logs to Cloud Storage to facilitate log analytics.
    Sai: Cloud Storage chỉ lưu trữ file JSON/CSV thô, không hỗ trợ query SQL hay analytics native như BigQuery. Phải dùng thêm công cụ ETL (như Dataflow) để load vào BigQuery → tăng số bước, không hiệu quả. Google khuyến nghị Storage chỉ cho archival dài hạn, không phải analytics chính.

  • ✅ Write log output to standard output (stdout) as single-line JSON to be ingested into Cloud Logging as structured logs.
    Đúng: Recommended nhất cho container/GKE (theo Operations Suite best practices). Viết log dạng { "severity": "INFO", "message": "Hello" } vào stdout/stderr → Cloud Logging agent tự parse thành structured fields (extractors tự động). Không cần API call, tương thích mọi ngôn ngữ (Node.js, Java, Python), zero-config cho GKE Logging.

  • ❌ Mandate the use of the Logging API in the application code to write structured logs to Cloud Logging.
    Sai: Dùng Logging API (client libraries) yêu cầu thay đổi code lớn (import SDK, auth IAM, handle retries) → không fewest steps, dễ lỗi nếu scale. Google không khuyến nghị cho container vì stdout đơn giản hơn, idempotent, và agent GKE xử lý hết. Chỉ dùng API cho non-container workloads.

  • ❌ Mandate the use of the Pub/Sub API to write structured data to Pub/Sub and create a Dataflow streaming pipeline to normalize logs and write them to BigQuery for analytics.
    Sai: Quá phức tạp (nhiều steps: Code Pub/Sub → Pipeline Dataflow → BigQuery). Tốn chi phí (Dataflow compute), latency cao, quản lý khó. Google ưu tiên trực tiếp từ Cloud Logging (sink to BigQuery), không cần Pub/Sub/Dataflow trừ khi custom transformation phức tạp – vi phạm "fewest steps".

📘 Tài liệu tham khảo (Cập nhật 2026)

Hy vọng phân tích này giúp bạn nắm vững! 🚀 Nếu cần ví dụ code JSON log, hỏi thêm nhé!

Câu 92
You are designing a deployment technique for your new applications on Google Cloud. As part of your deployment planning, you want to use live traffic to gather performance metrics for both new and existing applications. You need to test against the full production load prior to launch. What should you do?
  1. A Use canary deployment
  2. B Use blue/green deployment
  3. C Use rolling updates deployment
  4. D Use A/B testing with traffic mirroring during deployment
Xem giải thích

🧩 Phân tích chi tiết nội dung câu hỏi

Câu hỏi tập trung vào việc thiết kế kỹ thuật triển khai (deployment technique) cho ứng dụng mới trên Google Cloud Platform (GCP). Yêu cầu chính là:

  • Sử dụng live traffic (lưu lượng truy cập thực tế từ production) để thu thập performance metrics (chỉ số hiệu suất) cho cả ứng dụng mới và ứng dụng hiện tại.
  • Test đối với full production load (toàn bộ tải production thực tế) trước khi launch chính thức, mà không làm gián đoạn dịch vụ đang chạy.

📌 Mục tiêu cốt lõi: Cần một phương pháp cho phép kiểm tra ứng dụng mới dưới tải thực tế đầy đủ, thu thập dữ liệu so sánh với phiên bản cũ, nhưng không ảnh hưởng đến traffic production (không route traffic thật sang version mới).

🛠️ Bối cảnh GCP (cập nhật đến 2026): GCP hỗ trợ các chiến lược triển khai progressive delivery qua Google Kubernetes Engine (GKE), Cloud Run, Anthos Service Mesh (nay tích hợp Istio), với tính năng traffic mirroring (shadow traffic) để mirror 100% traffic production sang version mới mà chỉ thu thập metrics, không gửi response về client.

✅ Đáp án đúng và lý do lựa chọn

Đáp án đúng: Use A/B testing with traffic mirroring during deployment

Lý do:

  • A/B testing kết hợp traffic mirroring cho phép mirror toàn bộ live traffic (full production load) sang version mới, thu thập metrics (latency, error rate, throughput) để so sánh với version cũ mà không ảnh hưởng production (version mới chỉ nhận shadow requests, không reply back).
  • Đáp ứng hoàn hảo: Test full load trước launch, gather metrics cho cả new/existing apps.
  • Trong GCP: Hỗ trợ qua Istio traffic mirroring (GKE Enterprise), Cloud Run traffic splitting + mirroring (preview/full từ 2024), hoặc Knative Serving – cập nhật 2026 vẫn là best practice cho progressive delivery.

📋 Giải thích tất cả các phương án (đúng/sai)

  • ❌ [SAI] Use canary deployment
    Giải thích sai: Canary chỉ route một phần nhỏ traffic (ví dụ 5-10%) sang version mới để test dần dần. Không test full production load (chỉ subset), và không mirror traffic để so sánh metrics song song với existing app. Phù hợp gradual rollout nhưng không đáp ứng yêu cầu full load prior to launch.

  • ❌ [SAI] Use blue/green deployment
    Giải thích sai: Blue/green switch toàn bộ traffic từ blue (old) sang green (new) một lần. Không dùng live traffic để test trước launch dưới full load (chỉ test riêng lẻ), và không gather metrics song song cho both apps. Rủi ro cao nếu switch fail, không mirror.

  • ❌ [SAI] Use rolling updates deployment
    Giải thích sai: Rolling updates thay thế dần dần instances cũ bằng mới trong cùng cluster, route traffic thật sang new instances ngay. Không test full load riêng biệt prior to launch (test lẫn lộn), khó gather metrics riêng cho new vs existing mà không gián đoạn.

  • ✅ [ĐÚNG] Use A/B testing with traffic mirroring during deployment
    Giải thích đúng: Như trên, mirror 100% live traffic sang new version (A/B so sánh variants), thu thập metrics đầy đủ cho both apps dưới full production load mà không route response từ new version. Hoàn hảo cho test prior launch trên GCP.

📘 Tài liệu tham khảo (cập nhật GCP 2026)

Hy vọng phân tích này giúp bạn ôn thi hiệu quả! 🚀 Nếu cần thêm ví dụ code YAML Istio, hãy hỏi nhé!

Câu 93
You support an application that uses the Cloud Storage API. You review the logs and discover multiple HTTP 503 Service Unavailable error responses from the
API. Your application logs the error and does not take any further action. You want to implement Google-recommended retry logic to improve success rates.
Which approach should you take?
  1. A Retry the failures in batch after a set number of failures is logged.
  2. B Retry each failure at a set time interval up to a maximum number of times.
  3. C Retry each failure at increasing time intervals up to a maximum number of tries.
  4. D Retry each failure at decreasing time intervals up to a maximum number of tries.
Xem giải thích

🧩 Phân tích chi tiết nội dung câu hỏi

Câu hỏi tập trung vào việc xử lý lỗi HTTP 503 Service Unavailable từ Google Cloud Storage API (một dịch vụ lưu trữ đối tượng của Google Cloud Platform - GCP). Ứng dụng đang gặp lỗi này thường xuyên, nhưng hiện tại chỉ ghi log mà không thực hiện retry (thử lại), dẫn đến tỷ lệ thành công thấp.
📌 Mục tiêu: Triển khai retry logic được Google khuyến nghị để cải thiện tỷ lệ thành công khi gọi API.
🔍 Bối cảnh kỹ thuật: HTTP 503 là lỗi tạm thời (throttling hoặc quá tải server-side), nên retry với chiến lược phù hợp là best practice. Google Cloud khuyến nghị sử dụng exponential backoff (tăng dần khoảng cách thời gian thử lại) để tránh làm trầm trọng hóa vấn đề (như DDoS-like traffic). Kiến thức dựa trên tài liệu GCP cập nhật mới nhất (2024-2026), không thay đổi cơ bản so với trước.

✅ Đáp án đúng và lý do lựa chọn

Đáp án đúng: Retry each failure at increasing time intervals up to a maximum number of tries.
🛠️ Lý do: Đây chính là chiến lược exponential backoff (truncated exponential backoff) được Google chính thức khuyến nghị cho tất cả các API, bao gồm Cloud Storage.

  • Bắt đầu với khoảng cách ngắn (ví dụ: 1 giây), sau đó tăng dần (nhân đôi: 2s, 4s, 8s...) kèm jitter (random hóa nhẹ) để tránh xung đột.
  • Giới hạn số lần thử (max retries, thường 5-10) để tránh vòng lặp vô tận.
  • Lợi ích: Giảm tải server, tăng cơ hội thành công khi lỗi tạm thời.
    📘 Nguồn tham khảo:
  • Google Cloud Storage: Retry and backoff strategies (cập nhật 2024).
  • Google Cloud Client Libraries: Retry configuration (hỗ trợ tự động exponential backoff từ v2.x+).

📋 Giải thích tất cả các phương án (đúng/sai)

Dưới đây là phân tích từng lựa chọn một cách chi tiết. Tôi giữ nguyên văn bản gốc tiếng Anh của phương án, chỉ giải thích bằng tiếng Việt với emoji nổi bật:

  • Retry the failures in batch after a set number of failures is logged.
    ❌ Sai: Chiến lược này gom lỗi lại rồi retry hàng loạt sau khi đạt số lượng nhất định. Điều này không được Google khuyến nghị vì:

    • Làm chậm xử lý (chờ tích lũy lỗi), giảm trải nghiệm người dùng.
    • Tăng rủi ro overload server nếu batch lớn, đặc biệt với 503 (lỗi tạm thời cần retry ngay).
      🧨 Vấn đề: Không xử lý realtime, trái với best practice "immediate retry with backoff".
  • Retry each failure at a set time interval up to a maximum number of times.
    ❌ Sai: Retry mỗi lỗi với khoảng cách thời gian cố định (fixed interval, ví dụ: cứ 5s thử lại).

    • Nhược điểm: Dễ gây "thundering herd" (nhiều request đồng thời sau cùng một khoảng thời gian), làm tình trạng 503 tệ hơn.
    • Google không recommend fixed delay vì thiếu tính thích ứng với tải server.
      🚫 So sánh: Exponential backoff linh hoạt hơn, tránh xung đột.
  • Retry each failure at increasing time intervals up to a maximum number of tries.
    ✅ Đúng (như đã giải thích ở trên): Đây là exponential backoff chuẩn, được tích hợp sẵn trong Google Cloud Client Libraries (Java, Python, Go, Node.js...). Ví dụ code Python: client = storage.Client(retry=Retry(initial=1.0, maximum=60.0, multiplier=2.0)).
    🎯 Ưu điểm: Tăng dần → Giảm tải dần dần, jitter ngẫu nhiên tránh đồng bộ.

  • Retry each failure at decreasing time intervals up to a maximum number of tries.
    ❌ Sai: Retry với khoảng cách giảm dần (ví dụ: 10s → 5s → 1s).

    • Rủi ro cao: Tăng tần suất request theo thời gian, làm trầm trọng hóa throttling/503, có thể dẫn đến ban IP hoặc chi phí cao.
    • Hoàn toàn trái ngược với nguyên tắc backoff (phải "back off" = lùi dần).
      ⚠️ Không bao giờ dùng: Chỉ phù hợp hypothetically cho edge case, không phải best practice GCP.

🏆 Kết luận và khuyến nghị triển khai

  • Best practice GCP 2026: Sử dụng client libraries tự động (tích hợp backoff + jitter). Nếu custom, implement theo công thức: delay = min(initial * (2 **attempt), max_delay) + random_jitter.
  • Test: Sử dụng gcloud mock hoặc Load Balancer để simulate 503.
    📚 Tài liệu bổ sung: GCP API Design Guide: Handling failures (vẫn valid 2026). Nếu cần code sample, hãy hỏi thêm! 🚀
Câu 94
You need to redesign the ingestion of audit events from your authentication service to allow it to handle a large increase in traffic. Currently, the audit service and the authentication system run in the same Compute Engine virtual machine. You plan to use the following Google Cloud tools in the new architecture:
✑ Multiple Compute Engine machines, each running an instance of the authentication service
✑ Multiple Compute Engine machines, each running an instance of the audit service
✑ Pub/Sub to send the events from the authentication services.
How should you set up the topics and subscriptions to ensure that the system can handle a large volume of messages and can scale efficiently?
  1. A Create one Pub/Sub topic. Create one pull subscription to allow the audit services to share the messages.
  2. B Create one Pub/Sub topic. Create one pull subscription per audit service instance to allow the services to share the messages.
  3. C Create one Pub/Sub topic. Create one push subscription with the endpoint pointing to a load balancer in front of the audit services.
  4. D Create one Pub/Sub topic per authentication service. Create one pull subscription per topic to be used by one audit service.
  5. E Create one Pub/Sub topic per authentication service. Create one push subscription per topic, with the endpoint pointing to one audit service.
Xem giải thích

🧩 Phân tích chi tiết nội dung câu hỏi

Câu hỏi tập trung vào việc thiết kế lại hệ thống ingestion (thu nhận) các sự kiện audit từ dịch vụ authentication để xử lý lưu lượng traffic lớn tăng đột biến.

  • Tình huống hiện tại: Dịch vụ audit và authentication chạy chung trên một Compute Engine VM duy nhất, dẫn đến bottleneck khi scale.
  • Kiến trúc mới:
    • ✅ Nhiều Compute Engine VM chạy instances của authentication service (gửi events).
    • ✅ Nhiều Compute Engine VM chạy instances của audit service (nhận và xử lý events).
    • Sử dụng Pub/Sub làm message broker để authentication services publish events.
  • Mục tiêu chính: Thiết kế topics và subscriptions sao cho hệ thống xử lý volume lớn messages (high throughput), scale hiệu quả (horizontal scaling với multiple instances), đảm bảo fan-out/load balancing giữa các audit services mà không mất messages (at-least-once delivery).

🛠️ Vấn đề cốt lõi: Pub/Sub cần cấu hình để multiple authentication services publish vào topic chung, và multiple audit services consume chung mà không duplicate thừa hoặc bottleneck. Theo docs Google Cloud Pub/Sub (cập nhật 2024-2026), pull subscriptions với competing consumers là best practice cho scalability nội bộ.

📘 Tài liệu tham khảo:

✅ Đáp án đúng và lý do lựa chọn

Đáp án đúng: Create one Pub/Sub topic. Create one pull subscription to allow the audit services to share the messages.

🧩 Lý do chi tiết:

  • Một topic duy nhất: Tất cả authentication services publish vào topic chung, đơn giản hóa architecture, giảm quản lý (không cần nhiều topics), và Pub/Sub tự scale throughput lên đến millions messages/second (theo capacity 2026).
  • Một pull subscription: Các audit services pull messages từ subscription chung dưới dạng competing consumers (cạnh tranh ack messages). Pub/Sub tự load balance messages giữa multiple pull clients (mỗi VM audit instance pull độc lập), đảm bảo scale horizontal mà không duplicate thừa, xử lý high volume hiệu quả.
  • ✅ Ưu điểm scale: Không giới hạn số consumers, auto-handling backpressure, idempotent với ack/nack. Hoàn hảo cho "large increase in traffic" và multiple instances.

❌ Phân tích tất cả các phương án (đúng/sai)

Dưới đây là giải thích từng lựa chọn, giữ nguyên văn bản gốc:

  • ✅ [ĐÚNG] Create one Pub/Sub topic. Create one pull subscription to allow the audit services to share the messages.
    🛠️ Giải thích đúng: Như trên, đây là best practice cho fan-out với multiple consumers. Pull subscription cho phép shared load balancing, scale dễ dàng khi thêm audit instances mà không tạo thêm subs/topics thừa. Pub/Sub đảm bảo high throughput (~1M ops/sec/topic).

  • ❌ [SAI] Create one Pub/Sub topic. Create one pull subscription per audit service instance to allow the services to share the messages.
    🧩 Giải thích sai: Tạo nhiều pull subs trên cùng topic (một sub/instance) dẫn đến duplicate delivery (mỗi message replicate N lần cho N subs), tốn quota (subscriptions có limit 1K/topic), tăng chi phí và complexity quản lý. Không "share" hiệu quả, vi phạm scalability cho large volume.

  • ❌ [SAI] Create one Pub/Sub topic. Create one push subscription with the endpoint pointing to a load balancer in front of the audit services.
    🧩 Giải thích sai: Push subscription đẩy messages đến single endpoint (load balancer), nhưng load balancer (như HTTP LB) khó handle idempotency/ordering với multiple retries (Pub/Sub retry exponential). Không scale tốt cho internal VM instances (latency cao, single point failure), Pub/Sub docs khuyên tránh push cho high-volume internal services.

  • ❌ [SAI] Create one Pub/Sub topic per authentication service. Create one pull subscription per topic to be used by one audit service.
    🧩 Giải thích sai: Nhiều topics (một/auth instance) tạo quản lý phức tạp (topics limit 10K/project), không tận dụng high throughput/topic của Pub/Sub. Mỗi sub chỉ một audit service → không load balance, dễ bottleneck nếu auth > audit instances, kém scale cho "large increase".

  • ❌ [SAI] Create one Pub/Sub topic per authentication service. Create one push subscription per topic, with the endpoint pointing to one audit service.
    🧩 Giải thích sai: Kết hợp nhiều topics + push riêng lẻ tệ nhất: 1:1 mapping auth-audit (không scale nếu số lượng lệch), push endpoint fixed gây single point failure, retry issues, và overhead cao. Không handle "multiple instances" hiệu quả.

🛠️ Kết luận: Thiết kế đúng tận dụng Pub/Sub strengths (unbounded scale, competing consumers), phù hợp kiến trúc microservices trên Google Cloud (2026 updates hỗ trợ Regional topics cho durability cao hơn).

Câu 95
You are developing a marquee stateless web application that will run on Google Cloud. The rate of the incoming user traffic is expected to be unpredictable, with no traffic on some days and large spikes on other days. You need the application to automatically scale up and down, and you need to minimize the cost associated with running the application. What should you do?
  1. A Build the application in Python with Firestore as the database. Deploy the application to Cloud Run.
  2. B Build the application in C# with Firestore as the database. Deploy the application to App Engine flexible environment.
  3. C Build the application in Python with CloudSQL as the database. Deploy the application to App Engine standard environment.
  4. D Build the application in Python with Firestore as the database. Deploy the application to a Compute Engine managed instance group with autoscaling.
Xem giải thích

🧩 Phân tích nội dung câu hỏi

Câu hỏi mô tả việc phát triển một ứng dụng web stateless (không lưu trạng thái phiên), kiểu "marquee" (ứng dụng nổi bật, quan trọng), chạy trên Google Cloud. Đặc điểm chính:

  • Lưu lượng truy cập không dự đoán được: Không có traffic vào một số ngày, nhưng có spike lớn (đột biến cao) vào các ngày khác.
  • Yêu cầu: Tự động scale up/down (mở rộng/thu hẹp linh hoạt), và tối ưu chi phí (minimize cost) – đặc biệt quan trọng vì ứng dụng có thể idle (không hoạt động) lâu.

Mục tiêu là chọn giải pháp serverless hoặc autoscaling hiệu quả, pay-per-use (chỉ trả tiền khi có request), tránh chi phí cố định từ VM luôn chạy. Kiến thức dựa trên Google Cloud cập nhật 2024-2026: Cloud Run là lựa chọn tối ưu cho workload stateless, bursty traffic (theo docs chính thức GCP).

📘 Tài liệu tham khảo:

✅ Đáp án đúng

Build the application in Python with Firestore as the database. Deploy the application to Cloud Run.

Lý do chọn đáp án này 🛠️:

  • Cloud Run là nền tảng serverless container lý tưởng cho app stateless web: Tự động scale từ 0 instances (không tốn phí khi idle) lên hàng nghìn khi có spike, xử lý traffic bursty hoàn hảo.
  • Python hỗ trợ xuất sắc trên Cloud Run (native runtime), deploy nhanh via container (Docker).
  • Firestore là NoSQL serverless DB: Scale tự động, pay-per-read/write, phù hợp stateless app, không cần quản lý server, chi phí thấp khi traffic thấp.
  • Tối ưu chi phí: Chỉ tính phí per request/second, zero cost khi không traffic – hoàn hảo cho yêu cầu "minimize cost".

📋 Giải thích tất cả các phương án

Dưới đây là phân tích từng lựa chọn (giữ nguyên văn bản gốc), đánh dấu ✅ đúng hoặc ❌ sai, với lý do chi tiết bằng tiếng Việt:

  • ✅ Build the application in Python with Firestore as the database. Deploy the application to Cloud Run.
    🟢 Đúng vì: Như đã giải thích trên – serverless hoàn hảo, scale zero-to-many, chi phí thấp nhất cho traffic unpredictable. Firestore + Python là combo native, deploy dễ dàng.

  • ❌ Build the application in C# with Firestore as the database. Deploy the application to App Engine flexible environment.
    🔴 Sai vì: App Engine flexible environment chạy trên VM GKE (luôn có minimum instances), scale chậm hơn, chi phí cao hơn (billing theo VM uptime, không zero khi idle). C# hỗ trợ nhưng không native như Python; không tối ưu cost cho spike traffic.

  • ❌ Build the application in Python with CloudSQL as the database. Deploy the application to App Engine standard environment.
    🔴 Sai vì: App Engine standard scale tốt (sandboxed runtimes), nhưng CloudSQL là relational DB managed, luôn billing (instance giờ, storage) ngay cả idle – không minimize cost. Standard env có cold starts dài cho spike lớn, kém hơn Cloud Run.

  • ❌ Build the application in Python with Firestore as the database. Deploy the application to a Compute Engine managed instance group with autoscaling.
    🔴 Sai vì: Compute Engine MIG (Managed Instance Group) dùng VM thực, cần minimum instances chạy liên tục (chi phí cố định cao khi no traffic). Scale chậm (phút thay vì giây), quản lý phức tạp hơn serverless, không phù hợp minimize cost cho app stateless bursty.

Câu 96
You have written a Cloud Function that accesses other Google Cloud resources. You want to secure the environment using the principle of least privilege. What should you do?
  1. A Create a new service account that has Editor authority to access the resources. The deployer is given permission to get the access token.
  2. B Create a new service account that has a custom IAM role to access the resources. The deployer is given permission to get the access token.
  3. C Create a new service account that has Editor authority to access the resources. The deployer is given permission to act as the new service account.
  4. D Create a new service account that has a custom IAM role to access the resources. The deployer is given permission to act as the new service account.
Xem giải thích

🧩 Phân tích chi tiết nội dung câu hỏi

Câu hỏi tập trung vào việc bảo mật môi trường Google Cloud Functions theo nguyên tắc least privilege (quyền hạn tối thiểu). Cụ thể:
Bạn đã viết một Cloud Function cần truy cập các tài nguyên Google Cloud khác (như Storage, BigQuery, v.v.). Để đảm bảo an toàn, bạn phải:

  • Sử dụng service account (tài khoản dịch vụ) với quyền hạn hẹp nhất có thể.
  • Cấu hình để người deploy (deployer) có thể triển khai function mà không cần quyền rộng.

Mục tiêu: Function chỉ có quyền cần thiết để truy cập tài nguyên, deployer chỉ impersonate (giả lập) service account khi deploy, tránh rò rỉ quyền.
📘 Kiến thức cập nhật (GCP 2026): Theo tài liệu mới nhất, Cloud Functions (Gen 2) sử dụng runtime service account để truy cập tài nguyên. Best practice là custom IAM role + impersonation cho deployer (không dùng Editor role rộng).
Nguồn:

✅ Đáp án đúng

Create a new service account that has a custom IAM role to access the resources. The deployer is given permission to act as the new service account.

Lý do lựa chọn:
🛠️ Phương án này tuân thủ least privilege hoàn hảo:

  • Custom IAM role: Chỉ cấp quyền cụ thể (ví dụ: Storage Object Viewer thay vì Editor toàn bộ project), tránh over-privileged.
  • Deployer được phép "act as" service account (qua role roles/iam.serviceAccountUser hoặc roles/iam.serviceAccountTokenCreator): Deployer có thể impersonate SA khi deploy function với lệnh gcloud functions deploy --service-account=SA_EMAIL. Function runtime sẽ dùng SA này để truy cập tài nguyên an toàn.
    ✅ Không rò rỉ quyền deployer ra function, và function chỉ có quyền hẹp.

📋 Giải thích tất cả các phương án

  • ❌ [SAI] Create a new service account that has Editor authority to access the resources. The deployer is given permission to get the access token.
    ❌ Sai vì: Editor role (roles/editor) cấp quyền quá rộng (edit toàn project: compute, storage, etc.), vi phạm least privilege. "Get access token" chỉ cho phép lấy token tạm thời, không đủ để set runtime SA cho function khi deploy (cần impersonate đầy đủ).

  • ❌ [SAI] Create a new service account that has a custom IAM role to access the resources. The deployer is given permission to get the access token.
    ❌ Sai vì: Custom role ✅ tốt cho least privilege, nhưng "get access token" không cho phép impersonate hoặc set SA cho function. Deployer không thể chỉ định --service-account hiệu quả, dẫn đến function fallback về default SA (thường over-privileged).

  • ❌ [SAI] Create a new service account that has Editor authority to access the resources. The deployer is given permission to act as the new service account.
    ❌ Sai vì: "Act as" ✅ tốt cho deployer (impersonate SA), nhưng Editor role quá rộng, có thể cho function quyền edit không cần thiết (rủi ro security cao, như xóa dữ liệu nhầm).

  • ✅ [ĐÚNG] Create a new service account that has a custom IAM role to access the resources. The deployer is given permission to act as the new service account.
    ✅ Đúng hoàn toàn như giải thích ở phần đáp án trên: Kết hợp least privilege + impersonation an toàn cho deploy.

🛡️ Lời khuyên thực hành: Sử dụng gcloud iam service-accounts add-iam-policy-binding để cấp quyền act-as, và test với gcloud functions deploy --runtime=nodejs20 --service-account=sa@project.iam.gserviceaccount.com.

Câu 97
You are a SaaS provider deploying dedicated blogging software to customers in your Google Kubernetes Engine (GKE) cluster. You want to configure a secure multi-tenant platform to ensure that each customer has access to only their own blog and can't affect the workloads of other customers. What should you do?
  1. A Enable Application-layer Secrets on the GKE cluster to protect the cluster.
  2. B Deploy a namespace per tenant and use Network Policies in each blog deployment.
  3. C Use GKE Audit Logging to identify malicious containers and delete them on discovery.
  4. D Build a custom image of the blogging software and use Binary Authorization to prevent untrusted image deployments.
Xem giải thích

🧩 Phân tích chi tiết nội dung câu hỏi

Câu hỏi mô tả tình huống bạn là nhà cung cấp SaaS (Software as a Service) đang triển khai phần mềm blogging dành riêng cho từng khách hàng trên cụm Google Kubernetes Engine (GKE). Mục tiêu là xây dựng một nền tảng multi-tenant an toàn (đa người thuê), đảm bảo:

  • Mỗi khách hàng chỉ truy cập được blog của riêng họ.
  • Không thể ảnh hưởng đến workloads (các workload như pod, service) của khách hàng khác.

Điều này yêu cầu cách ly (isolation) mạnh mẽ về mặt network và tài nguyên, tránh tình trạng một tenant làm gián đoạn hoặc tấn công tenant khác. Trong GKE (dựa trên Kubernetes), multi-tenant isolation thường sử dụng Namespaces để phân vùng logic và Network Policies để kiểm soát lưu lượng mạng giữa các pod/namespace.
📘 Tài liệu tham khảo: Google Cloud GKE Multi-Tenancy Best Practices và Kubernetes Network Policies (cập nhật đến 2024-2026, hỗ trợ GKE Standard/Autopilot).

✅ Đáp án đúng và lý do lựa chọn

Đáp án đúng: Deploy a namespace per tenant and use Network Policies in each blog deployment.

Lý do 🛠️:

  • Namespace per tenant tạo ra các không gian tên riêng biệt cho từng khách hàng, cách ly tài nguyên (pods, services, configmaps) logic mà không cần cụm riêng (tiết kiệm chi phí).
  • Network Policies cho phép định nghĩa quy tắc firewall cấp pod/namespace, chặn lưu lượng không mong muốn giữa các tenant (ví dụ: chỉ cho phép traffic nội bộ blog, deny all từ tenant khác).
  • Kết hợp này đảm bảo isolation toàn diện về network và tài nguyên, phù hợp nhất cho multi-tenant SaaS trên GKE. Đây là best practice khuyến nghị từ Google Cloud đến năm 2026.

📋 Giải thích tất cả các phương án (đúng/sai)

Dưới đây là phân tích từng lựa chọn, giữ nguyên văn bản gốc bằng tiếng Anh. Mỗi phương án được đánh giá dựa trên tính hiệu quả cho secure multi-tenant isolation trên GKE:

  • Enable Application-layer Secrets on the GKE cluster to protect the cluster.
    ❌ Sai: "Application-layer Secrets" không phải tính năng chuẩn của GKE để bảo vệ cluster hoặc isolate tenant. GKE sử dụng Secret objects hoặc External Secrets Operator cho quản lý bí mật, nhưng chỉ bảo vệ dữ liệu nhạy cảm (như API keys), không cách ly network/workloads giữa tenant. Không giải quyết vấn đề truy cập chéo hoặc ảnh hưởng workloads.

  • Deploy a namespace per tenant and use Network Policies in each blog deployment.
    ✅ Đúng: Như giải thích ở trên, đây là giải pháp tối ưu. Namespaces cung cấp logical isolation, Network Policies (hỗ trợ Calico/Istio trong GKE) enforce zero-trust networking, ngăn pod của tenant A truy cập tenant B. Hoàn hảo cho blogging SaaS multi-tenant.

  • Use GKE Audit Logging to identify malicious containers and delete them on discovery.
    ❌ Sai: GKE Audit Logging (tích hợp Cloud Audit Logs) chỉ dùng để giám sát và ghi log hoạt động (detect sau sự cố), không ngăn chặn pro-actively. Việc "delete on discovery" là thủ công/react-tive, không đảm bảo isolation thời gian thực, dễ bị tấn công lan rộng trước khi phát hiện.

  • Build a custom image of the blogging software and use Binary Authorization to prevent untrusted image deployments.
    ❌ Sai: Binary Authorization (nay là Binary Authorization for Borg (Babore) trong GKE 2024+) chỉ verify image integrity/signature để chống image độc hại khi deploy, không isolate giữa các tenant đã deploy. Custom image giúp standardize software nhưng không ngăn pod của tenant này attack tenant khác qua network.

🏆 Kết luận và khuyến nghị

Giải pháp đúng tận dụng Kubernetes native features trong GKE để multi-tenant an toàn nhất. Để triển khai thực tế:

  • Tạo namespace: kubectl create namespace tenant-xyz.
  • Áp dụng NetworkPolicy YAML với ingress/egress deny-all trừ traffic cần thiết.
    📘 Nguồn bổ sung: GKE Security Best Practices (cập nhật 2026, nhấn mạnh Namespace + Network Policies cho multi-tenancy). Nếu cần code mẫu, hãy cung cấp thêm chi tiết! 🚀
Câu 98 Chọn nhiều đáp án
You have decided to migrate your Compute Engine application to Google Kubernetes Engine. You need to build a container image and push it to Artifact Registry using Cloud Build. What should you do? (Choose two.)
  1. A Run gcloud builds submit in the directory that contains the application source code.
  2. B Run gcloud run deploy app-name --image gcr.io/$PROJECT_ID/app-name in the directory that contains the application source code.
  3. C Run gcloud container images add-tag gcr.io/$PROJECT_ID/app-name gcr.io/$PROJECT_ID/app-name:latest in the directory that contains the application source code.
  4. D In the application source directory, create a file named cloudbuild.yaml that contains the following contents:
    steps:
    - name: 'gcr.io/cloud-builders/docker'
      args: ['build', '-t', 'gcr.io/$PROJECT_ID/app-name', '.']
    - name: 'gcr.io/cloud-builders/docker'
      args: ['push', 'gcr.io/$PROJECT_ID/app-name']
  5. E In the application source directory, create a file named cloudbuild.yaml that contains the following contents:
    steps:
      - name: 'gcr.io/cloud-builders/gcloud'
        args: ['app', 'deploy']
        timeout: '1600s'
Xem giải thích

🧩 Giải thích nội dung câu hỏi

Câu hỏi yêu cầu xử lý việc migrate ứng dụng từ Compute Engine sang Google Kubernetes Engine (GKE), cụ thể là xây dựng container image từ source code và push lên Artifact Registry bằng Cloud Build. Đây là bước chuẩn bị image trước khi deploy lên GKE.
📌 Yêu cầu chọn HAI đáp án đúng (Choose two).
🛠️ Bối cảnh chính:

  • Sử dụng Cloud Build để automate build và push image.
  • Artifact Registry (hoặc Container Registry - gcr.io cho tương thích) là nơi lưu trữ image.
  • Giả sử thư mục chứa source code có Dockerfile sẵn.
    ✅ Kiến thức cập nhật (GCP 2026): Cloud Build hỗ trợ tự động detect Dockerfile khi dùng gcloud builds submit, hoặc tùy chỉnh qua cloudbuild.yaml. Artifact Registry thay thế Container Registry, nhưng gcr.io vẫn hoạt động (deprecated dần từ 2023, hết hạn 2025-2026). Tài liệu: Cloud Build docs, Artifact Registry quickstart.

✅ Đáp án đúng (Chọn hai)

  1. Run gcloud builds submit in the directory that contains the application source code.
    🏆 Lý do: Lệnh này tự động build image từ Dockerfile và push lên registry (gcr.io hoặc Artifact Registry nếu config). Đơn giản nhất cho migration.

  2. In the application source directory, create a file named cloudbuild.yaml that contains the following contents:

    steps:
    - name: 'gcr.io/cloud-builders/docker'
      args: ['build', '-t', 'gcr.io/$PROJECT_ID/app-name', '.']
    - name: 'gcr.io/cloud-builders/docker'
      args: ['push', 'gcr.io/$PROJECT_ID/app-name']
    

    🏆 Lý do: File cloudbuild.yaml định nghĩa pipeline rõ ràng: build image với tag gcr.io/$PROJECT_ID/app-name rồi push. Sau đó chạy gcloud builds submit để trigger.

📋 Phân tích chi tiết tất cả các phương án

Dưới đây là phân tích từng lựa chọn, giữ nguyên văn bản gốc tiếng Anh. Mỗi phương án được đánh giá ✅ (Đúng) hoặc ❌ (Sai), kèm giải thích lý do bằng tiếng Việt.

  • ✅ Run gcloud builds submit in the directory that contains the application source code.
    🧩 Giải thích đúng: Lệnh gcloud builds submit (tương đương gcloud builds submit --tag gcr.io/$PROJECT_ID/app-name) tự động phát hiện Dockerfile, build container image và push lên Artifact Registry/Container Registry. Hoàn hảo cho bước migrate sang GKE. Không cần file config thêm.
    📘 Nguồn: Cloud Build CLI reference.

  • ❌ Run gcloud run deploy app-name --image gcr.io/$PROJECT_ID/app-name in the directory that contains the application source code.
    ❌ Giải thích sai: Lệnh gcloud run deploy dùng để deploy service lên Cloud Run, không phải build/push image. Nó giả định image đã tồn tại, không thực hiện build từ source code. Không phù hợp cho GKE migration.

  • ❌ Run gcloud container images add-tag gcr.io/$PROJECT_ID/app-name gcr.io/$PROJECT_ID/app-name:latest in the directory that contains the application source code.
    ❌ Giải thích sai: Không tồn tại lệnh gcloud container images add-tag. Container Registry/Artifact Registry dùng gcloud container images add-tag cũ (deprecated), nhưng lệnh đúng là docker tag hoặc gcloud artifacts docker tags add. Không build image, chỉ tag lại, và không dùng Cloud Build.

  • ✅ In the application source directory, create a file named cloudbuild.yaml that contains the following contents:

    steps:
    - name: 'gcr.io/cloud-builders/docker'
      args: ['build', '-t', 'gcr.io/$PROJECT_ID/app-name', '.']
    - name: 'gcr.io/cloud-builders/docker'
      args: ['push', 'gcr.io/$PROJECT_ID/app-name']
    

    🧩 Giải thích đúng: Đây là config chuẩn cho Cloud Build: Step 1 build image từ . (Dockerfile hiện tại), Step 2 push lên gcr.io. Chạy gcloud builds submit sau để kích hoạt. Linh hoạt, hỗ trợ Artifact Registry (thay gcr.io bằng us-central1-docker.pkg.dev/...).
    📘 Nguồn: Cloud Build config file schema.

  • ❌ In the application source directory, create a file named cloudbuild.yaml that contains the following contents:

    steps:
    - name: 'gcr.io/cloud-builders/gcloud'
      args: ['app', 'deploy']
      timeout: '1600s'
    

    ❌ Giải thích sai: Config này dùng builder gcloud để chạy gcloud app deploy (deploy App Engine), không liên quan đến build/push container image cho GKE. Timeout 1600s chỉ cho App Engine, không phải Cloud Build Docker workflow.

🏁 Kết luận & Lời khuyên

🔥 Cách thực hiện hoàn chỉnh: Chọn hai đáp án ✅ đầu tiên. Sau push image, dùng gcloud container clusters get-credentials và kubectl apply để deploy lên GKE.
📚 Tài liệu tham khảo thêm:

Câu 99
You are developing an internal application that will allow employees to organize community events within your company. You deployed your application on a single Compute Engine instance. Your company uses Google Workspace (formerly G Suite), and you need to ensure that the company employees can authenticate to the application from anywhere. What should you do?
  1. A Add a public IP address to your instance, and restrict access to the instance using firewall rules. Allow your company's proxy as the only source IP address.
  2. B Add an HTTP(S) load balancer in front of the instance, and set up Identity-Aware Proxy (IAP). Configure the IAP settings to allow your company domain to access the website.
  3. C Set up a VPN tunnel between your company network and your instance's VPC location on Google Cloud. Configure the required firewall rules and routing information to both the on-premises and Google Cloud networks.
  4. D Add a public IP address to your instance, and allow traffic from the internet. Generate a random hash, and create a subdomain that includes this hash and points to your instance. Distribute this DNS address to your company's employees.
Xem giải thích

🧩 Phân tích nội dung câu hỏi

Câu hỏi mô tả tình huống phát triển một ứng dụng nội bộ trên Google Compute Engine (một instance duy nhất) để nhân viên công ty tổ chức sự kiện cộng đồng. Công ty sử dụng Google Workspace (trước đây là G Suite), và yêu cầu là đảm bảo nhân viên có thể xác thực (authenticate) vào ứng dụng từ bất kỳ đâu (anywhere), nghĩa là hỗ trợ truy cập từ xa an toàn mà không phụ thuộc vào mạng nội bộ.

📌 Mục tiêu chính: Cần giải pháp bảo mật, dễ sử dụng, tích hợp với Google Workspace để kiểm soát truy cập dựa trên danh tính (identity-based access), thay vì chỉ dựa vào IP hoặc VPN phức tạp. Giải pháp phải tuân thủ nguyên tắc zero-trust security của Google Cloud, cập nhật đến năm 2026 với Identity-Aware Proxy (IAP) phiên bản mới nhất hỗ trợ OAuth 2.0 và tích hợp sâu với Google Workspace.

✅ Đáp án đúng và lý do lựa chọn

Đáp án đúng: Add an HTTP(S) load balancer in front of the instance, and set up Identity-Aware Proxy (IAP). Configure the IAP settings to allow your company domain to access the website.

Lý do chọn đáp án này 🛠️:

  • Đây là giải pháp tốt nhất và được khuyến nghị bởi Google Cloud cho ứng dụng web nội bộ cần xác thực từ xa. HTTP(S) Load Balancer (phiên bản mới nhất Global External HTTP(S) LB hoặc Regional) đặt trước instance để xử lý traffic HTTPS, kết hợp IAP (Identity-Aware Proxy) kiểm tra danh tính người dùng trước khi cho phép truy cập backend.
  • IAP tích hợp trực tiếp với Google Workspace, chỉ cho phép domain công ty (ví dụ: @company.com) truy cập, hỗ trợ SSO (Single Sign-On) và MFA (Multi-Factor Authentication) từ bất kỳ đâu mà không cần VPN hay IP cố định.
  • ✅ Ưu điểm: Không expose public IP trực tiếp instance (giảm rủi ro), dễ scale, zero-trust, và tuân thủ best practices GCP 2026 (hỗ trợ IAP TCP forwarding cho non-HTTP nếu cần).
  • Nguồn tham khảo: Cloud IAP Overview & Secure App Access with IAP (cập nhật 2025-2026).

📋 Giải thích tất cả các phương án (đúng/sai)

Dưới đây là phân tích chi tiết từng lựa chọn, giữ nguyên văn bản gốc tiếng Anh. Mỗi phương án được đánh giá dựa trên tính khả thi, bảo mật, và phù hợp với yêu cầu "authenticate from anywhere" + tích hợp Google Workspace.

  • [SAI] Add a public IP address to your instance, and restrict access to the instance using firewall rules. Allow your company's proxy as the only source IP address.
    ❌ Giải thích sai: Phương án này expose public IP trực tiếp lên instance, chỉ giới hạn firewall bằng IP proxy công ty (như corporate proxy). Tuy nhiên, nhân viên từ "anywhere" (nhà riêng, di động) sẽ không qua proxy công ty, dẫn đến không thể truy cập. Không hỗ trợ xác thực danh tính Google Workspace, dễ bị tấn công nếu IP proxy leak. Không phải zero-trust, vi phạm best practices GCP.

  • [ĐÚNG] Add an HTTP(S) load balancer in front of the instance, and set up Identity-Aware Proxy (IAP). Configure the IAP settings to allow your company domain to access the website.
    ✅ Giải thích đúng: Như đã phân tích ở trên. Giải pháp hoàn hảo cho web app, IAP kiểm tra identity trước proxy traffic đến instance (không cần public IP instance), hỗ trợ truy cập toàn cầu qua Google Workspace domain. Scale tốt với load balancer mới nhất (2026: hỗ trợ QUIC/HTTP3).

  • [SAI] Set up a VPN tunnel between your company network and your instance's VPC location on Google Cloud. Configure the required firewall rules and routing information to both the on-premises and Google Cloud networks.
    ❌ Giải thích sai: VPN (Cloud VPN hoặc HA VPN phiên bản 2026) chỉ phù hợp cho truy cập từ mạng nội bộ công ty, không hỗ trợ "from anywhere" (nhân viên ngoài mạng công ty phải kết nối VPN thủ công, phức tạp). Không tích hợp trực tiếp xác thực Google Workspace cho app web, tốn kém setup routing/firewall hai bên, và không zero-trust (dựa trên network thay vì identity).

  • [SAI] Add a public IP address to your instance, and allow traffic from the internet. Generate a random hash, and create a subdomain that chỉ includes this hash and points to your instance. Distribute this DNS address to your company's employees.
    ❌ Giải thích sai: Expose public IP + traffic internet toàn mở là rủi ro bảo mật cao (dễ DDoS, brute-force). "Random hash subdomain" chỉ là obfuscation (che giấu) chứ không phải xác thực thực sự – bất kỳ ai có link cũng truy cập được, không kiểm tra danh tính Google Workspace. Không scale, không an toàn cho "authenticate from anywhere", vi phạm nguyên tắc least privilege.

Kết luận tổng quát 🎯: Giải pháp IAP + Load Balancer là chuẩn mực cho GCP internal apps năm 2026, giúp bảo mật cao mà dễ quản lý. Nếu cần thực hành, dùng GCP Console để enable IAP chỉ trong 5 phút! 📘

Câu 100
Your development team is using Cloud Build to promote a Node.js application built on App Engine from your staging environment to production. The application relies on several directories of photos stored in a Cloud Storage bucket named webphotos-staging in the staging environment. After the promotion, these photos must be available in a Cloud Storage bucket named webphotos-prod in the production environment. You want to automate the process where possible. What should you do?
  1. A Manually copy the photos to webphotos-prod.
  2. B Add a startup script in the application's app.yami file to move the photos from webphotos-staging to webphotos-prod.
  3. C Add a build step in the cloudbuild.yaml file before the promotion step with the arguments:
    - name: gcr.io/cloud-builders/gsutil
      args: ['cp', '-r', 'gs://webphotos-staging', 'gs://webphotos-prod']
      waitFor: ['-']
  4. D Add a build step in the cloudbuild.yaml file before the promotion step with the arguments:
    - name: gcr.io/cloud-builders/gcloud
      args: ['cp','-A', 'gs://webphotos-staging', 'gs://webphotos-prod']
      waitFor: ['-']
Xem giải thích

🧩 Phân tích nội dung câu hỏi

Câu hỏi mô tả một tình huống thực tế trong quy trình CI/CD trên Google Cloud Platform (GCP):
Đội ngũ phát triển đang sử dụng Cloud Build để triển khai (promote) một ứng dụng Node.js được xây dựng trên App Engine từ môi trường staging sang production. Ứng dụng này phụ thuộc vào nhiều thư mục ảnh lưu trữ trong bucket Cloud Storage tên webphotos-staging (môi trường staging). Sau khi promote, các ảnh này phải có sẵn trong bucket webphotos-prod (môi trường production).
Yêu cầu chính là tự động hóa quy trình càng nhiều càng tốt (automate the process where possible), nghĩa là tích hợp vào pipeline build mà không cần can thiệp thủ công.
🛠️ Mục tiêu: Copy toàn bộ nội dung (bao gồm thư mục con) từ bucket staging sang prod một cách tự động trong quá trình build bằng Cloud Build, trước bước promote ứng dụng.

✅ Đáp án đúng và lý do lựa chọn

Đáp án đúng:
Add a build step in the cloudbuild.yaml file before the promotion step with the arguments:

- name: gcr.io/cloud-builders/gsutil
  args: ['cp', '-r', 'gs://webphotos-staging', 'gs://webphotos-prod']
  waitFor: ['-']

Lý do chi tiết (dựa trên tài liệu GCP mới nhất đến 2026):

  • Cloud Build sử dụng file cloudbuild.yaml để định nghĩa các bước build (steps) theo thứ tự, cho phép tự động hóa toàn bộ pipeline.
  • Thêm bước gsutil (Google Cloud Storage utility) trước bước promote là cách tối ưu và tự động, copy recursive (-r) toàn bộ thư mục ảnh từ gs://webphotos-staging sang gs://webphotos-prod.
  • gcr.io/cloud-builders/gsutil là container builder chính thức của GCP cho gsutil (hỗ trợ từ Cloud Build v1 và vẫn chuẩn đến 2026).
  • waitFor: ['-'] đảm bảo bước này chạy song song nếu cần, nhưng ở đây là sequential trước promote.
  • Điều này đảm bảo ảnh sẵn sàng ngay khi app deploy prod, tránh downtime.
    📘 Nguồn tham khảo:
  • Cloud Build documentation - cloudbuild.yaml schema (cập nhật 2025).
  • gsutil cp command (hỗ trợ recursive copy buckets).

❌ Phân tích tất cả các phương án

Dưới đây là giải thích từng phương án một cách chi tiết, giữ nguyên nội dung gốc bằng tiếng Anh:

  • Manually copy the photos to webphotos-prod.
    ❌ Sai: Phương án này yêu cầu sao chép thủ công, không tự động hóa được quy trình CI/CD. Cloud Build được thiết kế để automate toàn bộ, việc manual sẽ gây lỗi con người, không scale và không phù hợp với "automate where possible".

  • Add a startup script in the application's app.yami file to move the photos from webphotos-staging to webphotos-prod.
    ❌ Sai: (Lưu ý: Có lẽ lỗi chính tả "app.yaml"). Startup script trong app.yaml của App Engine chỉ chạy khi instance khởi động (entrypoint), không phải trong build pipeline. Copy bucket lớn (nhiều thư mục ảnh) sẽ tốn thời gian, làm chậm cold start, và không đảm bảo chạy trước promote. Không dùng cho data migration giữa environments.

  • Add a build step in the cloudbuild.yaml file before the promotion step with the arguments:

    - name: gcr.io/cloud-builders/gsutil
      args: ['cp', '-r', 'gs://webphotos-staging', 'gs://webphotos-prod']
      waitFor: ['-']
    

    ✅ Đúng: Như đã giải thích ở trên, đây là cách chuẩn xác, tự động và hiệu quả nhất sử dụng gsutil trong Cloud Build để copy recursive toàn bộ bucket trước khi promote app.

  • Add a build step in the cloudbuild.yaml file before the promotion step with the arguments:

    - name: gcr.io/cloud-builders/gcloud
      args: ['cp','-A', 'gs://webphotos-staging', 'gs://webphotos-prod']
      waitFor: ['-']
    

    ❌ Sai: gcr.io/cloud-builders/gcloud là builder cho gcloud CLI, không hỗ trợ lệnh cp cho Cloud Storage (gsutil mới có). Flag -A là cho ACL (access control), không tồn tại cho copy bucket. Lệnh này sẽ bị lỗi runtime trong Cloud Build.

🛠️ Lời khuyên bổ sung: Trong thực tế (GCP 2026), có thể kết hợp với Cloud Build triggers để trigger auto trên Git push, và dùng IAM roles (Cloud Build Service Account cần Storage Object Admin) để tránh lỗi permission. Test bằng gcloud builds submit trước production!