k8s pv pvc
2023-12-22 17:34 qgbo 阅读(2) 评论(0) 编辑 收藏 举报https://artifacthub.io/packages/helm/nfs-subdir-external-provisioner/nfs-subdir-external-provisioner
部署:
helm install -n nfs-provisioner nfs-subdir-external-provisioner-retain nfs-subdir-external-provisioner/nfs-subdir-external-provisioner --set nfs.server={IP} --set nfs.path=/nfsshare --set storageClass.reclaimPolicy=Retain --set storageClass.name=nfs-retain
这样部署之后,在statefulset 中使用这个 pv
然后删掉 namespace, 对应的PV 变为 release 状态.
再次部署,会生成新的PVC:
kubectl get pv, 就是没用用上之前的
kubectl get pvc:
如果要恢复数据: 删除 spec.claimRef, 重新部署即可
k get sc // 查看存储类
kubectl patch storageclass <your-class-name> -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}' // 设置默认存储类
如下代码测试本地的PVC:
apiVersion: v1
kind: PersistentVolume
metadata:
name: mypv
labels:
type: local
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
capacity:
storage: 10Gi
hostPath:
path: "/nfs"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: local-path-pvc
spec:
volumeName: mypv
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: docker.io/library/busybox
name: test-container
volumeMounts:
- mountPath: /cache
name: cache-volume
volumes:
- name: cache-volume
persistentVolumeClaim:
claimName: local-path-pvc
[root@master ~]# cat pv.yaml apiVersion: v1 kind: PersistentVolume metadata: name: storage-loki-0 labels: type: local spec: accessModes: - ReadWriteOnce storageClassName: "local-storage" capacity: storage: 10Gi hostPath: path: "/nfs" [root@master ~]# cat pvc.yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: foo-pvc spec: storageClassName: "local-storage" # Empty string must be explicitly set otherwise default StorageClass will be set accessModes: - ReadWriteOnce resources: requests: storage: 1Gi [root@master ~]# cat sc.yaml apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: local-storage #表示不需要自动创建PV provisioner: kubernetes.io/no-provisioner #WaitForFirstConsumer表示需要等到Pod运行之后才让PVC和PV绑定。因为在使用Local Persistent Volume的时候PV和对应的PVC必须 #要跟随Pod在同一node下面,否则会调度失败。 volumeBindingMode: WaitForFirstConsumer
气功波(18037675651)