k8s数据卷(volume)管理
volume数据卷管理一、volume先容
用于实现数据的恒久化存储
Kubernetes支持多种范例的卷,比方EmptyDir、HostPath、nfs、glusterfs、ceph等
二、emptyDir
创建Pod时,Pod运行的node节点会创建暂时卷,并将卷挂载到Pod指定的目次中
暂时卷存放目次
/var/lib/kubelet/pods//volumes/kubernetes.io~empty-dir/卷名称
Pod宕机烧毁后,该暂时卷中的数据会随之被删除
apiVersion: apps/v1
kind: Deployment
metadata:
name: test1-deploy
spec:
replicas: 2
selector:
matchLabels:
app: test1-pod
template:
metadata:
labels:
app: test1-pod
spec:
containers:
- name: test1-pod
image: busybox
imagePullPolicy: IfNotPresent
command:
- sleep
- "3600"
volumeMounts:
- name: test1-volume
mountPath: /test1
volumes:
- name: test1-volume
emptyDir: {}
三、hostPath
创建Pod时,Pod运行的node节点会在本地创建目次,并该目次挂载到Pod中
Pod宕机后,宿主机对应目次中的文件不会消散
apiVersion: apps/v1
kind: Deployment
metadata:
name: test2-deploy
labels:
app: test2-deploy
spec:
replicas: 2
selector:
matchLabels:
app: test2-pod
template:
metadata:
labels:
app: test2-pod
spec:
containers:
- name: test2-pod
image: busybox
imagePullPolicy: IfNotPresent
command:
- sleep
- "3600"
volumeMounts:
- name: test2-volume
mountPath: /test1
volumes:
- name: test2-volume
hostPath:
path: /data
四、基于nfs的网络卷
apiVersion: apps/v1
kind: Deployment
metadata:
name: test3-deploy
labels:
app: test3-deploy
spec:
replicas: 2
selector:
matchLabels:
app: test3-pod
template:
metadata:
labels:
app: test3-pod
spec:
containers:
- name: test3-pod
image: busybox
imagePullPolicy: IfNotPresent
command:
- sleep
- "3600"
volumeMounts:
- name: test3-volume
mountPath: /test1
volumes:
- name: test3-volume
nfs:
server: "192.168.140.11"
path: "/data"
五、PV与PVC 恒久卷
1、PV、PVC先容
PV PersistentVolume
后端真实存储空间的映射
PVC PersistentVolumeClain
利用存储空间的申请
利用流程
创建PV标识真实的存储空间
创建PVC发送申请存储空间的哀求,K8S集群会主动在PV、PVC间创建映射关系
创建映射关系:
依靠存储空间的巨细
依靠PV的访问模式
创建POD时绑定PVC,实现恒久化
1、创建PV
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-data1
spec:
capacity:
storage: 2G
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
server: 192.168.140.13
path: /data1
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!qidao123.com:ToB企服之家,中国第一个企服评测及软件市场,开放入驻,技术点评得现金
页:
[1]