持久性存储
pv(PersistentVolume):基于全局,所有的namespace都可以看到并使用
pvc(PersistentVolumeClaims):基于namespace
详细信息:https://kubernetes.io/docs/concepts/storage/persistent-volumes/
使用nfs配置pv持久性存储
nfs server:192.168.199.101:/pv01 #详细nfs搭建教程https://www.jianshu.com/p/e9891e29ec6b
vim pv01.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv0001
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
storageClassName: slow
nfs:
path: /pv01
server: 192.168.199.101
#创建pv01
kubectl apply -f pv01.yaml
#获取pv
kubectl get pv
#查看pv信息
kubectl describe pv pv0001
在pv上配置pvc
vim pvc01.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: myclaim
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 5Gi
#storageClassName 要和pv的相同,才能使用同一块存储
storageClassName: slow
#创建pvc01
kubectl apply -f pvc01.yaml
#获取pvc
kubectl get pvc
pod使用pvc
vim nginx-pvc.yaml
kind: Pod
apiVersion: v1
metadata:
name: web-nginx
spec:
containers:
- name: web
image: nginx
volumeMounts:
- mountPath: "/var/www/html"
name: mypd
volumes:
- name: mypd
persistentVolumeClaim:
claimName: myclaim
#创建pod
kubectl apply -f nginx-pvc.yaml
网友评论