Kubernetes section Volume type Introduction and YAML sample--NFS (network data volume)
persistent volume kubernetes
- kubernetes persistent volume
- Description
NFS volumes allow existing NFS (network file system) shares to be mounted in your container. Unlike Emptydir, when the Pod is deleted, kubernetes persistent volumes example the contents of the NFS volume are retained and the volume is simply unloaded. This means that the NFS volume can pre-populate the data, kubernetes volumes and it can "toggle" the data between the pods. NFS can be mounted simultaneously by multiple writers.
-
- kubernetes volume mounts
- Deploying Server for NFS
For deployment of NFS, kubernetes volume mount refer to NFS Deployment and optimization (i)persistent volume claim
- File sharing in the actual pod
#创建yaml文件cat >> nginx_volume.yaml << EOFapiVersion: v1kind: Podmetadata: name: nginx-test namespace: test labels: app: nginxspec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80 volumeMounts: #Mount the path to the container - mountPath: "/tmp/" name: pv0003 volumes: - name: pv0003 nfs: #fixed:This ip is the address of the nfs server server: 192.168.246.169 #fixed:This path is shared externally by the nfs server path: "/data"
#查看Pod运行状态kubectl get po -n testNAME READY STATUS RESTARTS AGEnginx-test 1/1 Running 0 29s
#进入容器查看共享卷volumekubectl exec -it nginx-test /bin/bash --namespace=test[email protected]:/# cd tmp[email protected]:/tmp# lslost+found sys##我们可以看到NFS服务器共享卷/data已经挂载进来了
- Multi-container sharing between multiple pods in real combat
#创建deploymentcat >> deploy_volume.yaml << EOFapiVersion: extensions/v1beta1kind: Deploymentmetadata: name: nginx-wtf namespace: testspec: replicas: 2 template: metadata: labels: app: wtf spec: containers: - name: nginx-wtf image: nginx:1.7.9 ports: - containerPort: 81 volumeMounts: - name: pv0003 mountPath: /tmp/ volumes: - name: pv0003 nfs: server: 192.168.246.169 path: "/data/"
#启动deploymentkubectl create -f ./deploy_volume.yaml
#查看Pods的运行状态NAME READY STATUS RESTARTS AGEnginx-wtf-5774b87bdc-n97gr 1/1 Running 0 32mnginx-wtf-5774b87bdc-xpsnr 1/1 Running 0 32m
#进入容器查看共享卷volumekubectl exec -it nginx-wtf-5774b87bdc-n97gr /bin/bash --namespace=test[email protected]:/# cd tmp[email protected]:/tmp# lslost+found sys
- Operation of the actual volume
#查看下当前命名空间运行有挂载NFS卷的Podskubectl get po -n testNAME READY STATUS RESTARTS AGEnginx-test 1/1 Running 0 2mnginx-wtf-5774b87bdc-n97gr 1/1 Running 0 36mnginx-wtf-5774b87bdc-xpsnr 1/1 Running 0 36m##在命名空间test里运行有三个Pods
#在NFS服务端对共享卷进行操作##创建目录datagrandmkdir /data/datagrand
#查看各Pod中容器内卷的变化##nginx-testkubectl exec -it nginx-test /bin/bash --namespace=test[email protected]:/# cd tmp[email protected]:/tmp# lsdatagrand lost+found sys##nginx-wtf-5774b87bdc-n97grkubectl exec -it nginx-wtf-5774b87bdc-n97gr /bin/bash --namespace=test[email protected]:/# cd tmp[email protected]:/tmp# lsdatagrand lost+found sys##nginx-wtf-5774b87bdc-xpsnrkubectl exec -it nginx-wtf-5774b87bdc-xpsnr /bin/bash --namespace=test[email protected]:/# cd tmp[email protected]:/tmp# lsdatagrand lost+found sys##说明:我们可以看到各Pod中容器内卷已有datagrand
Kubernetes section Volume type Introduction and YAML sample--NFS (network data volume)
volume mount kubernetes