【问题标题】:GKE: right way to mount same PV on multiple podsGKE:在多个 pod 上安装相同 PV 的正确方法
【发布时间】:2019-02-12 23:16:22
【问题描述】:

我无法创建可以从不同 pod 使用的持久卷(1 次写入,另一次读取)。

尝试在 pod 规范中直接使用 gcePersistentDisk,就像 k8s 页面上的示例一样(加上 readOnly):

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: gcr.io/google_containers/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
      readOnly: true
  volumes:
  - name: test-volume
    gcePersistentDisk:
      pdName: my-data-disk
      fsType: ext4
      readOnly: true

然后在第二个 pod 规范中除了 readOnly 之外完全相同...但出现 NoDiskConflict 错误。

第二种方法是像这样使用PersistentVolumePersistentVolumeClaim

apiVersion: v1
kind: PersistentVolume
metadata:
  name: data-standard
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  gcePersistentDisk:
    fsType: ext4
    pdName: data

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-standard-claim
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi

但现在我收到一条错误消息告诉我:

MountVolume.MountDevice failed for volume "kubernetes.io/gce-pd/xxx" (spec.Name: "yyy") pod "6ae34476-6197-11e7-9da5-42010a840186" (UID: "6ae34476-6197-11e7-9da5-42010a840186") with: mount failed: exit status 32 Mounting command: mount Mounting arguments: /dev/disk/by-id/google-gke-cluster-xxx /var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gke-cluster-xxx [ro] Output: mount: wrong fs type, bad option, bad superblock on /dev/sdb, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so.
Error syncing pod, skipping: timeout expired waiting for volumes to attach/mount for pod "default"/"my-deployment". list of unattached/unmounted volumes=[data]

那么如何正确使用 GCE 磁盘与多个 pod。

PS:Kubernetes 1.6.6

【问题讨论】:

    标签: kubernetes google-kubernetes-engine


    【解决方案1】:

    根据https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes,GCE 磁盘不支持 ReadWriteMany。我不确定这是否能解释问题,但我建议您尝试其他兼容的卷类型。

    【讨论】:

    • ReadWriteOnce 使用第二种方法似乎可行,但会创建一个新 PV 而不是使用已经存在的 PV
    • 可能启用了动态配置,因此它会尝试创建一个新 PV,而忽略实际存在的内容。
    【解决方案2】:

    你可以用ReadOnlyMany代替ReadWriteMany吗?

    访问模式:

    ReadWriteOnce – 卷可以被单个节点以读写方式挂载

    ReadOnlyMany – 卷可以被许多节点以只读方式挂载

    ReadWriteMany – 卷可以被许多节点以读写方式挂载

    GCE 永久磁盘不支持ReadWriteMany

    这里是提供者列表和支持的访问模式:

    https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes

    【讨论】:

    • 我将ReadWriteOnce 理解为“一次写入”但“到处读取”......但我错了:(
    • 有一个GKE example here使用ReadWriteOnce访问模式。
    【解决方案3】:

    我想,你应该可以通过使用 PV 和 PVC 来做到这一点。让我们举一个例子,你有一个 pv 和 PVC。我不太确定多工作节点架构。我是 minikube 用户。 在这里检查 - https://github.com/kubernetes/kubernetes/issues/60903

    现在你有了 PV 和 PVC,这两个状态都是绑定的。现在您将在 pod/deployment 资源定义中使用声明,在 pvc 名称中您将使用相同的声明名称。这会将卷附加到两个 pod。

    ---
    #pv defination:
    
    ---
    kind: PersistentVolume
    apiVersion: v1
    metadata:
      name: pv0
    spec:
      storageClassName: standard
      accessModes:
        - ReadWriteOnce
      capacity:
        storage: 5Gi
      hostPath:
        path: /path_on_node
        type: DirectoryOrCreate
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: claim0
    spec:
      storageClassName: standard
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 5Gi
      volumeName: pv0
    --- 
    # pod1
              volumeMounts:
                - mountPath: /container_path
                  name: vol0
                  subPath: sub_path_on_pv(say pod1 so on disk data will be written at /path_on_node/pod1
          volumes:
            - name: vol0
              persistentVolumeClaim:
                claimName: claim0  
    ---
    # pod2
              volumeMounts:
                - mountPath: /container_path
                  name: vol2
                  subPath: sub_path_on_pv(say pod2 so on disk data will be written at /path_on_node/pod2
          volumes:
            - name: vol2
              persistentVolumeClaim:
                claimName: claim0  
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-23
      • 1970-01-01
      • 2019-01-14
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多