1.找个机器搭建NFS

#master节点安装nfs
yum -y install nfs-utils

#创建nfs目录
mkdir -p /nfs/data/

#修改权限
chmod -R 777 /nfs/data

#编辑export文件
vim /etc/exports
/nfs/data *(rw,no_root_squash,sync)

#配置生效
exportfs -r
#查看生效
exportfs

#启动rpcbind、nfs服务
systemctl restart rpcbind && systemctl enable rpcbind
systemctl restart nfs && systemctl enable nfs

#查看 RPC 服务的注册状况
rpcinfo -p localhost

#showmount测试
showmount -e 192.168.92.56

#所有node节点安装客户端
yum -y install nfs-utils
systemctl start nfs && systemctl enable nfs

------------
#创建pv卷对应的目录
mkdir -p /nfs/data/pv001
mkdir -p /nfs/data/pv002

#配置exportrs
vim /etc/exports
/nfs/data *(rw,no_root_squash,sync)
/nfs/data/pv001 *(rw,no_root_squash,sync)
/nfs/data/pv002 *(rw,no_root_squash,sync)

#配置生效
exportfs -r
#重启rpcbind、nfs服务
systemctl restart rpcbind && systemctl restart nfs

2.创建PV

[centos@k8s-master ~]$ vim nfs-pv001.yaml 
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv001
labels:
pv: nfs-pv001
spec:
capacity:
storage: 100Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
storageClassName: nfs
nfs:
path: /nfs/data/pv001
server: 172.23.0.12



kubectl apply -f nfs-pv001.yaml

3.创建PVC

[centos@k8s-master ~]$ vim nfs-pvc001.yaml               
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc001
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Gi
storageClassName: nfs
selector:
matchLabels:
pv: nfs-pv001



kubectl apply -f nfs-pvc001.yaml
kubectl get pv
kubectl get pvc
ok gogogogo...

4.创建或者修改POD应用部署

{
"kind": "Deployment",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "hs-jd-zhineng",
"namespace": "default",
"selfLink": "/apis/extensions/v1beta1/namespaces/default/deployments/hs-jd-zhineng",
"uid": "05339eec-4348-4447-bcd2-2d7381731212",
"resourceVersion": "13608547",
"generation": 6,
"creationTimestamp": "2019-11-04T04:33:44Z",
"labels": {
"k8s-app": "hs-jd-zhineng"
},
"annotations": {
"deployment.kubernetes.io/revision": "6"
}
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"k8s-app": "hs-jd-zhineng"
}
},
"template": {
"metadata": {
"name": "hs-jd-zhineng",
"creationTimestamp": null,
"labels": {
"k8s-app": "hs-jd-zhineng"
}
},
"spec": {
"volumes": [
{
"name": "nfs-pv001",
"persistentVolumeClaim": {
"claimName": "nfs-pvc001"
}
}
],
"containers": [
{
"name": "hs-jd-zhineng",
"image": "registry.cn-hangzhou.aliyuncs.com/xxxxxxxxxxx",
"resources": {},
"volumeMounts": [
{
"name": "nfs-pv001",
"mountPath": "/var/lib/odoo" /****这里是程序路径
}
],
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"imagePullPolicy": "Always",
"securityContext": {
"privileged": false
}
}
],
"restartPolicy": "Always",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"securityContext": {},
"imagePullSecrets": [
{
"name": "s"
}
],
"schedulerName": "default-scheduler"
}
},
"strategy": {
"type": "RollingUpdate",
"rollingUpdate": {
"maxUnavailable": "25%",
"maxSurge": "25%"
}
},
"revisionHistoryLimit": 10,
"progressDeadlineSeconds": 600
},
"status": {
"observedGeneration": 6,
"replicas": 1,
"updatedReplicas": 1,
"readyReplicas": 1,
"availableReplicas": 1,
"conditions": [
****
]
}
}

5.在应用内上传图片,然后删除容器组测试,看看新创建的pod能不能调用之前的图片。