Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GKE: right way to mount same PV on multiple pods

I'm having trouble to create a persistent volume that I can use from different pods (1 write, another read).

Tried to use gcePersistentDisk directly in the pod spec like in the example on the k8s page (plus 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

Then in the second pod spec exactly the same except the readOnly ... but got an NoDiskConflict error.

Second approach is to use PersistentVolume and PersistentVolumeClaim like this:

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

But now I get an error telling me:

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]

So what is the correct way of using a GCE disk with multiple pods.

PS: Kubernetes 1.6.6

like image 326
Philipp Kyeck Avatar asked Jul 05 '17 15:07

Philipp Kyeck


2 Answers

According to https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes, GCE Disks do not support ReadWriteMany. I am not sure if this explains the issue but I would advise you to try another compatible Volume type.

like image 91
Javier Salmeron Avatar answered Sep 18 '22 13:09

Javier Salmeron


Instead of ReadWriteMany, can you use ReadOnlyMany?

Accessmodes:

ReadWriteOnce – the volume can be mounted as read-write by a single node

ReadOnlyMany – the volume can be mounted read-only by many nodes

ReadWriteMany – the volume can be mounted as read-write by many nodes

GCE persistent disk do not support ReadWriteMany

Here is the list of providers and supported accessmodes:

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

like image 26
Balaji Boggaram Ramanarayan Avatar answered Sep 21 '22 13:09

Balaji Boggaram Ramanarayan