Accessing Fileshares from Google Kubernetes Engine Clusters

Use this topic to learn how to access a Cloud Filestore fileshare from a GKE cluster by creating a persistent volume and persistent volume claim.

The cluster must be in the same Google Cloud Platform project and VPC network as the Cloud Filestore instance.

Create a Persistent Volume

  1. Install the kubectl command-line tool by running the following commands:

    gcloud components install kubectl
    gcloud container clusters get-credentials [CLUSTER_NAME]

    where [CLUSTER_NAME] is the name of the cluster.

  2. Create a Kubernetes Persistent Volume specification. This is a .yaml file that provides information about how to access the Cloud Filestore fileshare. The specification looks similar to the following example:

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: fileserver
    spec:
      capacity:
        storage: [STORAGE]
      accessModes:
      - ReadWriteMany
      nfs:
        path: /[FILESHARE]
        server: [IP_ADDRESS]
    

    where:

    • [STORAGE] is the size of the fileshare on the Cloud Filestore instance. You must specify the [STORAGE] value in one of the supported units described in Resource quantities, for example 2T.
    • [FILESHARE] is the name of the fileshare on the Cloud Filestore instance. You can get the fileshare name of an instance from any of following sources:
    • [IP_ADDRESS] is the IP address for the Cloud Filestore instance. You can get an instance's IP address from any of following sources:

    For more information on the other settings, see Persistent Volumes.

  3. Deploy the persistent volume specification by running the following command:

    kubectl create -f /path/to/[PERSISTENT_VOLUME_FILE_NAME].yaml

Create a Persistent Volume Claim

  1. Create a Kubernetes Persistent Volume Claim specification. This is a .yaml file that allows a Kubernetes pod to access the storage resources of a Persistent Volume. The specification looks similar to the following example:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: fileserver-claim
    spec:
      accessModes:
      - ReadWriteMany
      storageClassName: ""
      resources:
        requests:
          storage: [STORAGE]
    

    Where [STORAGE] is the size of the Persistent Volume Claim you want to make available to Kubernetes objects. You must specify the [STORAGE] value in one of the supported units described in Resource quantities. The value you specify must be equal to or less than the storage you specified for the Persistent Volume.

    For more information on the other settings, see Persistent Volume Claims.

  2. Deploy the persistent volume claim specification by running the following command:

    kubectl create -f /path/to/[PERSISTENT_VOLUME_CLAIM_FILE_NAME].yaml

Consume the Persistent Volume Claim

  1. Create a specification for a Kubernetes object that consumes a Persistent Volume Claim, for example a Kubernetes pod. This specification is a .yaml file that describes the object, including information about any storage resources available to it. A pod specification looks similar to the following example:

    apiVersion: v1
    kind: Pod
    metadata:
      name: my-pod
    spec:
      containers:
      - name: [CONTAINER_NAME]
        image: [IMAGE_NAME]
        volumeMounts:
        - mountPath: [MOUNT_PATH]
          name: mypvc
      volumes:
      - name: mypvc
        persistentVolumeClaim:
          claimName: [CLAIM_NAME]
          readOnly: false
    

    where:

    • [CONTAINER_NAME] is the name of a container in the Pod
    • [IMAGE_NAME] is the tag for the Docker image the container runs.
    • [MOUNT_PATH] is the path to mount the Persistent Volume Claim to, for example /mnt/fileserver.
    • [CLAIM_NAME] is the name of a deployed Persistent Value Claim. In this example, this is fileserver-claim.

    For more information on the other settings, see Pods.

  2. Deploy the pod specification by running the following command:

    kubectl create -f /path/to/[POD_FILE_NAME].yaml

What's next

Get information about the Cloud Filestore instance.

Czy ta strona była pomocna? Podziel się z nami swoją opinią:

Wyślij opinię na temat...

Cloud Filestore Documentation