标签:kubernetes volume nfs Volume类型介绍 yaml
Kubernetes部分Volume类型介绍及yaml示例--NFS(网络数据卷)#创建yaml文件
cat >> nginx_volume.yaml << EOF
apiVersion: v1
kind: Pod
metadata:
name: nginx-test
namespace: test
labels:
app: nginx
spec:
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.yaml
kubectl create -f ./nginx_volume.yaml
#查看Pod运行状态
kubectl get po -n test
NAME READY STATUS RESTARTS AGE
nginx-test 1/1 Running 0 29s
#进入容器查看共享卷volume
kubectl exec -it nginx-test /bin/bash --namespace=test
root@nginx-test:/# cd tmp
root@nginx-test:/tmp# ls
lost+found sys
##我们可以看到NFS服务器共享卷/data已经挂载进来了
#创建deployment
cat >> deploy_volume.yaml << EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-wtf
namespace: test
spec:
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/"
#启动deployment
kubectl create -f ./deploy_volume.yaml
#查看Pods的运行状态
NAME READY STATUS RESTARTS AGE
nginx-wtf-5774b87bdc-n97gr 1/1 Running 0 32m
nginx-wtf-5774b87bdc-xpsnr 1/1 Running 0 32m
#进入容器查看共享卷volume
kubectl exec -it nginx-wtf-5774b87bdc-n97gr /bin/bash --namespace=test
root@nginx-wtf-5774b87bdc-n97gr:/# cd tmp
root@nginx-wtf-5774b87bdc-n97gr:/tmp# ls
lost+found sys
#查看下当前命名空间运行有挂载NFS卷的Pods
kubectl get po -n test
NAME READY STATUS RESTARTS AGE
nginx-test 1/1 Running 0 2m
nginx-wtf-5774b87bdc-n97gr 1/1 Running 0 36m
nginx-wtf-5774b87bdc-xpsnr 1/1 Running 0 36m
##在命名空间test里运行有三个Pods
#在NFS服务端对共享卷进行操作
##创建目录datagrand
mkdir /data/datagrand
#查看各Pod中容器内卷的变化
##nginx-test
kubectl exec -it nginx-test /bin/bash --namespace=test
root@nginx-test:/# cd tmp
root@nginx-test:/tmp# ls
datagrand lost+found sys
##nginx-wtf-5774b87bdc-n97gr
kubectl exec -it nginx-wtf-5774b87bdc-n97gr /bin/bash --namespace=test
root@nginx-wtf-5774b87bdc-n97gr:/# cd tmp
root@nginx-wtf-5774b87bdc-n97gr:/tmp# ls
datagrand lost+found sys
##nginx-wtf-5774b87bdc-xpsnr
kubectl exec -it nginx-wtf-5774b87bdc-xpsnr /bin/bash --namespace=test
root@nginx-wtf-5774b87bdc-xpsnr:/# cd tmp
root@nginx-wtf-5774b87bdc-xpsnr:/tmp# ls
datagrand lost+found sys
##说明:我们可以看到各Pod中容器内卷已有datagrand
Kubernetes部分Volume类型介绍及yaml示例--NFS(网络数据卷)
标签:kubernetes volume nfs Volume类型介绍 yaml
原文地址:http://blog.51cto.com/wutengfei/2124840