NFS服务:
安装包:yum install -y nfs-utils rpcbind
创建:mkdir /nfsdata
授权:vim /etc/exports
/nfsdata *(rw,sync,no_root_squash)
起服务:systemctl start rpcbind
systemctl start nfs-server
查看:showmount -e 192.168.52.10
PV:persistentVolume(坚固的,持久的)
PVC:PersistentVolueClaim(需求,请求PV)
accessModes:访问模式
ReadwriteOnce:能以read-write模式mount到单个节点。
ReadwriteMany:能以read-write模式mount到多个节点。
ReadOnlyOnce:以只读的模式mount到单个节点。
ReadOnlyMany:以只读的模式mount到多个节点。
PV的回收策略:
Recycle:清除PV中的数据。
Retain:需要手动回收。
Delete(清除云存储):删除storage provider上的对应的存储资源。如 AWS EBS,GCE PD,Azure Disk,Openstack Cinder Volume等。
PV yaml文件:
vim nfs-pv1.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mypv1
spec:
capacity:
storage: 1Gi
accessModes: #访问模式
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle #PV的回收策略
storageClassName: nfs #标签,关联用
nfs:
path: /nfsdata/pv1
server: 192.168.52.10
PVC yaml文件:
vim nfs-pvc1.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypvc1
spec:
accessModes:
- ReadwriteOnce
resources: #资源
requests: #申请
storage: 1Gi #存储空间1G
storageClassName: nfs #标签指向nfs
一个PV能被多个PVC关联。
创建一个pod:
[root@master ~]# vim pod1.yaml
apiVersion: v1
kind: Pod
metadata:
name: mypod1
spec:
containers:
- name: mypod1
image: busybox
args:
- /bin/sh
- -c
- sleep 30000
volumeMounts:
- mountPath: ‘/mydata’ #挂载路径
name: mydata
volumes: #解释
- name: mydata
persistentVolumeClaim:
claimName: mypvc1
MySQL如何利用PV和PVC
附件:mysql-pv
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
persistentVolumeReclaimPolicy: Retain
storageClassName: nfs
nfs:
path: /nfsdata/mysql-pv
server: 192.168.190.10
附件:mysql-pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: nfs
附件:mysql
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: 123.com
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pvc
---
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql