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能不能調用之前的圖片。