← Cloud · GCP← Cloud · GCP
Cloud · GCPCloud · GCP19 Th7, 2026Jul 19, 202612 phút đọc10 min read

StorageStorage

Part of the Cloud knowledge base — GCP deep dive. Complements DevOps Roadmap.

Tổng quan

Storage trên Google Cloud chia thành ba dạng lớn, và chọn sai dạng là một sai lầm phổ biến và tốn kém:

DạngDịch vụMô hình truy cậpTương đương AWS
Object storageCloud Storage (GCS)HTTP API, key → blobS3
Block storagePersistent Disk, Hyperdisk, Local SSDGắn vào VM như một diskEBS / instance store
File storageFilestoreNFS mountEFS / FSx

Quy tắc kinh nghiệm: dùng object storage cho các blob phi cấu trúc (hình ảnh, backup, file data-lake, static asset); dùng block storage cho disk boot/data của VM và I/O ngẫu nhiên độ trễ thấp; dùng file storage khi nhiều VM cần một filesystem POSIX dùng chung.

Trang này tập trung vào Cloud Storage (được dùng nhiều nhất) và các lựa chọn block/file, cộng với mô hình chi phí egress khiến nhiều team bất ngờ.

Kiến thức nền tảng

Cloud Storage (GCS)

Cloud Storage lưu các object bất biến bên trong các bucket. Một bucket có tên duy nhất toàn cầu, một location, một storage class mặc định, và cấu hình IAM/policy. Object được địa chỉ hóa dưới dạng gs://bucket-name/path/to/object.

Các loại location:

LoạiDự phòngDùng khi
Region (vd us-central1)Nhiều zone trong một regionĐộ trễ thấp nhất tới compute cùng vị trí, data residency
Dual-region (vd nam4)Hai region cụ thểHA + cặp địa lý xác định
Multi-region (vd US, EU)Trải rộng một vùng địa lý lớnTính sẵn sàng cao nhất, đọc toàn cầu

Storage classes đánh đổi giá lưu trữ thấp hơn lấy chi phí truy cập (retrieval) cao hơn và thời lượng lưu trữ tối thiểu:

ClassThời lượng lưu tối thiểuDùng điển hìnhChi phí retrieval
StandardkhôngDữ liệu nóng, truy cập thường xuyên, website tĩnhkhông
Nearline30 ngàyTruy cập < 1 lần/tháng (backup)thấp
Coldline90 ngàyTruy cập < 1 lần/quý (DR)trung bình
Archive365 ngàyTruy cập < 1 lần/năm (compliance, lưu trữ sâu)cao nhất

Mọi class có cùng throughput, độ trễ, và API — khác biệt thuần túy nằm ở mô hình giá. Xóa hoặc ghi đè một object trước thời lượng tối thiểu của nó sẽ chịu phí xóa sớm (early-deletion).

Các thao tác cơ bản với CLI gcloud storage (kế thừa hiện đại của gsutil):

# Tạo một bucket regional với uniform bucket-level access
gcloud storage buckets create gs://my-app-assets \
  --location=us-central1 \
  --default-storage-class=STANDARD \
  --uniform-bucket-level-access

# Upload / download / list
gcloud storage cp ./photo.jpg gs://my-app-assets/photos/
gcloud storage cp gs://my-app-assets/photos/photo.jpg ./
gcloud storage ls gs://my-app-assets/photos/

# Đồng bộ một thư mục local với bucket (giống rsync)
gcloud storage rsync ./build gs://my-app-assets/site --recursive

Object versioning

Object versioning giữ lại các phiên bản không hiện hành (noncurrent) khi một object bị ghi đè hoặc xóa, bảo vệ khỏi mất mát vô tình và ransomware. Kết hợp với lifecycle rule để hết hạn các phiên bản cũ.

gcloud storage buckets update gs://my-app-assets --versioning

Quản lý vòng đời (lifecycle)

Lifecycle rules tự động chuyển object sang class lạnh hơn hoặc xóa chúng dựa trên tuổi, trạng thái phiên bản, hoặc class. Định nghĩa bằng JSON và áp dụng cho một bucket:

