使用 CFS PVC
使用 CFS PVC
Section titled “使用 CFS PVC”CFS PVC 提供多节点共享文件系统能力,常用于多个 Pod 读写同一目录。
- 集群已安装 CFS-CSI 组件
- 已准备 VPC、子网和 CFS 权限组
- 节点网络可以访问 CFS 挂载点
- 已确认 CFS 类型、NFS 协议版本和容量成本
创建 StorageClass
Section titled “创建 StorageClass”apiVersion: storage.k8s.io/v1kind: StorageClassmetadata: name: cfs-standardprovisioner: com.tencent.cloud.csi.cfsparameters: pgroupid: pgroup-xxxxxxxx storagetype: SD vpcid: vpc-xxxxxxxx subnetid: subnet-xxxxxxxx vers: "3" zone: ap-guangzhou-3reclaimPolicy: RetainvolumeBindingMode: Immediatekubectl apply -f cfs-storageclass.yamlkubectl get storageclass cfs-standard参数说明:
| 参数 | 说明 |
|---|---|
pgroupid | CFS 权限组 ID |
storagetype | SD 标准型或 HP 性能型 |
vpcid / subnetid | 文件系统所在私有网络和子网 |
vers | NFS 协议版本,常见为 "3" 或 "4" |
zone | 文件系统所在可用区 |
创建 PVC
Section titled “创建 PVC”apiVersion: v1kind: PersistentVolumeClaimmetadata: name: shared-dataspec: accessModes: - ReadWriteMany storageClassName: cfs-standard resources: requests: storage: 10Gi volumeMode: Filesystemkubectl apply -f cfs-pvc.yamlkubectl get pvc shared-dataCFS 文件系统容量会按产品能力扩展,PVC 中的 storage 更多用于 Kubernetes 资源声明和绑定。
挂载到 Deployment
Section titled “挂载到 Deployment”apiVersion: apps/v1kind: Deploymentmetadata: name: web-sharedspec: replicas: 2 selector: matchLabels: app: web-shared template: metadata: labels: app: web-shared spec: containers: - name: nginx image: nginx:1.25 volumeMounts: - name: shared mountPath: /usr/share/nginx/html volumes: - name: shared persistentVolumeClaim: claimName: shared-datakubectl apply -f web-shared.yamlkubectl get pods -l app=web-shared -o wide验证共享写入
Section titled “验证共享写入”POD=$(kubectl get pod -l app=web-shared -o jsonpath='{.items[0].metadata.name}')kubectl exec "${POD}" -- sh -c 'date > /usr/share/nginx/html/index.html'kubectl exec "${POD}" -- cat /usr/share/nginx/html/index.html再进入另一个 Pod 检查同一文件是否可见。
- CFS 适合共享文件,不适合替代高 IOPS 本地块存储。
- 权限组需要允许节点或 Pod 所在网络访问。
- 多 Pod 并发写同一文件时,应用需要自己处理锁和一致性。
- 性能敏感场景评估 CFS 类型、NFS 版本、目录结构和小文件数量。