发布时间: 2025-1-15 文章作者: myluzh 分类名称: 朗读文章
使用场景 | 推荐方式 |
---|---|
持久化存储(文件、数据库等) | PVC 或 volumeClaimTemplates |
配置和凭据管理 | ConfigMap 和 Secret |
临时数据存储 | EmptyDir |
访问主机文件 | HostPath |
动态云存储卷分配 | CSI |
volumes: - name: app-data persistentVolumeClaim: claimName: app-data-pvc --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: app-data-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 10Gi
volumeMounts: - name: mysql-data mountPath: /var/lib/mysql --- volumeClaimTemplates: - metadata: name: mysql-data spec: accessModes: - ReadWriteOnce resources: requests: storage: 20Gi storageClassName: standard # 指定存储类,不写就是默认存储类。修改默认存储类
kubectl patch storageclass <storage-class-name> -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
volumes: - name: app-config configMap: name: app-config
volumes: - name: temp-storage emptyDir: {}
volumes: - name: host-storage hostPath: path: /data/host
volumes: - name: csi-storage csi: driver: ebs.csi.aws.com volumeHandle: volume-id
发表评论