{
  "rule": [
    {
      "action": {"type": "SetStorageClass", "storageClass": "NEARLINE"},
      "condition": {"age": 30, "matchesStorageClass": ["STANDARD"]}
    },
    {
      "action": {"type": "SetStorageClass", "storageClass": "COLDLINE"},
      "condition": {"age": 90, "matchesStorageClass": ["NEARLINE"]}
    },
    {
      "action": {"type": "Delete"},
      "condition": {"age": 365}
    },
    {
      "action": {"type": "Delete"},
      "condition": {"numNewerVersions": 3, "isLive": false}
    }
  ]
}
gcloud storage buckets update gs://my-app-assets \
  --lifecycle-file=lifecycle.json

Policy này phân tầng Standard → Nearline sau 30 ngày, Nearline → Coldline sau 90 ngày, xóa object quá 365 ngày, và giữ tối đa 3 phiên bản noncurrent. Autoclass là một lựa chọn không phải bận tâm, tự động di chuyển object giữa các class dựa trên pattern truy cập.

Kiểm soát truy cập: IAM vs ACL

Hai cách để cấp quyền, và bạn nên chọn một cách có chủ đích:

Cơ chếMức chi tiếtKhuyến nghị
IAM (Uniform bucket-level access)Role mức bucketƯu tiên — nhất quán, audit được, hoạt động với org policy
ACL (fine-grained)Cấp quyền theo từng objectLegacy; chỉ khi bạn thực sự cần quyền theo từng object

Bật Uniform bucket-level access vô hiệu hóa ACL theo object và biến IAM thành nguồn sự thật duy nhất — mặc định được khuyến nghị. Các role phổ biến: roles/storage.objectViewer, roles/storage.objectAdmin, roles/storage.admin.

Signed URLs

Một signed URL cấp quyền truy cập có giới hạn thời gian tới một object cụ thể mà không yêu cầu người gọi có quyền IAM — lý tưởng để cho phép người dùng cuối upload hoặc download trực tiếp:

# Tạo một URL có hiệu lực 15 phút để GET một object
gcloud storage sign-url gs://my-app-assets/reports/q3.pdf \
  --duration=15m \
  --private-key-file=key.json

Dùng signed URL kiểu PUT để cho phép trình duyệt upload trực tiếp lên GCS, giữ các file lớn tránh xa server ứng dụng của bạn.

Hosting website tĩnh

Cloud Storage có thể phục vụ một site tĩnh trực tiếp. Trỏ một bucket đặt tên theo domain của bạn tới trang index/error, rồi đặt trước nó một external HTTPS load balancer + Cloud CDN để có TLS và custom domain:

gcloud storage buckets update gs://www.example.com \
  --web-main-page-index=index.html \
  --web-error-page=404.html

Persistent Disk & Hyperdisk (block storage)

Persistent Disk (PD) là block storage gắn qua mạng cho Compute Engine và GKE. Nó tồn tại qua stop/restart của instance và có thể resize khi đang chạy.

LoạiNền tảngDùng khi
pd-standardHDDI/O tuần tự, khối lượng lớn giá rẻ, dữ liệu lạnh
pd-balancedSSDMặc định general-purpose, $/IOPS tốt
pd-ssdSSDNhạy cảm độ trễ, database IOPS cao
pd-extremeSSDIOPS cao nhất, provision IOPS riêng

Hyperdisk là thế hệ mới hơn tách rời capacity, throughput, và IOPS để bạn tinh chỉnh từng cái độc lập — rẻ hơn và linh hoạt hơn cho các workload đòi hỏi cao (hyperdisk-balanced, hyperdisk-throughput, hyperdisk-extreme).

Regional persistent disk sao chép đồng bộ qua hai zone cho HA của các workload stateful. Snapshot là bản sao lưu incremental, differential của một disk, lưu trong Cloud Storage và dùng được qua các zone/region:

# Tạo một snapshot
gcloud compute disks snapshot my-data-disk \
  --snapshot-names=my-data-snap-$(date +%Y%m%d) \
  --zone=us-central1-a

# Tự động hóa với một snapshot schedule (resource policy)
gcloud compute resource-policies create snapshot-schedule daily-backup \
  --region=us-central1 \
  --max-retention-days=14 \
  --daily-schedule --start-time=03:00
