根据K8S官方文档:



我已经创建了一个带有RWO访问模式的持久卷。我已经应用了PVC:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: readwriteonce-test
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi
  storageClassName: ""

和部署:
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: test-deployment
spec:
  selector:
    matchLabels:
      app: test-deployment
  replicas: 3
  template:
    metadata:
      labels:
        app: test-deployment
    spec:
      containers:
      - name: test-pod
        image: "gcr.io/google_containers/busybox:1.24"
        command:
          - "/bin/sh"
        args:
          - "-c"
          - "rm -R /data/*; while :; do ls /data/; name=$(date '+%s'); echo \"some data in file ${name}\" >> \"/data/${name}.txt\" ; sleep 10; cat \"/data/${name}.txt\"; done"
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - mountPath: /data
          name: test-volume
      restartPolicy: Always
      volumes:
      - name: test-volume
        persistentVolumeClaim:
          claimName: readwriteonce-test

持续体积:
Name:            readwriteonce-test
Labels:          volume-name=readwriteonce-test
Annotations:     kubectl.kubernetes.io/last-applied-configuration:
                   {"apiVersion":"v1","kind":"PersistentVolume","metadata":{"annotations":{},"labels":{"volume-name":"readwriteonce-test"},"name":"readwriteo...
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:
Status:          Bound
Claim:           ***/readwriteonce-test
Reclaim Policy:  Retain
Access Modes:    RWO
VolumeMode:      Filesystem
Capacity:        8Gi
Node Affinity:   <none>
Message:
Source:
    Type:      NFS (an NFS mount that lasts the lifetime of a pod)
    Server:    ***.efs.eu-west-1.amazonaws.com
    Path:      /readwriteonce-test
    ReadOnly:  false
Events:        <none>

问题是:

谁能解释我,为什么这样的配置没有错误?如您所见,每个Pod已安装在不同的节点上。每个 Pane 都可以查看其他 Pane 创建的文件。

screenshot

最佳答案

我只能确认,使用基于EFS的持久卷(在PVC请求规范中动态创建)基于EFS的持久卷时,我与您在测试EKS集群上具有相同的观察结果。

如下所示,我可以从两个不同的Pod(分别安排在不同的节点上)同时写入同一文件:

Hello from test-deployment-6f954f9f67-ljghs at 1583239308 on ip-192-168-68-xyz.us-west-2.compute.internal node
Hello from test-deployment-6f954f9f67-bl99s at 1583239308 on ip-192-168-49-abc.us-west-2.compute.internal node

相反,我宁愿期待类似的行为*,例如在其他PV类型支持所有类型的accessMode(RWO,RWX,ROX)的情况下:
Warning  FailedAttachVolume  103s  attachdetach-controller  Multi-Attach error for volume "pvc-badb4724-5d5a-11ea-8395-42010aa80131"

 Multi-Attach error for volume "pvc-badb4724-5d5a-11ea-8395-42010aa80131" Volume is already used by pod(s) test-deployment-xyz-...

*在调度程序尝试使用同一PV调度Pod的第二个副本时发生。

我认为这是基于NFS的存储的本质,它是EFS-provisioner的基础存储类型。

似乎我们不是唯一在那件事上理解官方文档有问题的人,请检查这些开放的github问题:#18714#60903

关于kubernetes - Kubernetes PersistentVolumes访问模式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60420095/

10-10 04:36