Container 中的文件在磁盘上是临时存放的,这给 Container 中运行的较重要的应用 程序带来一些问题。一是当容器崩溃时文件丢失,kubelet 会重新启动容器, 但容器会以干净的状态重启。
二是在同一 Pod 中运行多个容器并共享文件时出现。 Kubernetes 卷(Volume) 这一抽象概念能够解决这两个问题。

Docker 也有 卷(Volume) 的概念,但对它只有少量且松散的管理。 Docker 卷是磁盘上或者另外一个容器内的一个目录。 Docker 提供卷驱动程序,但是其功能非常有限。

Kubernetes 支持很多类型的卷。 Pod 可以同时使用任意数目的卷类型。 临时卷类型的生命周期与 Pod 相同,但持久卷可以比 Pod 的存活期长。 因此,卷的存在时间会超出 Pod 中运行的所有容器,并且在容器重新启动时数据也会得到保留。 当 Pod 不再存在时,卷也将不再存在。

卷的核心是包含一些数据的一个目录,Pod 中的容器可以访问该目录。 所采用的特定的卷类型将决定该目录如何形成的、使用何种介质保存数据以及目录中存放 的内容。

使用卷时, 在 .spec.volumes 字段中设置为 Pod 提供的卷,并在 .spec.containers[*].volumeMounts 字段中声明卷在容器中的挂载位置。

Pod使用存储的几种方式

image.png

Pod直接使用存储

Kubernetes支持非常多的卷类型,参考官方文档:
https://kubernetes.io/zh/docs/concepts/storage/volumes/
本文中会介绍其中几种:

emptyDir

当 Pod 分派到某个 Node 上时,emptyDir 卷会被创建,并且在 Pod 在该节点上运行期间,卷一直存在。 就像其名称表示的那样,卷最初是空的。 尽管 Pod 中的容器挂载 emptyDir 卷的路径可能相同也可能不同,这些容器都可以读写 emptyDir 卷中相同的文件。 当 Pod 因为某些原因被从节点上删除时,emptyDir 卷中的数据也会被永久删除。
说明: 容器崩溃并会导致 Pod 被从节点上移除,因此容器崩溃期间 emptyDir 卷中的数据是安全的。<br />
emptyDir 的一些用途:

  • 缓存空间,例如基于磁盘的归并排序。
  • 为耗时较长的计算任务提供检查点,以便任务能方便地从崩溃前状态恢复执行。
  • 在 Web 服务器容器服务数据时,保存内容管理器容器获取的文件。

emptyDir 卷存储在该节点所使用的介质上;这里的介质可以是磁盘或 SSD 或网络存储。但是,你可以将 emptyDir.medium 字段设置为 "Memory",以告诉 Kubernetes 为你挂载 tmpfs(基于 RAM 的文件系统)。 虽然 tmpfs 速度非常快,但是要注意它与磁盘不同。 tmpfs 在节点重启时会被清除,并且你所写入的所有文件都会计入容器的内存消耗,受容器内存限制约束。

  1. [root@clientvm ~]# cat emptyDir-pod.yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. name: test-pd
  6. spec:
  7. containers:
  8. - image: nginx
  9. name: test-container
  10. imagePullPolicy: IfNotPresent
  11. volumeMounts:
  12. - mountPath: /cache
  13. name: cache-volume
  14. volumes:
  15. - name: cache-volume
  16. emptyDir: {}

