This page shows you how to access a Filestore file share from a GKE cluster by creating a Persistent Volume (PV) and Persistent Volume Claim (PVC).
The cluster must be in the same Google Cloud project and VPC network as the Filestore instance, unless the Filestore instance is on a shared VPC network. Currently, Filestore instances can only be created on a shared VPC network from the host project. For details, see Known issues.
Create a Persistent Volume
Install the
kubectl
command-line tool:gcloud components install kubectl && gcloud container clusters get-credentials cluster-name
where cluster-name is the name of the cluster.
Create a Kubernetes Persistent Volume specification. This is a .yaml file that provides information about how to access the Filestore file share. The specification looks similar to the following example:
apiVersion: v1 kind: PersistentVolume metadata: name: fileserver spec: capacity: storage: storage accessModes: - ReadWriteMany nfs: path: /file-share server: ip-address
where:
- storage is the size of the file share on the Filestore
instance. You must specify the storage value in one of the supported
units described in
Resource quantities,
such as
2T
. file-share is the name of the file share on the Filestore instance. You can get the file share name of an instance from any of following sources:
- The Filestore instances page in the Cloud Console.
Go to the Filestore instances page
- The
FILE_SHARE_NAME
field in the results from the instances list command. - The
name
field in thefileShares
section of the results from the instances describe command.
ip-address is the IP address for the Filestore instance. You can get an instance's IP address from any of following sources:
By visiting the Filestore instances page in the Cloud Console.
The
IP_ADDRESS
field in the results from the instances list command.The
ipAddresses
section in the results from the instances describe command.
For more information on the other settings, see Persistent Volumes.
- storage is the size of the file share on the Filestore
instance. You must specify the storage value in one of the supported
units described in
Resource quantities,
such as
Deploy the Persistent Volume specification:
kubectl create -f /path/to/persistent-volume-file-name.yaml
where persistent-volume-file-name is the name of the Kubernetes Persistent Volume specification file that you created in the previous step.
Create a Persistent Volume Claim
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: "" volumeName: fileserver 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.
Deploy the Persistent Volume Claim specification:
kubectl create -f /path/to/persistent-volume-claim-file-name.yaml
where persistent-volume-file-name is the name of the Kubernetes Persistent Volume specification file that you created in the previous step.
Consume the Persistent Volume Claim
Create a specification for a Kubernetes object that consumes a Persistent Volume Claim, such as 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 that 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.
Deploy the pod specification:
kubectl create -f /path/to/pod-file-name.yaml
where pod-file-name is the name of the pod specification that you created in the previous step.
What's next
Get information about the Filestore instance.