gcloud compute disks add-resource-policies my-data-disk \
  --resource-policies=daily-backup --zone=us-central1-a

Local SSD

Local SSD được gắn vật lý vào host, cho IOPS cao nhất/độ trễ thấp nhất — nhưng dữ liệu là ephemeral và bị mất khi stop/terminate/live-migration. Chỉ dùng cho không gian tạm (scratch), cache, hoặc các database scale-out sao chép chịu được mất node.

Filestore (file storage)

Filestore là NFS được quản lý cho các workload cần một filesystem POSIX dùng chung qua nhiều VM hoặc GKE pod (media CMS, HPC scratch, ứng dụng lift-and-shift kỳ vọng một mount). Các tier trải từ Basic tới Zonal, Regional, và Enterprise (hiệu năng và tính sẵn sàng cao hơn).

Khái niệm chính

Chọn một dịch vụ storage

Chọn dịch vụ storage
  1. ?Blob phi cấu trúc, backup, data-lake, static asset, truy cập qua HTTP?
    Cloud Storagechọn class theo tần suất truy cập; thêm lifecycle rule
  2. ?Một disk cho một VM (boot hoặc data), I/O ngẫu nhiên độ trễ thấp?
    Persistent Disk / HyperdiskPD regional cho HA; snapshot cho backup
  3. ?IOPS cao nhất có thể và chịu được mất dữ liệu khi stop?
    Local SSD
  4. ?Nhiều VM / pod cần một filesystem POSIX dùng chung (NFS)?
    Filestore

Chi phí truyền dữ liệu & egress

Giá lưu trữ chỉ là một phần hóa đơn — network egress thường chiếm phần lớn:

Với các migration lớn một lần hoặc liên tục, dùng Storage Transfer Service (từ S3, Azure, HTTP, hoặc on-prem) hoặc Transfer Appliance cho truyền offline quy mô petabyte.

Mã hóa

Mọi dữ liệu được mã hóa at rest theo mặc định với key do Google quản lý. Để kiểm soát bạn có thể dùng CMEK (Customer-Managed Encryption Keys qua Cloud KMS) hoặc CSEK (key do khách hàng cung cấp). CMEK là lựa chọn thông thường cho compliance.

Best Practices

  1. Khớp storage class với tần suất truy cập và tự động hóa việc chuyển tầng. Lý do: dùng Standard cho dữ liệu nóng gây lãng phí tiền cho các object hiếm khi đọc; lifecycle rule (hoặc Autoclass) tự động chuyển dữ liệu lạnh sang Nearline/Coldline/Archive để tiết kiệm lớn.

  2. Bật Uniform bucket-level access (IAM, không phải ACL). Lý do: một mô hình quyền duy nhất, audit được, hoạt động với org policy; ACL theo object dễ sai và khó suy luận.

  3. Bật Object Versioning cho các bucket giữ state quan trọng. Lý do: bảo vệ khỏi ghi đè/xóa vô tình và ransomware; kết hợp với lifecycle rule để giới hạn phình phiên bản.

  4. Dùng signed URL cho upload/download trực tiếp của người dùng. Lý do: giữ các lần truyền lớn tránh xa server ứng dụng và tránh cấp quyền IAM rộng, trong khi vẫn có giới hạn thời gian.

  5. Đặt Cloud CDN trước nội dung public/tĩnh. Lý do: cache tại edge, giảm mạnh chi phí egress từ origin và cải thiện độ trễ toàn cầu.

  6. Đặt bucket cùng vị trí với compute đọc nó. Lý do: truy cập cùng region nhanh và miễn phí egress; đọc cross-region thêm độ trễ và phí mạng.

  7. Đặt lifecycle rule để xóa các multipart upload dở dang và phiên bản cũ. Lý do: các upload bị bỏ dở và phiên bản noncurrent không giới hạn âm thầm tích lũy chi phí.

  8. Ưu tiên pd-balanced làm disk mặc định, chỉ nâng cấp khi bị giới hạn IOPS. Lý do: giá/hiệu năng tốt cho hầu hết workload; để dành pd-ssd/Hyperdisk-extreme cho các database quan trọng về độ trễ.

  9. Dùng Hyperdisk khi cần tinh chỉnh IOPS/throughput độc lập. Lý do: tách rời capacity khỏi hiệu năng tránh phải over-provision một disk lớn chỉ để có IOPS.

  10. Lên lịch snapshot disk tự động, incremental kèm retention. Lý do: snapshot rẻ, incremental, và cross-region — một primitive backup/DR đáng tin; policy retention ngăn tăng trưởng không giới hạn.

  11. Không bao giờ lưu dữ liệu bền vững trên Local SSD. Lý do: nó ephemeral và bị mất khi stop/migration; chỉ dùng cho scratch, cache, hoặc dữ liệu đã sao chép.

  12. Dùng regional Persistent Disk cho các workload stateful cần HA. Lý do: sao chép đồng bộ cross-zone cho phép một VM/pod stateful phục hồi ở zone khác mà không mất dữ liệu.

  13. Bật CMEK cho dữ liệu bị quản chế hoặc nhạy cảm. Lý do: cho bạn quyền xoay vòng key, thu hồi, và kiểm soát audit vượt qua mã hóa do Google quản lý mặc định.

  14. Áp dụng nguyên tắc đặc quyền tối thiểu trên bucket. Lý do: cấp objectViewer/objectAdmin giới hạn ở các bucket cụ thể thay vì storage.admin toàn project; một credential rò rỉ khi đó bị kiềm chế.

  15. Bật Bucket Lock / retention policy cho các archive tuân thủ. Lý do: tính bất biến kiểu WORM ngăn xóa trước một khoảng retention — bắt buộc cho nhiều use case audit và legal-hold.

  16. Mô hình hóa egress trước khi phục vụ media lớn từ GCS. Lý do: egress internet và phí retrieval có thể vượt xa chi phí lưu trữ; ước lượng chúng (và cân nhắc CDN) trước khi ra mắt để tránh sốc hóa đơn.