pod已经在worker1上运行:

  1. [root@clientvm ~]# kubectl get pod -n mytest -o wide
  2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  3. busybox 1/1 Running 43 5d 10.244.2.55 worker2.example.com <none> <none>
  4. dns 1/1 Running 42 4d22h 10.244.1.40 worker1.example.com <none> <none>
  5. test-pd 1/1 Running 0 3m24s 10.244.1.46 worker1.example.com <none> <none>
  6. [root@clientvm ~]# kubectl describe pod test-pd -n mytest
  7. ......
  8. Volumes:
  9. cache-volume:
  10. Type: EmptyDir (a temporary directory that shares a pod's lifetime)
  11. Medium:
  12. SizeLimit: <unset>

验证:

  1. [root@clientvm ~]# kubectl exec test-pd -n mytest -it -- bash
  2. root@test-pd:/# cd /cache/
  3. root@test-pd:/cache# touch aaa bbb ccc ddd
  4. root@test-pd:/cache# exit
  5. exit

worker1上,查找容器名字

  1. [root@worker1 ~]# docker ps | grep test-container
  2. 8c61c355f7bb bc9a0695f571 "/docker-entrypoint.…" 4 minutes ago Up 4 minutes k8s_test-container_test-pd_mytest_a75956a3-a140-4582-b02c-03f25163d3d2_0

查找dir

  1. [root@worker1 ~]# docker inspect 8c61c355f7bb | grep -A3 -B3 '/cache'
  2. ......
  3. "Mounts": [
  4. {
  5. "Type": "bind",
  6. "Source": "/var/lib/kubelet/pods/a75956a3-a140-4582-b02c-03f25163d3d2/volumes/kubernetes.io~empty-dir/cache-volume",
  7. "Destination": "/cache",
  8. "Mode": "Z",
  9. "RW": true,
  10. "Propagation": "rprivate"
  11. [root@worker1 ~]#
  12. [root@worker1 ~]# ll "/var/lib/kubelet/pods/a75956a3-a140-4582-b02c-03f25163d3d2/volumes/kubernetes.io~empty-dir/cache-volume"
  13. total 0
  14. -rw-r--r--. 1 root root 0 Dec 14 12:24 aaa
  15. -rw-r--r--. 1 root root 0 Dec 14 12:24 bbb
  16. -rw-r--r--. 1 root root 0 Dec 14 12:24 ccc
  17. -rw-r--r--. 1 root root 0 Dec 14 12:24 ddd

删除Pod后,发现dir也随之删除

  1. [root@clientvm ~]# kubectl delete -f emptyDir-pod.yaml -n mytest
  2. pod "test-pd" deleted
  3. [root@worker1 ~]# ll "/var/lib/kubelet/pods/a75956a3-a140-4582-b02c-03f25163d3d2/volumes/kubernetes.io~empty-dir/cache-volume"
  4. ls: cannot access /var/lib/kubelet/pods/a75956a3-a140-4582-b02c-03f25163d3d2/volumes/kubernetes.io~empty-dir/cache-volume: No such file or directory

限制emptyDir容量

  1. [root@clientvm ~]# cat empty-Dir-limit-pod.yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. name: test-pd
  6. spec:
  7. containers:
  8. - image: nginx
  9. name: test-container
  10. imagePullPolicy: IfNotPresent
  11. volumeMounts:
  12. - mountPath: /cache
  13. name: cache-volume
  14. volumes:
  15. - name: cache-volume
  16. emptyDir:
  17. sizeLimit: 2Gi
  1. [root@clientvm ~]# kubectl apply -f empty-Dir-limit-pod.yaml -n mytest
  2. pod/test-pd created
  3. [root@clientvm ~]# kubectl describe pod -n mytest test-pd
  4. ......
  5. Volumes:
  6. cache-volume:
  7. Type: EmptyDir (a temporary directory that shares a pod's lifetime)
  8. Medium:
  9. SizeLimit: 2Gi

hostPath

hostPath 卷能将主机节点文件系统上的文件或目录挂载到你的 Pod 中。

hostPath 的一些用法有:

  • 运行一个需要访问 Docker 内部机制的容器;可使用 hostPath 挂载 /var/lib/docker 路径。
  • 允许 Pod 指定给定的 hostPath 在运行 Pod 之前是否应该存在,是否应该创建以及应该以什么方式存在。

除了必需的 path 属性之外,用户可以选择性地为 hostPath 卷指定 type

取值 行为
空字符串(默认)用于向后兼容,这意味着在安装 hostPath 卷之前不会执行任何检查。
DirectoryOrCreate 如果在给定路径上什么都不存在,那么将根据需要创建空目录,权限设置为 0755,具有与 kubelet 相同的组和属主信息。
Directory 在给定路径上必须存在的目录。
FileOrCreate 如果在给定路径上什么都不存在,那么将在那里根据需要创建空文件,权限设置为 0644,具有与 kubelet 相同的组和所有权。
File 在给定路径上必须存在的文件。
Socket 在给定路径上必须存在的 UNIX 套接字。
CharDevice 在给定路径上必须存在的字符设备。
BlockDevice 在给定路径上必须存在的块设备。

配置范例:

  1. [root@clientvm ~]# cat hostPath-pod.yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. name: test-pd
  6. spec:
  7. containers:
  8. - image: nginx
  9. imagePullPolicy: IfNotPresent
  10. name: test-container
  11. volumeMounts:
  12. - mountPath: /test-pd
  13. name: test-volume
  14. volumes:
  15. - name: test-volume
  16. hostPath:
  17. path: /data
  18. # Optional
  19. type: DirectoryOrCreate
  1. [root@clientvm ~]# kubectl apply -f hostPath-pod.yaml
  2. pod/test-pd created
  3. [root@clientvm ~]# kubectl get pod -o wide
  4. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  5. test-pd 1/1 Running 0 99s 10.244.1.49 worker1.example.com <none> <none>
  6. [root@clientvm ~]# kubectl exec test-pd -it -- bash
  7. root@test-pd:/# cd /test-pd/
  8. root@test-pd:/test-pd# touch aaa bbb ccc ddd
  9. root@test-pd:/test-pd# exit
  10. exit

到worker1上验证:

  1. [root@worker1 ~]# cd /data/
  2. [root@worker1 data]# ll
  3. total 0
  4. -rw-r--r--. 1 root root 0 Dec 14 12:47 aaa
  5. -rw-r--r--. 1 root root 0 Dec 14 12:47 bbb
  6. -rw-r--r--. 1 root root 0 Dec 14 12:47 ccc
  7. -rw-r--r--. 1 root root 0 Dec 14 12:47 ddd

删除Pod后再查看:

  1. [root@clientvm ~]# kubectl delete -f hostPath-pod.yaml
  2. pod "test-pd" deleted
  3. [root@worker1 /]# ll /data/
  4. total 0
  5. -rw-r--r--. 1 root root 0 Dec 14 12:47 aaa
  6. -rw-r--r--. 1 root root 0 Dec 14 12:47 bbb
  7. -rw-r--r--. 1 root root 0 Dec 14 12:47 ccc
  8. -rw-r--r--. 1 root root 0 Dec 14 12:47 ddd

NFS

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: test-pd
  5. spec:
  6. containers:
  7. - image: nginx
  8. imagePullPolicy: IfNotPresent
  9. name: test-container
  10. volumeMounts:
  11. - mountPath: /usr/share/nginx/html
  12. name: test-volume
  13. volumes:
  14. - name: test-volume
  15. nfs:
  16. server: 192.168.198.128
  17. path: /data
  1. [root@clientvm ~]# kubectl apply -f pod-nfs.yaml -n mytest
  2. [root@clientvm ~]# cd /data/
  3. [root@clientvm data]# ls
  4. [root@clientvm data]# echo AAAAAAAAAAAAAA >index.html
  1. [root@master ~]# kubectl get pod -o wide -n mytest
  2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  3. ......
  4. test-pd 1/1 Running 0 6m43s 10.244.71.214 worker2.example.com <none> <none>
  5. [root@master ~]# curl 10.244.71.214
  6. AAAAAAAAAAAAAA

使用持久卷 Persistent Volume

理论基础

持久卷(PersistentVolume,PV)是集群中的一块存储,可以由管理员事先供应,或者 使用存储类(Storage Class)来动态供应。 持久卷是集群资源,就像节点也是集群资源一样。PV 持久卷和普通的 Volume 一样,也是使用 卷插件来实现的,只是它们拥有独立于任何使用 PV 的 Pod 的生命周期。 此 API 对象中记述了存储的实现细节,无论其背后是 NFS、iSCSI 还是特定于云平台的存储系统。

持久卷申明(PersistentVolumeClaim,PVC)表达的是用户对存储的请求。概念上与 Pod 类似。 Pod 会耗用节点资源,而 PVC 申领会耗用 PV 资源。Pod 可以请求特定数量的资源(CPU 和内存);同样 PVC 申领也可以请求特定的大小和访问模式 (例如,可以要求 PV 卷能够以 ReadWriteOnce、ReadOnlyMany 或 ReadWriteMany 模式之一来挂载,参见访问模式)。

回收策略

当用户不再使用其存储卷时,他们可以从 API 中将 PVC 对象删除,从而允许 该资源被回收再利用。PersistentVolume 对象的回收策略告诉集群,当其被 从申领中释放时如何处理该数据卷。 目前,数据卷可以被 Retained(保留)、 Deleted(删除)及Recycle(此策略已废弃)。

Retained(保留)
回收策略 Retain 使得用户可以手动回收资源。当 PersistentVolumeClaim 对象 被删除时,PersistentVolume 卷仍然存在,对应的数据卷被视为”已释放(released)”。 由于卷上仍然存在这前一申领人的数据,该卷还不能用于其他申领。 管理员可以通过下面的步骤来手动回收该卷:

  1. 删除 PersistentVolume 对象。与之相关的、位于外部基础设施中的存储资产 (例如 AWS EBS、GCE PD、Azure Disk 或 Cinder 卷)在 PV 删除之后仍然存在。
  2. 根据情况,手动清除所关联的存储资产上的数据。
  3. 手动删除所关联的存储资产;如果你希望重用该存储资产,可以基于存储资产的 定义创建新的 PersistentVolume 卷对象。

删除(Delete)
对于支持 Delete 回收策略的卷插件,删除动作会将 PersistentVolume 对象从 Kubernetes 中移除,同时也会从外部基础设施(如 AWS EBS、GCE PD、Azure Disk 或 Cinder 卷)中移除所关联的存储资产。 动态供应的卷会继承其 StorageClass 中设置的回收策略,该策略默认 为 Delete

访问模式

PersistentVolume 卷可以用资源提供者所支持的任何方式挂载到宿主系统上。 如下表所示,提供者(驱动)的能力不同,每个 PV 卷的访问模式都会设置为 对应卷所支持的模式值。 例如,NFS 可以支持多个读写客户,但是某个特定的 NFS PV 卷可能在服务器 上以只读的方式导出。每个 PV 卷都会获得自身的访问模式集合,描述的是 特定 PV 卷的能力。
访问模式有:

  • ReadWriteOnce — 卷可以被一个节点以读写方式挂载;
  • ReadOnlyMany — 卷可以被多个节点以只读方式挂载;
  • ReadWriteMany — 卷可以被多个节点以读写方式挂载。

在命令行接口(CLI)中,访问模式也使用以下缩写形式:

  • RWO - ReadWriteOnce
  • ROX - ReadOnlyMany
  • RWX - ReadWriteMany

范例

创建基于NFS的PV

  1. [root@clientvm ~]# cat nfs-pv.yaml
  2. apiVersion: v1
  3. kind: PersistentVolume
  4. metadata:
  5. name: nfs-pv1
  6. spec:
  7. capacity:
  8. storage: 100Mi
  9. accessModes:
  10. - ReadWriteMany
  11. persistentVolumeReclaimPolicy: Recycle
  12. nfs:
  13. server: 192.168.241.128
  14. path: "/data"
  15. [root@clientvm ~]# kubectl apply -f nfs-pv.yaml
  16. persistentvolume/nfs-pv1 created
  17. [root@clientvm ~]# kubectl get pv
  18. NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
  19. nfs-pv1 100Mi RWX Recycle Available 6s

创建PVC

  1. [root@clientvm ~]# cat pvc.yaml
  2. apiVersion: v1
  3. kind: PersistentVolumeClaim
  4. metadata:
  5. name: nfs-pvc1
  6. spec:
  7. accessModes:
  8. - ReadWriteMany
  9. storageClassName: ""
  10. resources:
  11. requests:
  12. storage: 100Mi
  13. [root@clientvm ~]# kubectl apply -f pvc.yaml
  14. persistentvolumeclaim/nfs1 created
  15. [root@clientvm ~]# kubectl get pv
  16. NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
  17. nfs-pv1 100Mi RWX Recycle Bound default/nfs-pvc1 15s
  18. [root@clientvm ~]# kubectl get pvc
  19. NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
  20. nfs-pvc1 Bound nfs-pv1 100Mi RWX 110s

创建Pod,使用PVC

  1. [root@clientvm ~]# cat pod-with-pvc.yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. name: task-pv-pod
  6. spec:
  7. volumes:
  8. - name: task-pv-storage
  9. persistentVolumeClaim:
  10. claimName: nfs-pvc1
  11. containers:
  12. - name: task-pv-container
  13. image: nginx
  14. imagePullPolicy: IfNotPresent
  15. ports:
  16. - containerPort: 80
  17. name: "http-server"
  18. volumeMounts:
  19. - mountPath: "/usr/share/nginx/html"
  20. name: task-pv-storage
  1. [root@clientvm ~]# kubectl apply -f pod-with-pvc.yaml
  2. pod/task-pv-pod created
  3. [root@clientvm ~]# kubectl get pod
  4. NAME READY STATUS RESTARTS AGE
  5. ......
  6. task-pv-pod 1/1 Running 0 13s

验证读写数据

  1. [root@clientvm ~]# kubectl exec task-pv-pod -it -- bash
  2. root@task-pv-pod:/# cd "/usr/share/nginx/html"
  3. root@task-pv-pod:/usr/share/nginx/html# ls
  4. root@task-pv-pod:/usr/share/nginx/html# echo AAAAAA >index.html
  5. root@task-pv-pod:/usr/share/nginx/html# exit
  6. exit
  7. [root@clientvm ~]# ls /data/
  8. index.html
  9. [root@clientvm ~]# cat /data/index.html
  10. AAAAAA

删除PVC与Pod,PV重新可用

  1. [root@clientvm ~]# kubectl delete -f pod-with-pvc.yaml
  2. pod "task-pv-pod" deleted
  3. [root@clientvm ~]# kubectl delete -f nfs-pvc.yaml
  4. persistentvolumeclaim "nfs-pvc1" deleted
  5. [root@clientvm ~]# kubectl get pv
  6. NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
  7. nfs-pv1 100Mi RWX Recycle Available 2m11s

使用StorageClass

创建基于NFS的StorageClass

参考: https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner

  1. [root@clientvm ~]# kubectl create namespace nfs-sc
  1. [root@clientvm ~]# kubectl apply -f /resources/yaml/nfs-storage-class/rbac.yaml
  2. [root@clientvm ~]# kubectl apply -f /resources/yaml/nfs-storage-class/deployment.yaml
  3. [root@clientvm ~]# kubectl apply -f /resources/yaml/nfs-storage-class/class.yaml
  4. [root@clientvm ~]# kubectl get sc
  5. NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
  6. managed-nfs-storage fuseim.pri/ifs Delete Immediate false 6m55s

创建PVC

  1. [root@clientvm ~]# cat sc-pvc.yaml
  2. kind: PersistentVolumeClaim
  3. apiVersion: v1
  4. metadata:
  5. name: test-pvc
  6. spec:
  7. accessModes:
  8. - ReadWriteMany
  9. storageClassName: managed-nfs-storage
  10. resources:
  11. requests:
  12. storage: 100Mi
  1. [root@clientvm ~]# kubectl apply -f sc-pvc.yaml
  2. persistentvolumeclaim/test-pvc created
  3. [root@clientvm ~]# kubectl get pvc
  4. NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
  5. test-pvc Bound pvc-17482f72-47c7-4409-9810-ce6ac1178a02 100Mi RWX managed-nfs-storage 9s

创建Pod

  1. [root@clientvm ~]# cat sc-pvc-pod.yaml
  2. kind: Pod
  3. apiVersion: v1
  4. metadata:
  5. name: test-pod-sc
  6. spec:
  7. containers:
  8. - name: test-pod-sc
  9. image: nginx
  10. imagePullPolicy: IfNotPresent
  11. volumeMounts:
  12. - name: nfs-pvc
  13. mountPath: "/usr/share/nginx/html/"
  14. restartPolicy: "Never"
  15. volumes:
  16. - name: nfs-pvc
  17. persistentVolumeClaim:
  18. claimName: test-pvc
  1. [root@clientvm ~]# kubectl apply -f sc-pvc-pod.yaml
  2. pod/test-pod-sc created
  3. [root@clientvm ~]# kubectl get pod
  4. NAME READY STATUS RESTARTS AGE
  5. ......
  6. test-pod-sc 1/1 Running 0 6s
  1. [root@clientvm ~]# kubectl exec test-pod-sc -it -- bash
  2. root@test-pod-sc:/# df -h
  3. Filesystem Size Used Avail Use% Mounted on
  4. ......
  5. 192.168.241.128:/data/default-test-pvc-pvc-17482f72-47c7-4409-9810-ce6ac1178a02 8.0G 3.9G 4.2G 48% /usr/share/nginx/html
  6. ......
  7. root@test-pod-sc:/# echo AAAAAAAAAAAA>/usr/share/nginx/html/index.html
  8. root@test-pod-sc:/# exit
  9. exit
  10. [root@clientvm ~]# ll /data/default-test-pvc-pvc-17482f72-47c7-4409-9810-ce6ac1178a02/
  11. total 4
  12. -rw-r--r--. 1 root root 13 Dec 14 17:12 index.html
  13. [root@clientvm ~]# cat /data/default-test-pvc-pvc-17482f72-47c7-4409-9810-ce6ac1178a02/index.html
  14. AAAAAAAAAAAA

删除PVC与Pod后,NFS上的数据也被删除

  1. [root@clientvm ~]# kubectl delete -f sc-pvc-pod.yaml
  2. pod "test-pod-sc" deleted
  3. [root@clientvm ~]# kubectl delete -f sc-pvc.yaml
  4. persistentvolumeclaim "test-pvc" deleted
  5. [root@clientvm ~]# ll /data/
  6. total 0

在StateFulset中使用StorageClass自动创建PV/PVC

  1. [root@clientvm ~]# cat statefulset-sc.yaml
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. name: nginx
  6. labels:
  7. app: nginx
  8. namespace: mytest
  9. spec:
  10. ports:
  11. - port: 80
  12. name: web
  13. clusterIP: None
  14. selector:
  15. app: nginx
  16. ---
  17. apiVersion: apps/v1
  18. kind: StatefulSet
  19. metadata:
  20. labels:
  21. app: nginx
  22. name: mystatefulset
  23. namespace: mytest
  24. spec:
  25. replicas: 3
  26. serviceName: nginx
  27. selector:
  28. matchLabels:
  29. app: nginx
  30. template:
  31. metadata:
  32. labels:
  33. app: nginx
  34. spec:
  35. containers:
  36. - image: nginx
  37. name: nginx
  38. imagePullPolicy: IfNotPresent
  39. ## volume
  40. volumeMounts:
  41. - name: www
  42. mountPath: /usr/share/nginx/html
  43. ## StorageClass
  44. volumeClaimTemplates:
  45. - metadata:
  46. name: www
  47. spec:
  48. accessModes: [ "ReadWriteOnce" ]
  49. storageClassName: "managed-nfs-storage"
  50. resources:
  51. requests:
  52. storage: 100Mi
  1. [root@clientvm ~]# kubectl get pod -n mytest
  2. NAME READY STATUS RESTARTS AGE
  3. ......
  4. mystatefulset-0 1/1 Running 0 15s
  5. mystatefulset-1 1/1 Running 0 12s
  6. mystatefulset-2 1/1 Running 0 7s
  7. [root@clientvm ~]# kubectl get pv
  8. NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
  9. nfs-pv1 100Mi RWX Recycle Available 102m
  10. pvc-85799af8-a9de-46fd-a268-b15edefb9eb5 100Mi RWO Delete Bound mytest/www-mystatefulset-2 managed-nfs-storage 13s
  11. pvc-b3529c5a-cb07-4823-87be-9c4961988c2b 100Mi RWO Delete Bound mytest/www-mystatefulset-1 managed-nfs-storage 18s
  12. pvc-c8faafe4-50a7-4ff4-acd7-9c45f3b5d4de 100Mi RWO Delete Bound mytest/www-mystatefulset-0 managed-nfs-storage 21s

设置默认StorageClass

  1. kubectl patch storageclass managed-nfs-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

或者

  1. [root@clientvm ~]# kubectl annotate storageclasses.storage.k8s.io managed-nfs-storage storageclass.kubernetes.io/is-default-class=true
  2. storageclass.storage.k8s.io/managed-nfs-storage annotated
  3. [root@clientvm ~]#
  4. [root@clientvm ~]# kubectl get sc
  5. NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
  6. managed-nfs-storage (default) fuseim.pri/ifs Delete Immediate false 2m41s