gke-storage

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GKE Storage

GKE 存储

This reference covers storage configuration for GKE clusters including persistent disks, file storage, and cloud storage integration.
MCP Tools:
apply_k8s_manifest
,
get_k8s_resource
,
describe_k8s_resource
,
get_cluster
本参考文档涵盖GKE集群的存储配置,包括持久磁盘、文件存储和云存储集成。
MCP工具:
apply_k8s_manifest
,
get_k8s_resource
,
describe_k8s_resource
,
get_cluster

Golden Path Storage Defaults

黄金路径存储默认配置

The golden path Autopilot config enables these CSI drivers:
DriverGolden PathAccess ModeUse Case
Compute EngineEnabled (default)ReadWriteOnceBlock storage for
: Persistent Disk : : : databases, :
: CSI : : : single-pod workloads :
Google CloudEnabledReadWriteManyShared NFS for
: Filestore CSI : : : multi-pod access :
Cloud StorageEnabledReadWriteMany /Mount GCS buckets as
: FUSE CSI : : ReadOnlyMany : volumes :
ParallelstoreEnabledReadWriteManyHigh-performance
: CSI : : : parallel file system :
Boot disk type
pd-balanced
N/ANode boot disks
黄金路径Autopilot配置启用了以下CSI驱动:
驱动程序黄金路径配置访问模式使用场景
Compute Engine 持久磁盘 CSI已启用(默认)ReadWriteOnce数据库、单Pod工作负载的块存储
Google Cloud Filestore CSI已启用ReadWriteMany多Pod访问的共享NFS存储
Cloud Storage FUSE CSI已启用ReadWriteMany / ReadOnlyMany将GCS存储桶挂载为卷
Parallelstore CSI已启用ReadWriteMany高性能并行文件系统
引导磁盘类型
pd-balanced
N/A节点引导磁盘

StorageClasses

StorageClass(存储类)

Default StorageClasses

默认StorageClass

GKE provides built-in StorageClasses:
StorageClassDisk TypeUse Case
standard-rwo
pd-standard
Cost-effective, low IOPS
premium-rwo
pd-ssd
High IOPS, databases
standard-rwx
Filestore (Basic HDD)Shared NFS
premium-rwx
Filestore (Basic SSD)Shared NFS, higher performance
GKE提供内置的StorageClass:
StorageClass磁盘类型使用场景
standard-rwo
pd-standard
高性价比、低IOPS
premium-rwo
pd-ssd
高IOPS、适用于数据库
standard-rwx
Filestore(基础HDD)共享NFS存储
premium-rwx
Filestore(基础SSD)共享NFS存储、更高性能

Custom StorageClass

自定义StorageClass

yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast-regional
provisioner: pd.csi.storage.gke.io
parameters:
  type: pd-ssd
  replication-type: regional-pd    # Replicate across 2 zones
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true         # Always enable for production
yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast-regional
provisioner: pd.csi.storage.gke.io
parameters:
  type: pd-ssd
  replication-type: regional-pd    # Replicate across 2 zones
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true         # Always enable for production

PersistentVolumeClaims

PersistentVolumeClaim(PVC)

Block Storage (ReadWriteOnce)

块存储(ReadWriteOnce)

yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: database-pvc
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: premium-rwo
  resources:
    requests:
      storage: 100Gi
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: database-pvc
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: premium-rwo
  resources:
    requests:
      storage: 100Gi

Shared File Storage (ReadWriteMany via Filestore)

共享文件存储(通过Filestore实现ReadWriteMany)

yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: shared-data
spec:
  accessModes:
  - ReadWriteMany
  storageClassName: standard-rwx
  resources:
    requests:
      storage: 1Ti    # Filestore minimum is 1 TiB for Basic tier
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: shared-data
spec:
  accessModes:
  - ReadWriteMany
  storageClassName: standard-rwx
  resources:
    requests:
      storage: 1Ti    # Filestore minimum is 1 TiB for Basic tier

GCS Bucket Mount (Cloud Storage FUSE)

GCS存储桶挂载(Cloud Storage FUSE)

