Ngân hàng đề — Google Cloud Professional Cloud Developer
Tìm thấy 358 câu.
- A Configure a Vertical Pod Autoscaler (VPA) to increase the memory and CPU by 10% and set the updateMode to Auto.
- B Configure the Pod replica count to be 10% more than the current replica count.
- C Configure a Pod Disruption Budget (PDB) value to have a minAvailable value of 10%.
- D Configure the Horizontal Pod Autoscaler (HPA) maxReplicas value to 10% more than the current replica count.
Xem giải thích
🧩 Phân tích chi tiết câu hỏi
📖 Nội dung câu hỏi:
Câu hỏi xoay quanh một ứng dụng chạy trên GKE cluster (Google Kubernetes Engine), bao gồm một stateless web frontend với yêu cầu high-availability cao (tức là phải đảm bảo tính sẵn sàng cao, tránh downtime). Cluster được thiết lập auto-upgrade, dẫn đến việc một số node cần được drain (dọn sạch Pods để nâng cấp). Nhiệm vụ là đảm bảo ứng dụng có serving capacity tương đương 10% số Pods trước khi drain bắt đầu.
✅ Ý nghĩa cốt lõi:
- "Serving capacity of 10% of the Pods prior to the drain" nghĩa là cần overprovision (cung cấp dư thừa) dung lượng phục vụ thêm 10% số Pods hiện tại ngay trước khi quá trình drain node diễn ra. Điều này giúp bù đắp cho các Pods bị evict (xóa) trong lúc drain, duy trì high-availability mà không làm giảm capacity phục vụ.
- GKE auto-upgrade sẽ drain nodes theo thứ tự, tôn trọng các cơ chế như PDB, nhưng để đảm bảo dư capacity cụ thể 10%, cần điều chỉnh số lượng replicas thủ công trước.
- Đây là kịch bản thực tế trong GKE (phiên bản mới nhất 2026 vẫn giữ nguyên cơ chế drain với Kubernetes 1.30+).
🛠️ Bối cảnh kỹ thuật:
- Stateless app dễ scale bằng replicas.
- Node drain evict Pods không critical (không có PDB chặn), nên cần chủ động tăng replicas để buffer.
✅ Đáp án đúng
Configure the Pod replica count to be 10% more than the current replica count.
Lý do chọn đáp án này (chi tiết):
- 🟢 Việc tăng số lượng replicas Pods lên 10% so với hiện tại (ví dụ: từ 100 lên 110 Pods) đảm bảo trước khi drain, ứng dụng có dung lượng phục vụ dư thừa chính xác 10%. Khi drain evict một phần Pods (thường khoảng 10-20% tùy node size), capacity vẫn duy trì gần full mà không cần autoscaling tự động.
- Phù hợp với high-availability vì stateless frontend có thể nhanh chóng phân tải sang Pods dư thừa qua Service/LoadBalancer.
- Không phụ thuộc metric như HPA, mà là hành động chủ động prior to drain (trước drain).
- Trong GKE, Deployment/StatefulSet cho phép chỉnh
replicasdễ dàng quakubectl scalehoặc YAML.
📋 Giải thích tất cả các phương án
-
Configure a Vertical Pod Autoscaler (VPA) to increase the memory and CPU by 10% and set the updateMode to Auto.
❌ Sai. VPA chỉ tự động điều chỉnh tài nguyên CPU/memory của từng Pod (vertical scaling), không tăng số lượng Pods hay serving capacity theo số lượng. UpdateMode=Auto có thể restart Pods, gây gián đoạn không mong muốn trong drain. Không giải quyết "10% of the Pods" (dựa trên số lượng). -
Configure the Pod replica count to be 10% more than the current replica count.
✅ Đúng (như giải thích ở trên). Đây là cách trực tiếp, đơn giản và chính xác để overprovision capacity trước drain. -
Configure a Pod Disruption Budget (PDB) value to have a minAvailable value of 10%.
❌ Sai. PDB kiểm soát số Pods minimum available trong quá trình disrupt/drain (minAvailable=10% nghĩa là chấp nhận chỉ còn 10% Pods chạy, evict đến 90%). Điều này vi phạm high-availability vì capacity giảm mạnh còn 10%, trái ngược yêu cầu "serving capacity of 10%" (dư thừa, không phải minimum). PDB chỉ bảo vệ during drain, không tạo capacity prior. -
Configure the Horizontal Pod Autoscaler (HPA) maxReplicas value to 10% more than the current replica count.
❌ Sai. HPA tự động scale dựa trên metric (CPU/load), chỉ set giới hạn maxReplicas cao hơn 10% mà không đảm bảo scale up ngay lập tức prior to drain. Nếu metric thấp, replicas không tăng, dẫn đến thiếu buffer khi drain. Không chủ động như set replicas thủ công.
📘 Tài liệu tham khảo
- GKE Documentation (2026): Node auto-upgrade và drain – Giải thích drain tôn trọng replicas và PDB.
- Kubernetes Docs (v1.30+): Pod Disruption Budgets & Deployment replicas.
- Cert Guide (Professional Cloud Developer): Khuyến nghị overprovision replicas cho HA apps trên GKE (Google Cloud Skills Boost).
Hy vọng phân tích này giúp bạn nắm vững! 🚀 Nếu cần ví dụ kubectl, hãy hỏi thêm.
steps:
- name: python
entrypoint: pip
args: ["install", "-r", "requirements.txt", "--user"]
- name: python
entrypoint: python
args: ["-m", "pytest", "--junitxml=${SHORT_SHA}_test_log.xml"]
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'us-central1-docker.pkg.dev/${PROJECT_ID}/${_ARTIFACT_REGISTRY_REPO}/myimage:${SHORT_SHA}', '.']
- name: google/cloud-sdk
args: ['gcloud', 'run', 'deploy', 'helloworld-${SHORT_SHA}', '--image=us-central1-docker.pkg.dev/${PROJECT_ID}/${_ARTIFACT_REGISTRY_REPO}/myimage:${SHORT_SHA}', '--region', 'us-central1', '--platform', 'managed', '--allow-unauthenticated']
After triggering the pipeline, you notice in the Cloud Build logs that the final step of the pipeline fails and the container is unable to be deployed to Cloud Run. What is the cause of this issue, and how should you resolve it?
- A The final step uses a Cloud Run instance name that does not match the container name. Update the deployment step so that the Cloud Run instance name matches the container name, and rerun the pipeline.
- B The Docker container image has not been pushed to Artifact Registry. Add a step to the pipeline to push the application container image to Artifact Registry, and rerun the pipeline.
- C Cloud Run does not allow unauthenticated invocations. Remove the --allow-unauthenticated parameter to enforce authentication on the application, and rerun the pipeline.
- D Unit tests in the pipeline are failing. Update the application code so that all unit tests pass, and rerun the pipeline.
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ả một pipeline Cloud Build trên Google Cloud Platform (GCP) để containerize và deploy một ứng dụng Python lên Cloud Run. Pipeline bao gồm 4 bước chính:
- Bước 1 📦: Cài đặt các dependencies từ
requirements.txtbằngpip install. - Bước 2 🧪: Chạy unit tests bằng
pytestvà xuất kết quả XML. - Bước 3 🛠️: Build Docker image với tag chỉ định vào Artifact Registry (repository
_ARTIFACT_REGISTRY_REPOtrong project, regionus-central1), tag là${SHORT_SHA}(commit hash ngắn). - Bước 4 🚀: Deploy service Cloud Run tên
helloworld-${SHORT_SHA}sử dụng image vừa build, regionus-central1, platform managed, cho phép truy cập không xác thực (--allow-unauthenticated).
Vấn đề: Bước cuối cùng thất bại theo logs Cloud Build, container không deploy được lên Cloud Run. Nguyên nhân cốt lõi là image Docker chỉ được build local trong môi trường Cloud Build (bước 3), nhưng chưa được push lên Artifact Registry. Khi lệnh gcloud run deploy chạy, Cloud Run cố gắng pull image từ registry (Artifact Registry), nhưng image chưa tồn tại ở đó → lỗi pull thất bại.
Đây là quy trình chuẩn trên GCP (cập nhật đến 2026): Cloud Run bắt buộc image phải lưu trữ trên Container Registry hoặc Artifact Registry trước khi deploy. Không push → deploy fail.
📘 Tài liệu tham khảo:
- Cloud Build documentation - Docker steps
- Cloud Run deploy from Cloud Build
- Artifact Registry best practices
✅ Đáp án đúng
The Docker container image has not been pushed to Artifact Registry. Add a step to the pipeline to push the application container image to Artifact Registry, and rerun the pipeline.
Lý do chọn:
- Sau
docker build(bước 3), image chỉ tồn tại local trong container builder của Cloud Build, chưa upload lên Artifact Registry. - Lệnh
gcloud run deployyêu cầu image phải có sẵn trên registry để pull → fail. - Giải quyết: Thêm bước push ngay sau build, ví dụ:
- name: 'gcr.io/cloud-builders/docker' args: ['push', 'us-central1-docker.pkg.dev/${PROJECT_ID}/${_ARTIFACT_REGISTRY_REPO}/myimage:${SHORT_SHA}'] - Rerun pipeline → thành công. Đây là best practice GCP mới nhất (2026).
❌ Phân tích tất cả các phương án
-
[SAI] The final step uses a Cloud Run instance name that does not match the container name. Update the deployment step so that the Cloud Run instance name matches the container name, and rerun the pipeline.
Giải thích sai: Tên Cloud Run service (helloworld-${SHORT_SHA}) và image name (myimage:${SHORT_SHA}) không cần phải giống nhau. Cloud Run chỉ cần image tag hợp lệ từ registry. Vấn đề không phải mismatch tên, mà là image chưa push → không pull được. Không fix được lỗi deploy. -
[ĐÚNG] The Docker container image has not been pushed to Artifact Registry. Add a step to the pipeline to push the application container image to Artifact Registry, and rerun the pipeline.
Giải thích đúng: Như phần trên, image build local chưa push → Cloud Run không tìm thấy image trên Artifact Registry khi deploy. Thêmdocker pushlà fix chuẩn xác, phù hợp quy trình CI/CD GCP. -
[SAI] Cloud Run does not allow unauthenticated invocations. Remove the --allow-unauthenticated parameter to enforce authentication on the application, and rerun the pipeline.
Giải thích sai: Cloud Run hoàn toàn hỗ trợ--allow-unauthenticatedcho public access (mặc định yêu cầu auth, nhưng flag này override ok). Logs chỉ fail ở deploy container, không liên quan auth. Xóa flag còn làm app private hơn, không fix vấn đề pull image. -
[SAI] Unit tests in the pipeline are failing. Update the application code so that all unit tests pass, and rerun the pipeline.
Giải thích sai: Logs chỉ rõ bước cuối (deploy) fail, không phải pytest (bước 2). Nếu tests fail, pipeline dừng sớm ở bước 2, không chạy đến bước 4. Vấn đề là push image, không phải code tests.
💡 Lời khuyên: Luôn thêm docker push sau docker build trong Cloud Build cho Cloud Run. Sử dụng substitutions như ${_ARTIFACT_REGISTRY_REPO} để linh hoạt! 🚀
- A Use Terraform on GKE. Create a Kubernetes service account to execute the Terraform code. Use workload identity federation to authenticate as the Google service account.
- B Install Terraform on a Compute Engine VM. Configure the VM by using a service account that has the required permissions to manage the Google Cloud resources.
- C Configure Terraform Cloud to use workload identity federation to authenticate to the Google Cloud APIs.
- D Create a service account that has the required permissions to manage the Google Cloud resources, and import the service account key to Terraform Cloud. Use this service account to authenticate to the Google Cloud APIs.
Xem giải thích
🧩 Phân tích nội dung câu hỏi
Câu hỏi tập trung vào việc cấu hình pipeline Infrastructure as Code (IaC) sử dụng Terraform Cloud để quản lý tài nguyên Google Cloud một cách an toàn nhất (most secure approach) và tối thiểu hóa thay đổi cấu hình (minimize changes).
- Bối cảnh: Nhóm hạ tầng đang sử dụng Terraform Cloud (dịch vụ của HashiCorp) để quản lý tài nguyên GCP qua các file cấu hình Terraform.
- Yêu cầu chính: Cần xác thực (authenticate) với Google Cloud APIs cho pipeline IaC, ưu tiên bảo mật cao (không dùng key dễ leak) và giữ nguyên cách sử dụng Terraform Cloud hiện tại.
- Mục tiêu: Tìm phương pháp xác thực bảo mật nhất, tận dụng các tính năng native của GCP như Workload Identity Federation (WIF) – một cơ chế không dùng service account key, mà sử dụng OIDC token để impersonate service account, giảm rủi ro lộ key.
- Liên quan kiến thức GCP mới nhất (2026): Terraform Cloud hỗ trợ tích hợp trực tiếp WIF từ phiên bản 1.5+ của provider Google (google-beta), theo best practice từ Google Cloud và HashiCorp. Tránh service account key vì vi phạm nguyên tắc "least privilege" và tăng bề mặt tấn công. 🛡️
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng: Configure Terraform Cloud to use workload identity federation to authenticate to the Google Cloud APIs.
Lý do:
- Đây là cách bảo mật nhất vì Terraform Cloud (chạy trên cloud của HashiCorp) có thể sử dụng Workload Identity Federation (WIF) để tạo OIDC token, impersonate service account GCP mà không cần lưu trữ service account key (tránh rủi ro leak, rotation thủ công).
- Tối thiểu hóa thay đổi: Không cần migrate sang GKE/VM, giữ nguyên Terraform Cloud hiện tại. Chỉ cần cấu hình provider block trong Terraform với
workload_identity_providervàuse_terraform_cloud_workload_identity_federation. - Phù hợp best practice GCP 2026: WIF là khuyến nghị chính thức cho external workloads như Terraform Cloud. 📘
📋 Giải thích chi tiết tất cả các phương án
-
[SAI] Use Terraform on GKE. Create a Kubernetes service account to execute the Terraform code. Use workload identity federation to authenticate as the Google service account.
❌ Sai vì yêu cầu thay đổi lớn: Phải migrate từ Terraform Cloud sang chạy Terraform trực tiếp trên GKE (tạo cluster, pod, service account), vi phạm "minimize changes". WIF trên GKE tốt nhưng không tận dụng Terraform Cloud sẵn có. Không phải "most secure" trong ngữ cảnh này. -
[SAI] Install Terraform on a Compute Engine VM. Configure the VM by using a service account that has the required permissions to manage the Google Cloud resources.
❌ Sai vì kém bảo mật và thay đổi lớn: Attach service account trực tiếp vào VM (dùng metadata server) dễ bị tấn công nếu VM compromise. Phải setup VM mới, install Terraform, migrate pipeline – trái với "minimize changes". Không dùng WIF, kém hơn so với federation. -
[ĐÚNG] Configure Terraform Cloud to use workload identity federation to authenticate to the Google Cloud APIs.
✅ Đúng hoàn toàn (như giải thích ở trên): Tích hợp native, short-lived credentials qua OIDC, zero key management. Hỗ trợ đầy đủ từ Terraform Cloud v2023+ với GCP provider v5.0+. -
[SAI] Create a service account that has the required permissions to manage the Google Cloud resources, and import the service account key to Terraform Cloud. Use this service account to authenticate to the Google Cloud APIs.
❌ Sai vì kém bảo mật: Service account key là JSON file dễ leak (qua repo, log), phải rotate định kỳ, vi phạm principle of least privilege. Google khuyến cáo KHÔNG dùng key cho production từ 2021, thay bằng WIF/OIDC. Terraform Cloud hỗ trợ nhưng không "most secure".
📚 Tài liệu tham khảo
- HashiCorp Terraform Cloud Docs: Workload Identity Federation with Google Cloud (cập nhật 2025).
- Google Cloud Docs: Workload Identity Federation for external identities (best practice 2026).
- Terraform Google Provider: workload_identity_federation block (v6.0+).
Hy vọng phân tích giúp bạn ôn thi hiệu quả! 🚀
- A Use Cloud Service Mesh with sidecar proxies to connect the application to the REST service.
- B Use Cloud Service Mesh with proxyless gRPC to connect the application to the REST service.
- C Configure the REST service's firewall to allow health checks originating from the GKE service’s IP ranges.
- D Configure the REST service's firewall to allow health checks originating from the GKE control plane’s IP ranges.
- E Configure the REST service's firewall to allow health checks originating from the GKE check probe’s IP ranges.
Xem giải thích
🧩 Phân tích nội dung câu hỏi
Câu hỏi tập trung vào việc thiết lập kết nối giữa một ứng dụng chạy trên GKE cluster với một REST service được triển khai trên hai GKE clusters ở hai vùng (regions) khác nhau. Đồng thời, cần cấu hình health checks (kiểm tra sức khỏe) để đảm bảo kết nối ổn định và đáng tin cậy.
✅ Yêu cầu chọn hai phương án đúng từ các lựa chọn, sử dụng các tính năng của Google Kubernetes Engine (GKE) và Cloud Service Mesh (trước đây là Anthos Service Mesh, cập nhật đến phiên bản mới nhất năm 2026).
🛠️ Bối cảnh chính:
- Ứng dụng cần giao tiếp cross-cluster và cross-region (ví dụ: từ us-central1 sang europe-west1).
- Kết nối: Sử dụng service mesh để quản lý traffic mTLS, routing, và discovery.
- Health checks: Kubernetes probes (liveness/readiness) chạy từ các IP ranges cụ thể của GKE, cần mở firewall cho traffic cross-cluster.
📘 Tài liệu tham khảo: - Cloud Service Mesh overview (cập nhật 2026).
- GKE health check probes IP ranges.
- Multi-cluster services with Cloud Service Mesh.
✅ Đáp án đúng (chọn hai)
Hai phương án đúng là:
- Use Cloud Service Mesh with sidecar proxies to connect the application to the REST service.
- Configure the REST service's firewall to allow health checks originating from the GKE check probe’s IP ranges.
Lý do lựa chọn:
🛠️ Phương án 1: Cloud Service Mesh (dựa trên Istio) với sidecar proxies (Envoy) là cách chuẩn để kết nối REST service (HTTP/RESTful) cross-cluster/region. Nó cung cấp service discovery, mTLS, traffic splitting, và observability mà không cần thay đổi code ứng dụng. Phù hợp cho REST vì sidecar hỗ trợ HTTP/1.1 và HTTP/2 đầy đủ.
🛠️ Phương án 2: Health checks (Kubernetes probes) trong GKE cross-cluster yêu cầu firewall rules mở cho GKE check probe’s IP ranges (130.211.0.0/22 và 35.191.0.0/16). Điều này đảm bảo probes từ cluster nguồn có thể kiểm tra readiness/liveness của service đích mà không bị chặn. Không có cách nào khác hiệu quả hơn cho multi-cluster setup.
📘 Xác nhận: Theo docs GCP 2026, đây là best practice cho GKE multi-cluster với Service Mesh.
📋 Giải thí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 một cách rõ ràng (giữ nguyên văn bản gốc tiếng Anh, chỉ giải thích bằng tiếng Việt):
✅ Use Cloud Service Mesh with sidecar proxies to connect the application to the REST service.
Đúng 🟢: Đây là giải pháp kết nối lý tưởng cho REST service cross-region. Sidecar proxies (Envoy) được inject vào pods, xử lý toàn bộ traffic outbound/inbound, hỗ trợ HTTP routing và security. Không cần sidecar sẽ khó scale và secure traffic multi-cluster.
❌ Use Cloud Service Mesh with proxyless gRPC to connect the application to the REST service.
Sai 🔴: Proxyless gRPC chỉ dành cho gRPC clients (không proxy), không hỗ trợ REST/HTTP thuần. REST service dùng HTTP protocol, nên proxyless sẽ fail vì thiếu Envoy để translate và route. Chỉ dùng cho gRPC-native workloads.
❌ Configure the REST service's firewall to allow health checks originating from the GKE service’s IP ranges.
Sai 🔴: Không tồn tại khái niệm "GKE service’s IP ranges" chính thức. Service IPs là ClusterIP/NodePort/LoadBalancer IPs nội bộ, không dùng cho probes cross-cluster. Mở sai range sẽ không block/unblock đúng probes.
❌ Configure the REST service's firewall to allow health checks originating from the GKE control plane’s IP ranges.
Sai 🔴: GKE control plane (master nodes) chỉ xử lý API server traffic (https:443), không originate probes. Probes chạy từ kubelet trên worker nodes, dùng IP ranges riêng (không phải control plane như 10.x.x.x hoặc regional masters).
✅ Configure the REST service's firewall to allow health checks originating from the GKE check probe’s IP ranges.
Đúng 🟢: GKE check probe’s IP ranges (130.211.0.0/22 & 35.191.0.0/16) là nguồn gốc thực tế của liveness/readiness probes cross-cluster. Firewall VPC rules phải allow TCP/HTTP từ ranges này đến service ports để health checks pass, đặc biệt với multi-cluster Service Mesh.
Kết luận 🎯: Setup này đảm bảo kết nối an toàn, observable và health checks reliable theo best practices GCP 2026! Nếu cần code sample hoặc Terraform, hãy hỏi thêm. 🚀
-
A
1. Use Cloud Composer to manage the connection to the Cloud SQL database from your Python application.
2. Grant an IAM role to the service account that includes the composer.worker permission. -
B
1. Use the Cloud SQL API to connect to the Cloud SQL database from your Python application.
2. Grant an IAM role to the service account that includes the cloudsql.instances.login permission. -
C
1. Use the Cloud SQL connector library for Python to connect to the Cloud SQL database through a Cloud SQL Auth Proxy.
2. Grant an IAM role to the service account that includes the cloudsql.instances.connect permission. -
D
1. Use the Cloud SQL emulator to connect to the Cloud SQL database from Cloud Shell
2. Grant an IAM role to the user that includes the cloudsql.instances.login permission.
Xem giải thích
🧩 Phân tích nội dung câu hỏi
Câu hỏi tập trung vào việc phát triển một API sử dụng Python 3 phiên bản ổn định mới nhất (tính đến 2026, là Python 3.12+), lưu trữ dữ liệu trong Cloud SQL database (dịch vụ cơ sở dữ liệu quan hệ managed của Google Cloud, hỗ trợ MySQL, PostgreSQL, SQL Server). Yêu cầu chính là thực hiện CRUD operations (Create, Read, Update, Delete) trên production database một cách bảo mật (secure), đáng tin cậy (reliable) và tối thiểu công sức (minimal effort).
🔍 Bối cảnh quan trọng:
- Đây là môi trường production, nên cần tránh hardcode credentials (như username/password), ưu tiên IAM-based authentication để tránh rủi ro bảo mật.
- Minimal effort nghĩa là sử dụng thư viện/client chính thức của Google Cloud, hỗ trợ kết nối tự động, retry logic và tích hợp dễ dàng với SQLAlchemy/pure Python DB-API.
- Kiến thức cập nhật 2026: Google Cloud khuyến nghị Cloud SQL Python Connector library (ra mắt 2023, phiên bản 1.10+ năm 2026) kết hợp Cloud SQL Auth Proxy cho kết nối serverless/on-prem, hoặc Serverless Connector cho Cloud Run/Functions với IAM role
roles/cloudsql.client(bao gồmcloudsql.instances.connect).
📘 Nguồn tham khảo:
- Cloud SQL Python Connector Docs (cập nhật 2026).
- Cloud SQL Auth Proxy IAM Permissions.
- Best Practices for Production DB Access.
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng là phương án thứ 3:
- Use the Cloud SQL connector library for Python to connect to the Cloud SQL database through a Cloud SQL Auth Proxy.
- Grant an IAM role to the service account that includes the cloudsql.instances.connect permission.
Lý do chọn 🛠️:
- Cloud SQL connector library (gói
cloud-sql-python-connector) là thư viện chính thức, hỗ trợ kết nối qua Cloud SQL Auth Proxy (trước là Cloud SQL Proxy, phiên bản 2026 tích hợp tốt hơn với ephemeral certificates). Nó cho phép CRUD operations an toàn với Unix socket/TCP, tự động quản lý SSL, connection pooling và retry – minimal effort chỉ cần vài dòng code. - Permission
cloudsql.instances.connect(trong roleroles/cloudsql.client) cho phép service account generate short-lived certs mà không cần DB credentials, đảm bảo secure & reliable cho production API (hỗ trợ GCE, Cloud Run, Kubernetes). - Đây là best practice từ Google, giảm thiểu config so với proxy thủ công.
📋 Giải thích tất cả các phương án
Dưới đây là phân tích chi tiết từng lựa chọn, với ✅ đúng hoặc ❌ sai, giữ nguyên văn bản gốc:
-
❌ Phương án 1 (SAI):
- Use Cloud Composer to manage the connection to the Cloud SQL database from your Python application.
- Grant an IAM role to the service account that includes the composer.worker permission.
Giải thích sai ❌: Cloud Composer là dịch vụ orchestration workflow (dựa Apache Airflow), dùng cho ETL/batch jobs, KHÔNG phù hợp cho API real-time CRUD. Permissioncomposer.workerchỉ cho worker nodes của Composer, không liên quan kết nối DB trực tiếp từ app Python. Sử dụng sẽ phức tạp hóa (overkill), không minimal effort và kém reliable cho production API.
-
❌ Phương án 2 (SAI):
- Use the Cloud SQL API to connect to the Cloud SQL database from your Python application.
- Grant an IAM role to the service account that includes the cloudsql.instances.login permission.
Giải thích sai ❌: Cloud SQL API (REST API) chỉ dùng để quản lý instances (create, backup, scale), KHÔNG dùng cho CRUD data (không execute SQL queries). Permissioncloudsql.instances.logindành cho user-based login (deprecated, không khuyến khích cho service accounts), không hỗ trợ connector library. Cách này không secure/reliable cho production và yêu cầu effort cao hơn.
-
✅ Phương án 3 (ĐÚNG):
- Use the Cloud SQL connector library for Python to connect to the Cloud SQL database through a Cloud SQL Auth Proxy.
- Grant an IAM role to the service account that includes the cloudsql.instances.connect permission.
Giải thích đúng ✅: Như đã nêu ở trên, đây là cách chuẩn xác nhất năm 2026, hỗ trợ IAM auth thuần túy, tránh IP whitelisting/passwords. Code ví dụ:pip install cloud-sql-python-connector, rồi dùngconnector.connect()với proxy. Hoàn hảo cho secure, reliable CRUD với minimal config (chỉ 1 IAM role).
-
❌ Phương án 4 (SAI):
- Use the Cloud SQL emulator to connect to the Cloud SQL database from Cloud Shell.
- Grant an IAM role to the user that includes the cloudsql.instances.login permission.
Giải thích sai ❌: Cloud SQL emulator chỉ là tool local dev/testing (chạy trong Docker), KHÔNG kết nối production DB. Cloud Shell là môi trường tạm thời, không dùng cho API production. Permissioncloudsql.instances.logindành cho user login (không phải service account), kém secure và không reliable (không scale). Hoàn toàn không minimal effort cho real-world API.
🏆 Kết luận: Chọn phương án 3 để đạt hiệu suất cao nhất theo docs GCP 2026! Nếu deploy trên Cloud Run, kết hợp Serverless Connector còn đơn giản hơn nữa.
- A Create a BigQuery dataset and table to act as the internal database. Query the table when user requests are received.
- B Create a Memorystore for Redis instance to store all stock market data. Query this database when user requests are received.
- C Create a Bigtable instance. Query the table when user requests are received. Configure a Pub/Sub topic to queue user requests that your API will respond to.
- D Create a Memorystore for Redis instance, and use this database to store the most accessed stock data. Query this instance first when user requests are received, and fall back to the internal database.
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ế: Công ty đang quản lý ứng dụng thu thập dữ liệu chứng khoán (stock data) vào một database nội bộ. Nhiệm vụ là xây dựng một API cung cấp dữ liệu chứng khoán thời gian thực (real-time) cho người dùng. Yêu cầu chính là:
- Trả về dữ liệu nhanh nhất có thể (low latency, ưu tiên tốc độ truy vấn).
- Giải pháp phải highly scalable (mở rộng linh hoạt theo lưu lượng truy cập cao, đặc biệt với dữ liệu chứng khoán biến động nhanh). 📘 Bối cảnh GCP (Google Cloud Platform): Đây là bài toán caching và optimization cho API real-time trên GCP, sử dụng các dịch vụ như Memorystore for Redis (managed Redis), BigQuery, Bigtable, Pub/Sub. Dữ liệu nội bộ có thể chậm nếu query trực tiếp, nên cần layer cache để tăng tốc.
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng: Create a Memorystore for Redis instance, and use this database to store the most accessed stock data. Query this instance first when user requests are received, and fall back to the internal database.
🛠️ Lý do chọn đáp án này:
- Memorystore for Redis là dịch vụ managed in-memory của GCP (cập nhật đến 2026: hỗ trợ Redis 7.x với clustering, multi-zone replication cho high availability và scalability tự động).
- Sử dụng Redis làm cache layer cho dữ liệu truy cập nhiều nhất (most accessed stock data) – phù hợp real-time stock data vì Redis có latency <1ms, throughput hàng triệu QPS.
- Query Redis trước, fallback về internal DB: Đây là cache-aside pattern chuẩn (write-through hoặc read-through), giảm tải DB nội bộ, đảm bảo low latency ngay cả khi traffic spike.
- Scalable cao: Redis cluster auto-scale theo CPU/RAM, tích hợp seamless với Compute Engine/App Engine/Cloud Run cho API.
- Phù hợp nhất cho real-time API vì ưu tiên speed mà không thay thế hoàn toàn DB nội bộ (tránh tốn kém lưu all data in-memory).
📘 Tài liệu tham khảo:
- Memorystore for Redis docs (GCP, updated 2025).
- Caching strategies on GCP – khuyến nghị Redis cho low-latency workloads.
🔍 Giải thí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 một cách logic, dựa trên kiến thức GCP mới nhất (2026: Memorystore hỗ trợ Redis OSS 7.2 với vector search; Bigtable v2 với codeless schema).
-
Create a BigQuery dataset and table to act as the internal database. Query the table when user requests are received.
❌ Sai vì: BigQuery là data warehouse OLAP (optimized cho analytics, batch queries), không phải real-time OLTP. Latency query thường 1-10 giây (thậm chí streaming insert chậm), không phù hợp "as quickly as possible". Scalable cho big data nhưng overkill và chậm cho stock API (traffic real-time cao). Không thay thế internal DB hiệu quả. -
Create a Memorystore for Redis instance to store all stock market data. Query this database when user requests are received.
❌ Sai vì: Lưu tất cả (all) stock market data vào Redis là không thực tế – dữ liệu chứng khoán toàn cầu khổng lồ (terabytes, biến động liên tục), tốn kém chi phí (RAM đắt), khó scale (hit memory limit nhanh). Không fallback, rủi ro data loss nếu Redis down. GCP khuyến nghị Redis chỉ cho hot data (top accessed), không phải full dataset. -
Create a Bigtable instance. Query the table when user requests are received. Configure a Pub/Sub topic to queue user requests that your API will respond to.
❌ Sai vì: Bigtable là NoSQL wide-column tốt cho high-throughput (millions QPS), nhưng latency ~10-50ms (không phải sub-ms như Redis). Pub/Sub queue requests làm chậm thêm (async processing, polling delay), trái ngược "return data as quickly as possible". Phù hợp IoT/big data ingestion, không phải real-time API direct query. Scalable nhưng thêm latency không cần thiết.
🧩 Tóm tắt so sánh: | Đặc điểm | BigQuery | Redis (all data) | Bigtable + Pub/Sub | Redis cache + fallback | |----------|----------|------------------|--------------------|----------------------------| | Latency | Cao (giây) | Thấp | Trung bình + queue | Thấp nhất (<1ms) | | Scalability | Batch cao | Giới hạn RAM | Cao | Tự động + hybrid | | Phù hợp real-time | ❌ | ❌ (chi phí) | ❌ (queue) | ✅ |
Giải pháp đúng cân bằng performance + cost + reliability trên GCP! 🚀
- A Configure the Cloud Run service to use HTTP/2. Implement gRPC for communication between the microservices. Use streaming gRPCs when a large amount of data has to be sent.
- B Implement the microservices with the REST API communication protocol. Use Apigee with rate-limiting to provide the best QoS for high-priority services.
- C Use SOAP to build the microservices API, and use XML as the data format for communication across the microservices. Define SOAP data contracts for each microservice.
- D Use HTTP REST to communicate across the microservices. Implement pagination and add indexing to your database.
Xem giải thích
🧩 Phân tích nội dung câu hỏi
Câu hỏi tập trung vào việc thiết kế kiến trúc microservices cho một ứng dụng mới được triển khai trên Cloud Run (dịch vụ serverless của Google Cloud Platform - GCP). Ứng dụng cần giao tiếp nội bộ giữa các microservices với throughput cao (lượng dữ liệu lớn/giây) và độ trễ thấp nhất (lowest latency).
Yêu cầu chính: Chọn giao thức giao tiếp hiệu quả nhất, phù hợp với môi trường Cloud Run.
Cloud Run hỗ trợ các protocol hiện đại như HTTP/2 và gRPC (dựa trên HTTP/2), giúp tối ưu cho microservices nội bộ nhờ binary serialization (Protobuf), multiplexing, và streaming. Điều này đặc biệt quan trọng cho high-throughput mà không cần proxy bên ngoài. (Kiến thức cập nhật đến 2026: Cloud Run fully supports gRPC over HTTP/2 từ phiên bản 2023+).
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng: Configure the Cloud Run service to use HTTP/2. Implement gRPC for communication between the microservices. Use streaming gRPCs when a large amount of data has to be sent.
Lý do:
🛠️ gRPC là protocol lý tưởng cho microservices nội bộ trên Cloud Run vì:
- Dựa trên HTTP/2 (hỗ trợ multiplexing, header compression, binary framing) → giảm latency đáng kể so với HTTP/1.1.
- Sử dụng Protocol Buffers (Protobuf) → serialization nhanh, compact hơn JSON/XML.
- Streaming gRPC (bidirectional hoặc server/client streaming) xử lý dữ liệu lớn hiệu quả, tránh block và giảm latency cho high-throughput.
Cloud Run tự động hỗ trợ gRPC mà không cần config thêm (từ 2021, ổn định đến 2026). Đây là best practice cho internal communication theo tài liệu GCP.
📋 Giải thí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 bằng tiếng Anh. Mỗi phương án được đánh giá ✅ (đúng) hoặc ❌ (sai), kèm lý do cụ thể:
-
Configure the Cloud Run service to use HTTP/2. Implement gRPC for communication between the microservices. Use streaming gRPCs when a large amount of data has to be sent.
✅ Đúng hoàn toàn (như đã giải thích ở trên). Đây là giải pháp tối ưu nhất cho low-latency và high-throughput nội bộ trên Cloud Run. -
Implement the microservices with the REST API communication protocol. Use Apigee with rate-limiting to provide the best QoS for high-priority services.
❌ Sai: REST thường dùng HTTP/1.1 (text-based JSON), gây latency cao hơn do serialization chậm và không multiplexing. Apigee (API gateway của GCP) phù hợp cho external APIs với rate-limiting/QoS, nhưng thêm overhead cho internal microservices → không hiệu quả cho high-throughput nội bộ. -
Use SOAP to build the microservices API, and use XML as the data format for communication across the microservices. Define SOAP data contracts for each microservice.
❌ Sai nghiêm trọng: SOAP/XML là protocol cũ kỹ, verbose (dữ liệu lớn, parsing chậm) → latency rất cao, không phù hợp microservices hiện đại. Cloud Run hỗ trợ kém SOAP, và nó không tối ưu cho high-throughput (thường dùng cho enterprise legacy). -
Use HTTP REST to communicate across the microservices. Implement pagination and add indexing to your database.
❌ Sai: HTTP REST (thường HTTP/1.1) không phải lowest latency vì thiếu binary efficiency và multiplexing. Pagination/indexing chỉ tối ưu database queries, không giải quyết vấn đề giao tiếp network giữa microservices → không đáp ứng yêu cầu protocol low-latency.
📘 Tài liệu tham khảo
- Google Cloud Run Documentation: Cloud Run gRPC support (cập nhật 2025: Full HTTP/2 + streaming).
- gRPC on GCP: Best practices for microservices (2024+).
- So sánh protocols: GCP Architecture Framework (2026 edition) khuyến nghị gRPC > REST cho internal services.
Hy vọng phân tích này giúp bạn ôn thi chứng chỉ Professional Cloud Developer! 🚀 Nếu cần thêm ví dụ code, hãy hỏi nhé!
- A Ask the SRE team to enable Managed Service for Prometheus on your GKE cluster.
- B Reconfigure your applications to write logs to an emptyDir volume. Configure a sidecar agent to read the logs and send them to the Cloud Logging API.
- C Update your microservices code to emit logs in JSON format.
- D Instrument your microservices code with OpenTelemetry libraries.
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 cải thiện khả năng indexing (chỉ mục hóa) và searchability (tìm kiếm) của logs trong Cloud Logging cho ứng dụng microservices chạy trên GKE (Google Kubernetes Engine).
- Bối cảnh: Công ty đã chuyển từ monolith ecommerce sang microservices trên GKE, sử dụng Google Cloud's Operations Suite (trước đây là Stackdriver) để monitor và log.
- Mục tiêu: Tối ưu logs với ít effort (nỗ lực) nhất để logs dễ tìm kiếm hơn, ví dụ qua các trường dữ liệu có cấu trúc thay vì text thuần.
- Vấn đề cốt lõi: Logs mặc định từ containers trong GKE thường là unstructured (text đơn giản), khó index và query. Cần structured logs để Cloud Logging tự động parse, index các trường như timestamp, severity, message... giúp query nhanh hơn qua Logs Explorer. 📈
📘 Tài liệu tham khảo:
- Cloud Logging Structured Logging (cập nhật 2024-2026: Hỗ trợ JSON payload tự động parse trong GKE via Cloud Operations for GKE agent).
- GKE Logging Best Practices (phiên bản mới nhất khuyến nghị JSON cho microservices).
✅ Đáp án đúng: Update your microservices code to emit logs in JSON format.
Lý do lựa chọn (bằng tiếng Việt):
Đây là giải pháp ít effort nhất vì chỉ cần thay đổi code ứng dụng để output logs dưới dạng JSON structured (ví dụ: {"severity": "ERROR", "message": "User login failed", "userId": 123}), mà không cần config thêm agent hay dịch vụ. GKE's Logging agent (dựa trên Fluent Bit/Fluentd) sẽ tự động detect và parse JSON, lưu vào Cloud Logging với các trường indexed sẵn. Kết quả: Searchability tăng cao (query bằng jsonPayload.userId="123"), không downtime, dễ implement cho microservices. Hoàn hảo cho least effort! 🚀
🔍 Giải thích tất cả các phương án (đúng/sai)
-
❌ [SAI] Ask the SRE team to enable Managed Service for Prometheus on your GKE cluster.
Phương án này sai hoàn toàn vì Managed Service for Prometheus (MSP) chỉ dùng cho metrics và monitoring (như CPU, memory), không liên quan đến logs. Nó không cải thiện indexing/search logs trong Cloud Logging. Việc yêu cầu SRE team còn tăng effort không cần thiết. 🛑 -
❌ [SAI] Reconfigure your applications to write logs to an emptyDir volume. Configure a sidecar agent to read the logs and send them to the Cloud Logging API.
Phương án sai và effort cao: Phải reconfigure app viết logs vàoemptyDir(volume tạm thời), thêm sidecar container (như Fluentd sidecar) để đọc và push lên API. Điều này phức tạp, dễ lỗi (volume mất khi pod restart), tăng CPU/network overhead, không phải "least effort". GKE đã có agent tự động rồi! ⚠️ -
✅ [ĐÚNG] Update your microservices code to emit logs in JSON format.
Như đã giải thích ở trên: Đúng và optimal vì tận dụng native support của Cloud Logging/GKE cho structured JSON, chỉ edit code đơn giản (hỗ trợ mọi ngôn ngữ như Node.js, Java, Python via libraries như Winston, Log4j). Indexing tự động, search nhanh, zero thêm config. 🌟 -
❌ [SAI] Instrument your microservices code with OpenTelemetry libraries.
Phương án sai ở ngữ cảnh least effort: OpenTelemetry (OTel) tuyệt vời cho distributed tracing/metrics/logs (chuẩn mở, tích hợp Cloud Trace/Logging), nhưng phải instrument toàn bộ code (thêm SDK, export config), phức tạp hơn nhiều so với chỉ JSON logs. Không cần thiết nếu chỉ cải thiện logs searchability. Phù hợp hơn cho full observability sau này. 🧪
- A Use estimation to extrapolate performance from summary monitoring charts.
- B Analyze the log data in BigQuery by configuring a BigQuery log sink with the appropriate inclusion filter for your application.
- C Use Cloud Monitoring’s default log console for analysis.
- D Analyze the log data in Cloud SQL for PostgreSQL by pushing logs to a Pub/Sub topic. Use Dataflow to process and ingest the logs.
Xem giải thích
🧩 Phân tích nội dung câu hỏi
Câu hỏi tập trung vào việc thực hiện load test cho ứng dụng chạy trên Cloud Run (dịch vụ serverless của Google Cloud để deploy containerized apps). Mục tiêu là phân tích logs theo từng giây (second-by-second) để hiểu phản ứng của service trước các traffic spike đột ngột (tăng tải nhanh). Yêu cầu chính: tối thiểu hóa effort (công sức triển khai và phân tích).
📘 Bối cảnh kỹ thuật (cập nhật đến 2026): Cloud Run tự động ghi logs vào Cloud Logging (trước đây là Stackdriver Logging). Để phân tích chi tiết thời gian thực (second-by-second), cần export logs sang công cụ query mạnh mẽ như BigQuery, vì Cloud Logging UI chỉ phù hợp xem tổng quát, không lý tưởng cho phân tích granular. Load test thường dùng công cụ như Apache JMeter hoặc Locust, tạo traffic spike để kiểm tra autoscaling (Cloud Run scale từ 0 đến 1000+ instances).
🛠️ Vấn đề cốt lõi: Phân tích logs cần độ chính xác cao, query linh hoạt theo thời gian, mà không tốn nhiều công sức setup.
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng: Analyze the log data in BigQuery by configuring a BigQuery log sink with the appropriate inclusion filter for your application.
Lý do chọn (chi tiết):
- Cloud Run logs được lưu trữ trong Cloud Logging, và cách tối ưu nhất để phân tích second-by-second là export sang BigQuery qua Log Sink (log router).
- BigQuery hỗ trợ SQL query siêu nhanh trên dữ liệu lớn, dễ filter theo timestamp (giây), resource (Cloud Run service), severity, và metrics như latency/CPU.
- Inclusion filter cho phép chỉ export logs liên quan đến app cụ thể (ví dụ:
resource.type="cloud_run_revision" AND jsonPayload.service_name="your-service"), giảm chi phí và noise. - Minimize effort: Setup sink chỉ mất vài phút qua Console/CLI/gcloud, không cần code phức tạp. Sau export, query ngay:
SELECT TIMESTAMP_TRUNC(timestamp, SECOND) as second, AVG(jsonPayload.httpRequest.latency.value) FROMproject.dataset.tableGROUP BY second. - ✅ Phù hợp load test: Xem traffic spike qua logs như request count, errors, cold starts per second.
Tài liệu tham khảo:
- Cloud Run Logging (Google Cloud Docs, cập nhật 2025).
- Export Logs to BigQuery (Hướng dẫn sink filter).
📋 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. Mỗi phương án được đánh giá dựa trên tính khả thi, độ chính xác second-by-second, và effort (theo best practices GCP 2026).
-
❌ Use estimation to extrapolate performance from summary monitoring charts.
Sai vì: Chỉ dùng ước lượng từ biểu đồ tổng hợp (như Cloud Monitoring dashboards) không cho phép phân tích second-by-second chính xác. Biểu đồ chỉ hiển thị aggregate (ví dụ: avg/min/max 1 phút), không drill-down logs granular. Effort thấp nhưng không đáp ứng yêu cầu "analyze logs second by second" và dễ miss spike chi tiết. Không phải cách chính thức cho load test. -
✅ Analyze the log data in BigQuery by configuring a BigQuery log sink with the appropriate inclusion filter for your application.
Đúng vì: Như giải thích trên – best practice cho phân tích logs chi tiết, low-effort, hỗ trợ query SQL theo giây trên dữ liệu lớn. Sink export real-time/near-real-time, filter chính xác cho Cloud Run logs (severity=INFO/ERROR, httpRequest). -
❌ Use Cloud Monitoring’s default log console for analysis.
Sai vì: Cloud Logging console (trong Monitoring) chỉ phù hợp xem/search logs cơ bản, nhưng khó khăn cho second-by-second do UI filter thời gian kém linh hoạt (không group by second dễ dàng), và với volume logs load test lớn (hàng triệu entries), sẽ chậm/lag. Không minimize effort cho phân tích sâu, thiếu SQL power. -
❌ Analyze the log data in Cloud SQL for PostgreSQL by pushing logs to a Pub/Sub topic. Use Dataflow to process and ingest the logs.
Sai vì: Quá phức tạp và high-effort (setup Pub/Sub sink + Dataflow pipeline + schema Cloud SQL). Cloud SQL không phải tool logs native (dành cho relational DB), Dataflow cho streaming nhưng overkill cho batch analysis second-by-second. Chi phí cao, latency ingest lớn (phút thay vì giây), không optimal so với BigQuery sink trực tiếp.
🧩 Kết luận: Phương án BigQuery sink là golden path cho Cloud Run load testing, đảm bảo scalability và insights sâu với effort thấp nhất! Nếu cần demo code gcloud setup sink: gcloud logging sinks create my-sink bigquery.googleapis.com/projects/myproject/datasets/my_dataset --log-filter='...'.
- A Assign the IAM service account to the cluster’s node pool. Configure the application to authenticate to the bucket by using Application Default Credentials.
- B Assign the IAM service account to the cluster’s node pool. Encrypt the IAM service account key file by using a symmetric block cipher, and store the encrypted file on a persistent volume. Store the encryption key in Secret Manager.
- C Create a Kubernetes service account. Create a Kubernetes secret with a base64-encoded IAM service account key file. Annotate the Kubernetes secret with the Kubernetes service account. Assign the Kubernetes ServiceAccount to the Pods that need to access the bucket.
- D Create a Kubernetes service account. Use an IAM policy to bind the IAM service account to a Kubernetes service account. Annotate the Kubernetes ServiceAccount object with the name of the bound IAM service account. Assign the Kubernetes ServiceAccount to the Pods that need to access the bucket.
Xem giải thích
🧩 Phân tích nội dung câu hỏi
Câu hỏi tập trung vào việc triển khai ứng dụng microservices trên GKE (Google Kubernetes Engine). Một microservice cần tải file từ Cloud Storage bucket. Bạn đã có IAM service account với vai trò Storage Object Viewer trên project chứa bucket. Nhiệm vụ là cấu hình ứng dụng truy cập bucket theo thực hành khuyến nghị của Google (Google-recommended practices).
🔍 Chi tiết vấn đề:
- Tránh sử dụng service account key files (rủi ro bảo mật cao, dễ bị lộ).
- Ưu tiên phương pháp không dùng key, như Workload Identity – cách tốt nhất để pods trong GKE truy cập GCP services mà không cần credentials thủ công.
- Đảm bảo least privilege: Chỉ cấp quyền cho các pods/microservice cụ thể cần truy cập, không cấp cho toàn cluster/node pool.
- Kiến thức cập nhật đến 2026: Theo tài liệu GCP mới nhất (GKE 1.29+), Workload Identity là chuẩn mực, hỗ trợ OIDC federation, loại bỏ nhu cầu key rotation.
📘 Tài liệu tham khảo:
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng: Create a Kubernetes service account. Use an IAM policy to bind the IAM service account to a Kubernetes service account. Annotate the Kubernetes ServiceAccount object with the name of the bound IAM service account. Assign the Kubernetes ServiceAccount to the Pods that need to access the bucket.
Lý do:
- Đây là cách Workload Identity chính thức của Google: Bind IAM SA với K8s SA qua IAM policy, annotate K8s SA với email của IAM SA (ví dụ:
iam.gke.io/gcp-service-account: sa@project.iam.gserviceaccount.com), rồi assign K8s SA cho pods. - ✅ Ưu điểm: Không dùng key files (zero-key), tự động, an toàn, tuân thủ least privilege, tích hợp OIDC token từ GKE metadata server.
- Phù hợp với microservices: Mỗi service có K8s SA riêng, chỉ cấp quyền cho pods cần thiết.
🛠️ Giải thích tất cả các phương án
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 bằng tiếng Anh. Tôi đánh dấu ✅ đúng, ❌ sai và giải thích rõ ràng:
-
❌ Assign the IAM service account to the cluster’s node pool. Configure the application to authenticate to the bucket by using Application Default Credentials.
- Sai vì: Gán IAM SA cho node pool sẽ cấp quyền cho toàn bộ nodes/cluster, vi phạm least privilege (tất cả pods đều dùng credentials của node). ADC (Application Default Credentials) dựa vào metadata server của node, không an toàn cho multi-tenant GKE. Google khuyến nghị tránh cách này từ 2020+.
-
❌ Assign the IAM service account to the cluster’s node pool. Encrypt the IAM service account key file by using a symmetric block cipher, and store the encrypted file on a persistent volume. Store the encryption key in Secret Manager.
- Sai vì: Vẫn gán cho node pool (rủi ro lan tỏa quyền), và sử dụng key file (dù mã hóa) là anti-pattern. Key files dễ bị lộ nếu PV bị hack; Google cấm dùng key từ 2019, ưu tiên Workload Identity. Secret Manager chỉ quản lý key mã hóa, không giải quyết gốc rễ.
-
❌ Create a Kubernetes service account. Create a Kubernetes secret with a base64-encoded IAM service account key file. Annotate the Kubernetes secret with the Kubernetes service account. Assign the Kubernetes ServiceAccount to the Pods that need to access the bucket.
- Sai vì: Sử dụng Kubernetes secret chứa key file base64 – vẫn là key management thủ công, rủi ro cao (secret có thể bị dump). Annotate secret không chuẩn; Google deprecated cách này, thay bằng Workload Identity để tránh key rotation và vaulting.
-
✅ Create a Kubernetes service account. Use an IAM policy to bind the IAM service account to a Kubernetes service account. Annotate the Kubernetes ServiceAccount object with the name of the bound IAM service account. Assign the Kubernetes ServiceAccount to the Pods that need to access the bucket.
- Đúng vì: Triển khai Workload Identity chuẩn:
- Tạo K8s SA.
- Bind IAM SA với K8s SA qua IAM policy (
gcloud iam service-accounts add-iam-policy-binding). - Annotate K8s SA:
annotations: iam.gke.io/gcp-service-account: <IAM_SA_EMAIL>. - Assign cho pods qua
serviceAccountName.
- Pods tự fetch short-lived OIDC token từ GKE, impersonate IAM SA → truy cập Storage an toàn, không key. Hoàn hảo cho GKE Autopilot/Standard (2026).
- Đúng vì: Triển khai Workload Identity chuẩn:
🔥 Tóm tắt: Workload Identity là "best practice" duy nhất, giúp giảm surface attack và tuân thủ zero-trust! 🚀