一、emptydir
删除pod,数据丢失,pod启动,数据持久。
kubecrl delete -f :这个数据会丢失
docker rm -f :这个数据不会丢失
适合存储日志
spec:nodeName: 10.0.0.13volumes:- name: mysqlemptyDir: {}containers:- name: wp-mysqlimage: 10.0.0.11:5000/mysql:5.7imagePullPolicy: IfNotPresentports:- containerPort: 3306volumeMounts:- mountPath: /var/lib/mysqlname: mysql
二、HostPath
适合做web服务的数据共享
nodeName: 10.0.0.13 ,但是需要通过nadeName来固定主机,不让pod飘来飘去。如果不设置nadeName还是实现不了数据持久化
spec:nodeName: 10.0.0.12volumes:- name: mysqlhostPath:path: /data/wp_mysqlnodeName: 10.0.0.13
containers:- name: wp-mysqlimage: 10.0.0.11:5000/mysql:5.7imagePullPolicy: IfNotPresentports:- containerPort: 3306volumeMounts:- mountPath: /var/lib/mysqlname: mysql
nfs
volumes:- name: mysqlnfs:path: /data/wp_mysqlserver: 10.0.0.11
查看yaml文件的意思
[root@k8s-master vloume]# kubectl explain pv.spec.persistentVolumeReclaimPolicy
FIELD: persistentVolumeReclaimPolicy <string>
DESCRIPTION:
What happens to a persistent volume when released from its claim. Valid
options are Retain (default) and Recycle. Recycling must be supported by the
volume plugin underlying this persistent volume. More info:
http://kubernetes.io/docs/user-guide/persistent-volumes#recycling-policy
有问题请加博主微信进行沟通!
全部评论