Can I mount multiple partitions of a single GCE di

2019-05-11 01:52发布

问题:

I'd like use a single google compute engine disk and mount it to multiple places a Kubernetes Google Container Engine.

I'm wondering if using persistentVolumeClaim would work, but what I did expect to work is being able to mount two partitions of the same disk:

  ...
  volumes:
    - name: database
      gcePersistentDisk:
        pdName: dist-1
        fsType: ext4
        partition: 1
        readOnly: true
    - name: media
      gcePersistentDisk:
        pdName: disk-1
        fsType: ext4
        partition: 2
        readOnly: true

Mounting either of them separately works, but trying to mount both gives an error:

FailedMount     Unable to mount volumes for pod "frontend-ni7uf_foo": Could not attach GCE PD "disk-1". Timeout waiting for mount paths to be created.

Technically I can manually mount both partitions on a single instance.

I'm wondering if it's a bug and if there is another solution for that (outside of having multiple disks)?

回答1:

Looks like it Google Container Engine requires readOnly on both:

containers:
  - volumeMounts:
      - readOnly: true
volumes:
  - gcePersistentDisk:
      readOnly: true


回答2:

Thanks for the question Wernight.

In order for (different partitions of) the same volume to be mounted in multiple places it must be read-only at the moment.

I opened https://github.com/kubernetes/kubernetes/issues/20835 to track if this is the behavior we want moving forward or not.



回答3:

I'm interpreting the question differently than the other answers. Why should it not be possible to mount different partitions of a single PD in a single pod, all read-write. The PD is still attached to one node and used by one pod.

The only answer is that we didn't think of that as a use case. Most people do not sub-partition block devices this way, in our experience, except when booting an OS.

If this is an important use-case to you, I encourage you to file a github issue on it. I don't immediately know how to evolve to solve it, but I don't think it is an errant request.