{"id":555,"title":"kubernetes-\u5b58\u50a8\u62bd\u8c61pv&pvc","good":0,"bad":0,"hit":1028,"created_at":"2023-01-06 07:04:21","content":"
\u7531\u4e8edeployment\u90e8\u7f72\u751f\u6210\u7684pod\u5177\u6709\u6545\u969c\u8f6c\u79fb\u529f\u80fd\uff0c\u5047\u5982\u67d0\u4e2apod\u6302\u4e86\uff0c\u91cd\u542f\u540e\u53ef\u80fd\u4eceA\u673a\u5668\u90e8\u7f72\u5230B\u673a\u5668\u4e86\uff0c\u5982\u679c\u6570\u636e\u5b58\u50a8\u5728A\u673a\u5668\u4e0a\uff0c\u5219B\u673a\u5668\u4e0a\u542f\u52a8\u7684POD\u5c31\u53ef\u80fd\u6ca1\u6709\u6570\u636e\uff1b
<\/p>
\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u7528\u7684\u6587\u4ef6\u5b58\u50a8<\/p>
\u3010\u4e00\u79cd\u662f\u901a\u8fc7\u6587\u4ef6\u5171\u4eab\u7684\u65b9\u5f0f\u3011\uff1a<\/p>
#\u6240\u6709\u673a\u5668\u5b89\u88c5nfs\u6587\u4ef6\u7cfb\u7edf<\/p>
yum install -y nfs-utils<\/p>
<\/p>
#nfs\u4e3b\u8282\u70b9\u4e0a\u6267\u884c<\/p>
echo "\/nfs\/data\/ *(insecure,rw,sync,no_root_squash)" > \/etc\/exports<\/p>
mkdir -p \/nfs\/data
<\/p>
systemctl enable rpcbind --now<\/p>
systemctl enable nfs-server --now<\/p>
#\u914d\u7f6e\u751f\u6548<\/p>
exportfs -r<\/p>
<\/p>
\u4ece\u8282\u70b9\u4e0a\u6302\u8f7d\uff0c\u5982\u679c\u6ca1\u6709\u4ece\u8282\u70b9\u53ef\u4e0d\u6267\u884c\uff08ip\u6539\u4e3a\u4e3b\u8282\u70b9\u7684\uff09<\/span><\/p> showmount -e 172.31.0.4<\/p> #\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6302\u8f7d nfs \u670d\u52a1\u5668\u4e0a\u7684\u5171\u4eab\u76ee\u5f55\u5230\u672c\u673a\u8def\u5f84 \/root\/nfsmount<\/p> mkdir -p \/nfs\/data<\/p> mount -t nfs 172.31.0.4:\/nfs\/data \/nfs\/data<\/p> # \u5199\u5165\u4e00\u4e2a\u6d4b\u8bd5\u6587\u4ef6<\/p> echo "hello nfs server" > \/nfs\/data\/test.txt<\/p> ------------------\u539f\u751f\u6570\u636e\u6302\u8f7d,\uff0c\u53d1\u751f\u6545\u969c\u8f6c\u79fb\u65f6\u5c31\u6709\u95ee\u9898\u4e86--------------------<\/p> apiVersion: apps\/v1<\/p> kind: Deployment<\/p> metadata:<\/p> labels:<\/p> app: nginx-pv-demo<\/p> name: nginx-pv-demo<\/p> spec:<\/p> replicas: 2<\/p> selector:<\/p> matchLabels:<\/p> app: nginx-pv-demo<\/p> template:<\/p> metadata:<\/p> labels:<\/p> app: nginx-pv-demo<\/p> spec:<\/p> containers:<\/p> - image: nginx<\/p> name: nginx<\/p> volumeMounts:<\/p> - name: html<\/p> mountPath: \/usr\/share\/nginx\/html<\/p> volumes:<\/p> - name: html<\/p> nfs:<\/p> server: 172.31.0.4<\/p> path: \/nfs\/data\/nginx-pv<\/p> PV\uff1a\u6301\u4e45\u5377\uff08Persistent Volume\uff09\uff0c\u5c06\u5e94\u7528\u9700\u8981\u6301\u4e45\u5316\u7684\u6570\u636e\u4fdd\u5b58\u5230\u6307\u5b9a\u4f4d\u7f6e<\/em><\/p> PVC\uff1a\u6301\u4e45\u5377\u7533\u660e\uff08<\/em>Persistent Volume Claim<\/em>\uff09\uff0c\u7533\u660e\u9700\u8981\u4f7f\u7528\u7684\u6301\u4e45\u5377\u89c4\u683c<\/em><\/p> \u9759\u6001\u4f9b\u5e94\uff08\u5148\u521b\u5efa\u597d\u5b58\u50a8\u7a7a\u95f4\uff09\uff0c\u4e5f\u6709\u52a8\u6001\u4f9b\u5e94\u65b9\u5f0f\uff08\u6839\u636epvc\u4e2d\u7684\u5927\u5c0f\u81ea\u52a8\u751f\u6210\uff09<\/span><\/p> #nfs\u4e3b\u8282\u70b9\u4e0a\u521b\u5efa3\u4e2a\u5b58\u50a8\u76ee\u5f55<\/p> mkdir -p \/nfs\/data\/01<\/p> mkdir -p \/nfs\/data\/02<\/p> mkdir -p \/nfs\/data\/03<\/p> #\u89c4\u5b9a\u6bcf\u4e2a\u76ee\u5f55\u5b58\u50a8\u7684\u5927\u5c0f\uff0c\u4f9d\u6b21\u4e3a10M\uff0c1G\uff0c3G<\/p> apiVersion: v1<\/p> kind: PersistentVolume<\/p> metadata:<\/p> name: pv01-10m<\/p> spec:<\/p> capacity:<\/p> storage: 10M<\/p> accessModes:<\/p> - ReadWriteMany<\/p> storageClassName: nfs<\/p> nfs:<\/p> path: \/nfs\/data\/01<\/p> server: 172.31.0.4<\/p> ---<\/p> apiVersion: v1<\/p> kind: PersistentVolume<\/p> metadata:<\/p> name: pv02-1gi<\/p> spec:<\/p> capacity:<\/p> storage: 1Gi<\/p> accessModes:<\/p> - ReadWriteMany<\/p> storageClassName: nfs<\/p> nfs:<\/p> path: \/nfs\/data\/02<\/p> server: 172.31.0.4<\/p> ---<\/p> apiVersion: v1<\/p> kind: PersistentVolume<\/p> metadata:<\/p> name: pv03-3gi<\/p> spec:<\/p> capacity:<\/p> storage: 3Gi<\/p> accessModes:<\/p> - ReadWriteMany<\/p> storageClassName: nfs<\/p> nfs:<\/p> path: \/nfs\/data\/03<\/p> server: 172.31.0.4<\/p> \u521b\u5efaPVC\uff08\u5199\u4e00\u4e2a\u7533\u8bf7\uff0c\u9700\u8981200M\u7a7a\u95f4\uff0c\u7cfb\u7edf\u6839\u636e\u9759\u6001\u914d\u7f6e\u7684\u5927\u5c0f\uff0c\u9009\u62e9\u4e00\u5757\u5408\u9002\u7684\u5b58\u50a8\u76ee\u5f55\uff0c\u8fd9\u91cc\u4f1a\u9009\u62e91G\u7684\uff09<\/span><\/p> kind: PersistentVolumeClaim<\/p> apiVersion: v1<\/p> metadata:<\/p> name: nginx-pvc<\/p> spec:<\/p> accessModes:<\/p> - ReadWriteMany<\/p> resources:<\/p> requests:<\/p> storage: 200Mi<\/p> storageClassName: nfs<\/p> \u521b\u5efaPod\u7ed1\u5b9aPVC<\/span><\/p> apiVersion: apps\/v1<\/p> kind: Deployment<\/p> metadata:<\/p> labels:<\/p> app: nginx-deploy-pvc<\/p> name: nginx-deploy-pvc<\/p> spec:<\/p> replicas: 2<\/p> selector:<\/p> matchLabels:<\/p> app: nginx-deploy-pvc<\/p> template:<\/p> metadata:<\/p> labels:<\/p> app: nginx-deploy-pvc<\/p> spec:<\/p> containers:<\/p> - image: nginx<\/p> name: nginx<\/p> volumeMounts:<\/p> - name: html<\/p> mountPath: \/usr\/share\/nginx\/html<\/p> volumes:<\/p> - name: html<\/p> persistentVolumeClaim:<\/p> claimName: nginx-pvc<\/p>
<\/p>
<\/p>
<\/p>1\u3001PV&PVC<\/span><\/h2>
<\/em><\/p>
<\/p>
<\/p>
<\/p>
<\/p>PVC\u521b\u5efa\u4e0e\u7ed1\u5b9a<\/span><\/h3>
<\/p>
<\/p>
<\/p>
<\/p>
<\/p>"}