Tài liệu tham khảo

Part of the Cloud knowledge base — GCP deep dive. Complements DevOps Roadmap.

Overview

Storage on Google Cloud splits into three broad shapes, and picking the wrong one is a common and expensive mistake:

ShapeService(s)Access modelAWS equivalent
Object storageCloud Storage (GCS)HTTP API, key → blobS3
Block storagePersistent Disk, Hyperdisk, Local SSDAttached to a VM as a diskEBS / instance store
File storageFilestoreNFS mountEFS / FSx

The rule of thumb: object storage for unstructured blobs (images, backups, data-lake files, static assets); block storage for VM boot/data disks and low-latency random I/O; file storage when multiple VMs need a shared POSIX filesystem.

This page focuses on Cloud Storage (by far the most used) and the block/file options, plus the egress-cost model that surprises many teams.

Fundamentals

Cloud Storage (GCS)

Cloud Storage stores immutable objects inside buckets. A bucket has a globally unique name, a location, a default storage class, and IAM/policy configuration. Objects are addressed as gs://bucket-name/path/to/object.

Location types:

TypeRedundancyUse when
Region (e.g. us-central1)Multi-zone within one regionLowest latency to co-located compute, data residency
Dual-region (e.g. nam4)Two specific regionsHA + defined geographic pair
Multi-region (e.g. US, EU)Across a large geographyHighest availability, global read access

Storage classes trade lower storage price for higher access (retrieval) cost and minimum storage durations:

ClassMin storage durationTypical useRetrieval cost
StandardnoneHot data, frequently accessed, static websitesnone
Nearline30 daysAccessed < once/month (backups)low
Coldline90 daysAccessed < once/quarter (DR)medium
Archive365 daysAccessed < once/year (compliance, deep archive)highest

All classes have the same throughput, latency, and API — the difference is purely the pricing model. Deleting or overwriting an object before its minimum duration incurs an early-deletion charge.

Basic operations with the gcloud storage CLI (the modern successor to gsutil):

# Create a regional bucket with uniform bucket-level access
gcloud storage buckets create gs://my-app-assets \
  --location=us-central1 \
  --default-storage-class=STANDARD \
  --uniform-bucket-level-access

# Upload / download / list
gcloud storage cp ./photo.jpg gs://my-app-assets/photos/
gcloud storage cp gs://my-app-assets/photos/photo.jpg ./
gcloud storage ls gs://my-app-assets/photos/

