本文共 3287 字,大约阅读时间需要 10 分钟。
Kubernetes部分Volume类型介绍及yaml示例--NFS(网络数据卷)
#创建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"
#启动nginx_volume.yamlkubectl create -f ./nginx_volume.yaml
#查看Pod运行状态kubectl get po -n testNAME READY STATUS RESTARTS AGEnginx-test 1/1 Running 0 29s
#进入容器查看共享卷volumekubectl exec -it nginx-test /bin/bash --namespace=testroot@nginx-test:/# cd tmproot@nginx-test:/tmp# lslost+found sys##我们可以看到NFS服务器共享卷/data已经挂载进来了
#创建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=testroot@nginx-wtf-5774b87bdc-n97gr:/# cd tmproot@nginx-wtf-5774b87bdc-n97gr:/tmp# lslost+found sys
#查看下当前命名空间运行有挂载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=testroot@nginx-test:/# cd tmproot@nginx-test:/tmp# lsdatagrand lost+found sys##nginx-wtf-5774b87bdc-n97grkubectl exec -it nginx-wtf-5774b87bdc-n97gr /bin/bash --namespace=testroot@nginx-wtf-5774b87bdc-n97gr:/# cd tmproot@nginx-wtf-5774b87bdc-n97gr:/tmp# lsdatagrand lost+found sys##nginx-wtf-5774b87bdc-xpsnrkubectl exec -it nginx-wtf-5774b87bdc-xpsnr /bin/bash --namespace=testroot@nginx-wtf-5774b87bdc-xpsnr:/# cd tmproot@nginx-wtf-5774b87bdc-xpsnr:/tmp# lsdatagrand lost+found sys##说明:我们可以看到各Pod中容器内卷已有datagrand
转载于:https://blog.51cto.com/wutengfei/2124840