>那里,
根据文档:
ReadWriteOnce – the volume can be mounted as read-write by a single node
我创建了一个基于 nfs 的 PV:
apiVersion: v1
kind: PersistentVolume
metadata:
name: tspv01
spec:
capacity:
storage: 15Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /gpfs/fs01/shared/prod/democluster01/dashdb/gamestop/spv01
server: 169.55.11.79
此 PV 的 PVC:
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: sclaim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 15Gi
创建 PVC 绑定到 PV 后:
root@hydra-cdsdev-dal09-0001:~/testscript# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
sclaim Bound tspv01 15Gi RWO 4m
然后我使用相同的 PVC 创建了 2 个 POD:
POD1:
kind: Pod
apiVersion: v1
metadata:
name: mypodshared1
labels:
name: frontendhttp
spec:
containers:
- name: myfrontend
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: mypd
volumes:
- name: mypd
persistentVolumeClaim:
claimName: sclaim
POD2:
kind: Pod
apiVersion: v1
metadata:
name: mypodshared2
labels:
name: frontendhttp
spec:
containers:
- name: myfrontend
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: mypd
volumes:
- name: mypd
persistentVolumeClaim:
claimName: sclaim
创建 2 个 POD 后,它们被分配给 2 个不同的节点。我可以执行到容器中,并且可以在 nfs 挂载的文件夹中读写。
root@hydra-cdsdev-dal09-0001:~/testscript# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
mypodshared1 1/1 Running 0 18s 172.17.52.7 169.45.189.108
mypodshared2 1/1 Running 0 36s 172.17.83.9 169.45.189.116
有人知道为什么会这样吗?
访问模式取决于存储提供程序。对于 NFS,它们实际上并没有做任何不同的事情,但 HostPath 应该正确使用这些模式。
有关所有各种选项,请参阅下表:http://kubernetes.io/docs/user-guide/persistent-volumes/#access-modes