2

那里,

根据文档:

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

有人知道为什么会这样吗?

4

1 回答 1

1

accessModes 取决于存储提供程序。对于 NFS,它们并没有真正做任何不同的事情,但是 HostPath 应该正确使用这些模式。

有关所有各种选项,请参见下表:http: //kubernetes.io/docs/user-guide/persistent-volumes/#access-modes

于 2016-11-16T03:08:05.773 回答