Pod配置PersistentVolumeClaim详解
1,创建PersistentVolume
kind: PersistentVolume
apiVersion: v1
metadata:
name: task-pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
执行上面配置文件后PersistentVolume被创建,通过命令查看
kubectl get pv
2,创建PersistentVolumeClaim
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: task-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
PersistentVolumeClaim已邦定到PersistentVolume,创建后通过命令查看
kubectl get pvc
3,创建Pod使用PersistentVolumeClaim
kind: Pod
apiVersion: v1
metadata:
name: task-pv-pod
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
containers:
- name: task-pv-container
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: task-pv-storage
容器目录/usr/share/nginx/html已挂载到宿主机/mnt/data
参考资料
https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/
https://kubernetes.io/docs/concepts/storage/persistent-volumes/
https://kubernetes.io/docs/tasks/administer-cluster/change-default-storage-class/