Mount a GCS bucket as a volume without a PVC:
yaml
apiVersion: v1
kind: Pod
metadata:
  name: gcs-reader
  annotations:
    gke-gcsfuse/volumes: "true"
spec:
  containers:
  - name: reader
    image: busybox
    command: ["ls", "/data"]
    volumeMounts:
    - name: gcs-bucket
      mountPath: /data
  volumes:
  - name: gcs-bucket
    csi:
      driver: gcsfuse.csi.storage.gke.io
      readOnly: true
      volumeAttributes:
        bucketName: <BUCKET_NAME>
Requires Workload Identity for the pod's service account to have
storage.objectViewer
on the bucket.
无需PVC即可将GCS存储桶挂载为卷:
yaml
apiVersion: v1
kind: Pod
metadata:
  name: gcs-reader
  annotations:
    gke-gcsfuse/volumes: "true"
spec:
  containers:
  - name: reader
    image: busybox
    command: ["ls", "/data"]
    volumeMounts:
    - name: gcs-bucket
      mountPath: /data
  volumes:
  - name: gcs-bucket
    csi:
      driver: gcsfuse.csi.storage.gke.io
      readOnly: true
      volumeAttributes:
        bucketName: <BUCKET_NAME>
要求Pod的服务账号具备Workload Identity权限,且对该存储桶拥有
storage.objectViewer
角色。

Volume Expansion

卷扩容

If
allowVolumeExpansion: true
is set on the StorageClass, resize by updating the PVC:
bash
undefined
如果StorageClass上设置了
allowVolumeExpansion: true
,可通过更新PVC进行扩容:
bash
undefined

kubectl

kubectl

kubectl patch pvc <PVC_NAME> -p '{"spec":{"resources":{"requests":{"storage":"200Gi"}}}}'
undefined
kubectl patch pvc <PVC_NAME> -p '{"spec":{"resources":{"requests":{"storage":"200Gi"}}}}'
undefined

MCP (preferred)

MCP(推荐)

patch_k8s_resource(parent="...", resourceType="persistentvolumeclaim", name="<PVC_NAME>", patch='{"spec":{"resources":{"requests":{"storage":"200Gi"}}}}')

Kubernetes automatically resizes the filesystem.
patch_k8s_resource(parent="...", resourceType="persistentvolumeclaim", name="<PVC_NAME>", patch='{"spec":{"resources":{"requests":{"storage":"200Gi"}}}}')

Kubernetes会自动调整文件系统大小。

Best Practices

最佳实践

  1. Always enable volume expansion: Set
    allowVolumeExpansion: true
    on all StorageClasses
  2. Use regional PDs for production:
    replication-type: regional-pd
    replicates across 2 zones for HA
  3. Use
    WaitForFirstConsumer
    : Ensures the PV is provisioned in the same zone as the pod
  4. Choose the right disk type:
    pd-ssd
    for databases,
    pd-balanced
    (golden path default) for general use,
    pd-standard
    for cold storage
  5. Use Filestore for shared access: When multiple pods need to read/write the same files
  6. Use GCS FUSE for data pipelines: Mount buckets directly for ML training data, logs, etc.
  7. Back up PVCs: Use Backup for GKE (see the
    gke-backup-dr
    skill) to protect persistent data
  1. 始终启用卷扩容:在所有StorageClass上设置
    allowVolumeExpansion: true
  2. 生产环境使用区域PD
    replication-type: regional-pd
    可在2个可用区之间复制,实现高可用
  3. 使用
    WaitForFirstConsumer
    :确保PV在与Pod相同的可用区中创建
  4. 选择合适的磁盘类型
    pd-ssd
    适用于数据库,
    pd-balanced
    (黄金路径默认)适用于通用场景,
    pd-standard
    适用于冷存储
  5. 共享访问使用Filestore:当多个Pod需要读写同一文件时使用
  6. 数据管道使用GCS FUSE:直接挂载存储桶用于机器学习训练数据、日志等
  7. 备份PVC:使用GKE备份功能(参考
    gke-backup-dr
    技能)保护持久化数据