# Sync a local directory to a bucket (like rsync)
gcloud storage rsync ./build gs://my-app-assets/site --recursive

Object versioning

Object versioning keeps noncurrent versions when an object is overwritten or deleted, protecting against accidental loss and ransomware. Combine with lifecycle rules to expire old versions.

gcloud storage buckets update gs://my-app-assets --versioning

Lifecycle management

Lifecycle rules automatically transition objects to colder classes or delete them based on age, version state, or class. Define them in JSON and apply to a bucket:

{
  "rule": [
    {
      "action": {"type": "SetStorageClass", "storageClass": "NEARLINE"},
      "condition": {"age": 30, "matchesStorageClass": ["STANDARD"]}
    },
    {
      "action": {"type": "SetStorageClass", "storageClass": "COLDLINE"},
      "condition": {"age": 90, "matchesStorageClass": ["NEARLINE"]}
    },
    {
      "action": {"type": "Delete"},
      "condition": {"age": 365}
    },
    {
      "action": {"type": "Delete"},
      "condition": {"numNewerVersions": 3, "isLive": false}
    }
  ]
}
gcloud storage buckets update gs://my-app-assets \
  --lifecycle-file=lifecycle.json

This policy tiers Standard → Nearline at 30 days, Nearline → Coldline at 90 days, deletes objects past 365 days, and keeps at most 3 noncurrent versions. Autoclass is a hands-off alternative that moves objects between classes automatically based on access patterns.

Access control: IAM vs ACLs

Two ways to grant access, and you should pick one deliberately:

MechanismGranularityRecommendation
IAM (Uniform bucket-level access)Bucket-level rolesPreferred — consistent, auditable, works with org policy
ACLs (fine-grained)Per-object grantsLegacy; only when you truly need per-object permissions

Enabling Uniform bucket-level access disables per-object ACLs and makes IAM the single source of truth — the recommended default. Common roles: roles/storage.objectViewer, roles/storage.objectAdmin, roles/storage.admin.

Signed URLs

A signed URL grants time-limited access to a specific object without requiring the caller to have IAM permissions — ideal for letting end users upload or download directly:

# Generate a URL valid for 15 minutes to GET an object
gcloud storage sign-url gs://my-app-assets/reports/q3.pdf \
  --duration=15m \
  --private-key-file=key.json

Use PUT signed URLs to let browsers upload directly to GCS, keeping large files off your application servers.

Static website hosting

Cloud Storage can serve a static site directly. Point a bucket named after your domain at index/error pages, then front it with an external HTTPS load balancer + Cloud CDN for TLS and a custom domain:

gcloud storage buckets update gs://www.example.com \
  --web-main-page-index=index.html \
  --web-error-page=404.html

Persistent Disk & Hyperdisk (block storage)

Persistent Disk (PD) is network-attached block storage for Compute Engine and GKE. It survives instance stop/restart and can be resized live.

TypeBackingUse when
pd-standardHDDSequential I/O, cheap bulk, cold data
pd-balancedSSDGeneral purpose default, good $/IOPS
pd-ssdSSDLatency-sensitive, high IOPS databases
pd-extremeSSDHighest IOPS, provision IOPS separately

Hyperdisk is the newer generation that decouples capacity, throughput, and IOPS so you tune each independently — cheaper and more flexible for demanding workloads (hyperdisk-balanced, hyperdisk-throughput, hyperdisk-extreme).

Regional persistent disks synchronously replicate across two zones for HA of stateful workloads. Snapshots are incremental, differential backups of a disk, stored in Cloud Storage and usable across zones/regions:

# Create a snapshot
gcloud compute disks snapshot my-data-disk \
  --snapshot-names=my-data-snap-$(date +%Y%m%d) \
  --zone=us-central1-a

# Automate with a snapshot schedule (resource policy)
gcloud compute resource-policies create snapshot-schedule daily-backup \
  --region=us-central1 \
  --max-retention-days=14 \
  --daily-schedule --start-time=03:00
gcloud compute disks add-resource-policies my-data-disk \
  --resource-policies=daily-backup --zone=us-central1-a

Local SSD

