Use an Azure File share
GKE on Azure supports mounting Azure Files shares. If you already have an Azure File share to use with GKE on Azure, you can create a PersistentVolume (PV) object and reserve it for a specific PersistentVolumeClaim (PVC).
This page explains how to create a PV by using an existing share populated with data, and how to use the PV in a Pod.
Before you begin
- Connect to your cluster
- Have access to or create an Azure File share. For more information, see Create an Azure file share .
Store your Azure storage account information
GKE on Azure stores information to access your Azure storage account in a Secret. If you haven't created a Secret in your cluster, you must add one. If you have this Secret in you cluster, skip to Create a PersistentVolume for a pre-existing share .
-
To create the Secret, copy the following manifest into a file named 'azure-service-account-key.yaml'.
--- apiVersion : v1 kind : Secret metadata : name : azure-secret-account-key type : Opaque stringData : accountname : STORAGE_ACCOUNT_NAME accountkey : STORAGE_ACCOUNT_KEYReplace the following:
- STORAGE_ACCOUNT_NAME : your Azure storage account name
- STORAGE_ACCOUNT_KEY : your Azure storage account key
-
Apply the file to your cluster with the
kubectltool:kubectl apply -f azure-service-account-key.yaml
Create a PersistentVolume for a pre-existing share
You import an existing Azure File share by specifying a new PV in your cluster. To create the PV, do the following:
-
Copy the following YAML into a file named
existing-volume.yaml:apiVersion : v1 kind : PersistentVolume metadata : name : VOLUME_NAME spec : capacity : storage : VOLUME_CAPACITY storageClassName : standard-rwx accessModes : - ReadWriteMany persistentVolumeReclaimPolicy : Retain csi : driver : file.csi.azure.com readOnly : false volumeHandle : VOLUME_IDReplace the following:
- VOLUME_NAME : a name for the volume
- VOLUME_CAPACITY
: size of the volume. For example,
30Gi. For more information on specifying volume capacity in Kubernetes, see the Meaning of memory . - VOLUME_ID
: a unique ID for the volume, formatted as a string
of
RESOURCE_GROUP_NAME # STORAGE_ACCOUNT_NAME # FILESHARE_NAME #where - FILE_SHARE_NAME : the Azure File share name
If your storage account is in a different resource group than your cluster, you need to add a reference to a Secret that contains your storage account key. To add the reference, insert the following in the
spec.csisection:# Optional. Only required if your storageAccount is in a different resource group than the cluster. nodeStageSecretRef : name : NODE_STAGE_SECRET_NAME namespace : NODE_STAGE_SECRET_NAMESPACEReplace the following:
- NODE_STAGE_SECRET_NAME : the name of the Secret
- NODE_STAGE_SECRET_NAMESPACE the Namespace that contains the Secret
-
Apply the YAML to your cluster.
kubectl apply -f existing-volume.yaml -
Confirm the creation of your PV with
kubectl describe pv.kubectl describe pv VOLUME_NAMEThe output of this command contains the status of the PV.
Use the volume with a PersistentVolumeClaim and Pod
After you have imported your volume, you can create a PVC and a Pod that mounts the PVC.
-
The following YAML creates a PVC and attaches it to a Pod running the Nginx web server. Copy it into a file named
nginx.yaml:apiVersion : v1 kind : PersistentVolumeClaim metadata : name : my-pvc spec : storageClassName : STORAGE_CLASS_NAME volumeName : VOLUME_NAME accessModes : - ACCESS_MODE resources : requests : storage : VOLUME_CAPACITY --- apiVersion : v1 kind : Pod metadata : name : web-server spec : containers : - name : web-server image : nginx volumeMounts : - mountPath : /var/lib/www/html name : data volumes : - name : data persistentVolumeClaim : claimName : my-pvcReplace the following:
- STORAGE_CLASS
: the name of the StorageClass from the
PersistentVolume you created previously. For example,
standard-rwo. - ACCESS_MODE
: the access mode of the volume. For Azure Disk,
use
ReadWriteOnce. For Azure File, useReadWriteMany. - VOLUME_CAPACITY
: size of the volume. For example,
30Gi.
- STORAGE_CLASS
: the name of the StorageClass from the
PersistentVolume you created previously. For example,
-
Apply the YAML to your cluster.
kubectl apply -f nginx.yaml -
Check the status of your Nginx instance with
kubectl describe. The output should have aSTATUSofRunning.kubectl describe pod web-server -
To delete the Pod, use the
kubectl deletecommand.kubectl delete -f nginx.yaml
What's next
- Use additional storage drivers with GKE on Azure.
- Read the documentation for the Azure File CSI driver .

