gke-storage
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGKE 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_resourceget_cluster
本参考文档涵盖GKE集群的存储配置,包括持久磁盘、文件存储和云存储集成。
MCP工具:,apply_k8s_manifest,get_k8s_resource,describe_k8s_resourceget_cluster
Golden Path Storage Defaults
黄金路径存储默认配置
The golden path Autopilot config enables these CSI drivers:
| Driver | Golden Path | Access Mode | Use Case |
|---|---|---|---|
| Compute Engine | Enabled (default) | ReadWriteOnce | Block storage for |
| : Persistent Disk : : : databases, : | |||
| : CSI : : : single-pod workloads : | |||
| Google Cloud | Enabled | ReadWriteMany | Shared NFS for |
| : Filestore CSI : : : multi-pod access : | |||
| Cloud Storage | Enabled | ReadWriteMany / | Mount GCS buckets as |
| : FUSE CSI : : ReadOnlyMany : volumes : | |||
| Parallelstore | Enabled | ReadWriteMany | High-performance |
| : CSI : : : parallel file system : | |||
| Boot disk type | | N/A | Node 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 | 高性能并行文件系统 |
| 引导磁盘类型 | | N/A | 节点引导磁盘 |
StorageClasses
StorageClass(存储类)
Default StorageClasses
默认StorageClass
GKE provides built-in StorageClasses:
| StorageClass | Disk Type | Use Case |
|---|---|---|
| | Cost-effective, low IOPS |
| | High IOPS, databases |
| Filestore (Basic HDD) | Shared NFS |
| Filestore (Basic SSD) | Shared NFS, higher performance |
GKE提供内置的StorageClass:
| StorageClass | 磁盘类型 | 使用场景 |
|---|---|---|
| | 高性价比、低IOPS |
| | 高IOPS、适用于数据库 |
| Filestore(基础HDD) | 共享NFS存储 |
| 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 productionyaml
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 productionPersistentVolumeClaims
PersistentVolumeClaim(PVC)
Block Storage (ReadWriteOnce)
块存储(ReadWriteOnce)
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: database-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: premium-rwo
resources:
requests:
storage: 100Giyaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: database-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: premium-rwo
resources:
requests:
storage: 100GiShared 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 tieryaml
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 tierGCS 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 haveon the bucket.storage.objectViewer
无需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 is set on the StorageClass, resize by updating
the PVC:
allowVolumeExpansion: truebash
undefined如果StorageClass上设置了,可通过更新PVC进行扩容:
allowVolumeExpansion: truebash
undefinedkubectl
kubectl
kubectl patch pvc <PVC_NAME> -p '{"spec":{"resources":{"requests":{"storage":"200Gi"}}}}'
undefinedkubectl patch pvc <PVC_NAME> -p '{"spec":{"resources":{"requests":{"storage":"200Gi"}}}}'
undefinedMCP (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
最佳实践
- Always enable volume expansion: Set on all StorageClasses
allowVolumeExpansion: true - Use regional PDs for production: replicates across 2 zones for HA
replication-type: regional-pd - Use : Ensures the PV is provisioned in the same zone as the pod
WaitForFirstConsumer - Choose the right disk type: for databases,
pd-ssd(golden path default) for general use,pd-balancedfor cold storagepd-standard - Use Filestore for shared access: When multiple pods need to read/write the same files
- Use GCS FUSE for data pipelines: Mount buckets directly for ML training data, logs, etc.
- Back up PVCs: Use Backup for GKE (see the skill) to protect persistent data
gke-backup-dr
- 始终启用卷扩容:在所有StorageClass上设置
allowVolumeExpansion: true - 生产环境使用区域PD:可在2个可用区之间复制,实现高可用
replication-type: regional-pd - 使用:确保PV在与Pod相同的可用区中创建
WaitForFirstConsumer - 选择合适的磁盘类型:适用于数据库,
pd-ssd(黄金路径默认)适用于通用场景,pd-balanced适用于冷存储pd-standard - 共享访问使用Filestore:当多个Pod需要读写同一文件时使用
- 数据管道使用GCS FUSE:直接挂载存储桶用于机器学习训练数据、日志等
- 备份PVC:使用GKE备份功能(参考技能)保护持久化数据
gke-backup-dr