赞
踩
创建一个pv,名字为app-config,大小为2Gi,访问模式为ReadWriteMany。Volume的类型为hostPath,路径为/srv/app-config
app-config.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: app-config
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 2Gi
accessModes:
- ReadWriteMany
hostPath:
path: "/srv/app-config"
kubectl create -f app-config.yaml
创建一个名字为pv-volume的pvc,指定storageClass为csi-hostpath-sc,大小为10Mi
然后创建一个Pod,名字为web-server,镜像为nginx,并且挂载该PVC至/usr/share/nginx/html,挂载的权限为ReadWriteOnce。之后通过kubectl edit或者kubectl path将pvc改成70Mi,并且记录修改记录。
使用参考中的github项目的examples中的csi-storageclass.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: csi-hostpath-sc
provisioner: hostpath.csi.k8s.io
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowVolumeExpansion: true
pv-volume-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-volume
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Mi
storageClassName: csi-hostpath-sc
web-server-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: web-server
spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: pv-volume
volumes:
- name: pv-volume
persistentVolumeClaim:
claimName: pv-volume
命令
kubectl create -f pv-volume-pvc.yaml
kubectl create -f web-server-pod.yaml
可以看到pvc和Pod均创建成功。
k8s学习-持久化存储(Volumes、hostPath、emptyDir、PV、PVC)详解与实战
github-csi-driver-host-path
更多k8s相关内容,请看文章:k8s学习-思维导图与学习笔记
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。