Search code examples
kubernetesgoogle-kubernetes-enginepersistent-volumesgce-persistent-disk

Initializing a dynamically provisioned shared volume with ReadOnlyMany access mode


My GKE deployment consists of N pods (possibly on different nodes) and a shared volume, which is dynamically provisioned by pd.csi.storage.gke.io and is a Persistent Disk in GCP. I need to initialize this disk with data before the pods go live.

My problem is I need to set accessModes to ReadOnlyMany and be able to mount it to all pods across different nodes in read-only mode, which I assume effectively would make it impossible to mount it in write mode to the initContainer.

Is there a solution to this issue? Answer to this question suggests a good solution for a case when each pod has their own disk mounted, but I need to have one disk shared among all pods since my data is quite large.


Solution

  • With GKE 1.21 and later, you can enable the managed Filestore CSI driver in your clusters. You can enable the driver for new clusters

    gcloud container clusters create CLUSTER_NAME \
        --addons=GcpFilestoreCsiDriver ...
    

    or update existing clusters:

    gcloud container clusters update CLUSTER_NAME \
       --update-addons=GcpFilestoreCsiDriver=ENABLED
    

    Once you've done that, create a storage class (or have or platform admin do it):

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: filestore-example
    provisioner: filestore.csi.storage.gke.io
    volumeBindingMode: WaitForFirstConsumer
    allowVolumeExpansion: true
    parameters:
      tier: standard
      network: default
    

    After that, you can use PVCs and dynamic provisioning:

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: podpvc
    spec:
      accessModes:
      - ReadWriteMany
      storageClassName: filestore-example
      resources:
        requests:
          storage: 1Ti