Local SSD is physically attached to the host, offering the highest IOPS/lowest latency — but data is ephemeral and lost on stop/terminate/live-migration. Use only for scratch space, caches, or replicated scale-out databases that tolerate node loss.

Filestore (file storage)

Filestore is managed NFS for workloads that need a shared POSIX filesystem across many VMs or GKE pods (CMS media, HPC scratch, lift-and-shift apps expecting a mount). Tiers range from Basic to Zonal, Regional, and Enterprise (higher performance and availability).

Key Concepts

Choosing a storage service

Choosing a storage service
  1. ?Unstructured blobs, backups, data-lake, static assets, accessed over HTTP?
    Yes
    Cloud Storagechoose class by access frequency; add lifecycle rules
  2. ?A disk for one VM (boot or data), low-latency random I/O?
    Yes
    Persistent Disk / Hyperdiskregional PD for HA; snapshots for backup
  3. ?Highest possible IOPS and can tolerate data loss on stop?
    Yes
    Local SSD
  4. ?Multiple VMs / pods need a shared POSIX filesystem (NFS)?
    Yes
    Filestore

Data transfer & egress costs

Storage price is only part of the bill — network egress often dominates:

For large one-time or ongoing migrations, use Storage Transfer Service (from S3, Azure, HTTP, or on-prem) or Transfer Appliance for petabyte-scale offline transfer.

Encryption

All data is encrypted at rest by default with Google-managed keys. For control you can use CMEK (Customer-Managed Encryption Keys via Cloud KMS) or CSEK (customer-supplied keys). CMEK is the usual choice for compliance.

Best Practices

  1. Match storage class to access frequency and automate transitions. Rationale: Standard for hot data wastes money on rarely-read objects; lifecycle rules (or Autoclass) move cold data to Nearline/Coldline/Archive automatically for large savings.

  2. Enable Uniform bucket-level access (IAM, not ACLs). Rationale: a single, auditable permission model that works with org policy; per-object ACLs are error-prone and hard to reason about.

  3. Turn on Object Versioning for buckets holding important state. Rationale: protects against accidental overwrite/delete and ransomware; pair with lifecycle rules to bound version sprawl.

  4. Use signed URLs for direct user upload/download. Rationale: keeps large transfers off your app servers and avoids handing out broad IAM permissions, while remaining time-limited.

  5. Front public/static content with Cloud CDN. Rationale: caches at the edge, dramatically reducing origin egress cost and improving global latency.

  6. Co-locate buckets with the compute that reads them. Rationale: same-region access is fast and egress-free; cross-region reads add latency and network charges.

  7. Set lifecycle rules to delete incomplete multipart uploads and old versions. Rationale: abandoned uploads and unbounded noncurrent versions silently accumulate cost.

  8. Prefer pd-balanced as the default disk, upgrade only when IOPS-bound. Rationale: good price/performance for most workloads; reserve pd-ssd/Hyperdisk-extreme for latency-critical databases.

  9. Use Hyperdisk when you need to tune IOPS/throughput independently. Rationale: decoupling capacity from performance avoids over-provisioning a large disk just to get IOPS.

  10. Schedule automated, incremental disk snapshots with retention. Rationale: snapshots are cheap, incremental, and cross-region — a reliable backup/DR primitive; a retention policy prevents unbounded growth.

  11. Never store durable data on Local SSD. Rationale: it is ephemeral and lost on stop/migration; use it only for scratch, cache, or replicated data.

  12. Use regional Persistent Disks for stateful HA workloads. Rationale: synchronous cross-zone replication lets a stateful VM/pod recover in another zone without data loss.

  13. Enable CMEK for regulated or sensitive data. Rationale: gives you key rotation, revocation, and audit control beyond the default Google-managed encryption.

  14. Apply the Principle of Least Privilege on buckets. Rationale: grant objectViewer/objectAdmin scoped to specific buckets rather than project-wide storage.admin; a leaked credential is then contained.

  15. Turn on Bucket Lock / retention policy for compliance archives. Rationale: WORM-style immutability prevents deletion before a retention period — required for many audit and legal-hold use cases.

  16. Model egress before serving large media from GCS. Rationale: internet egress and retrieval fees can dwarf storage cost; estimate them (and consider CDN) before launch to avoid bill shock.

References