// Module included in the following assemblies:
//
// * storage/container_storage_interface/persistent_storage-csi-azure-file.adoc
//
:_mod-docs-content-type: PROCEDURE
[id="persistent-storage-csi-azure-file-static-provisioning-procedure_{context}"]
= Static provisioning for Azure File

[role="_abstract"]
Use static provisioning to manually create persistent volumes (PVs) for existing Azure File shares. Create a secret with storage credentials, define a PV that references the share, and create a persistent volume claim (PVC) to consume the storage.

.Prerequisites
* Access to an {product-title} cluster with administrator rights

.Procedure
. If you have not yet created a secret for the Azure storage account, create it now:
+
This secret must contain the Azure Storage Account name and key with the following very specific format with two key-value pairs:

* `azurestorageaccountname`: <storage_account_name>
* `azurestorageaccountkey`: <account_key>
+
To create a secret named `azure-secret`, run the following command:
+
[source,terminal]
----
oc create secret generic azure-secret  -n <namespace_name> --type=Opaque --from-literal=azurestorageaccountname="<storage_account_name>" --from-literal=azurestorageaccountkey="<account_key>"
----
+
** Set `<namespace_name>` to the namespace where the PV is consumed.
** Provide your values for `<storage_account_name>` and `<account_key>`.

. Create a PV by using the following example YAML file:
+
.Example PV YAML file
[source,yaml]
----
apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/provisioned-by: file.csi.azure.com
  name: pv-azurefile
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: <sc-name>
  mountOptions:
    - dir_mode=0777
    - file_mode=0777
    - uid=0
    - gid=0
    - cache=strict
    - nosharesock
    - actimeo=30
    - nobrl
  csi:
    driver: file.csi.azure.com
    volumeHandle: "{resource-group-name}#{account-name}#{file-share-name}"
    volumeAttributes:
      shareName: EXISTING_FILE_SHARE_NAME
    nodeStageSecretRef:
      name: azure-secret
      namespace: <my-namespace>
----
+
* `spec.capacity.storage`: Specifies the Volume size.
* `spec.accessModes`: Defines the read/write and mount permissions. For more information, see "Access modes".
* `spec.persistentVolumeReclaimPolicy`: Specifies the Reclaim policy, which tells the cluster what to do with the volume after it is released. Accepted values are `Retain`, `Recycle`, or `Delete`.
* `spec.storageClassName`: Specifies the storage class name. This name is used by the PVC to bind to this specific PV. For static provisioning, a `StorageClass` object does not need to exist, but the name in the PV and PVC must match.
* `spec.mountOPtions.dir_mode=0777`: Modify this permission if you want to enhance the security.
* `spec.mountOPtions.cache`: Specifies the cache mode. Accepted values are `none`, `strict`, and `loose`. The default is `strict`.
* `spec.mountOPtions..nosharesock`: Use to reduce the probability of a reconnect race.
* `spec.mountOPtions.actimeo`: Specifies the time (in seconds) that the CIFS client caches attributes of a file or directory before it requests attribute information from a server.
* `spec.mountOPtions.nobrl`: Disables sending byte range lock requests to the server, and for applications which have challenges with POSIX locks.
* `csi.volumeHandle`: Specifies the `volumeHandle`. Ensure that `volumeHandle` is unique across the cluster. The `resource-group-name` is the Azure resource group where the storage account resides.
* `csi.volumeAttributes.shareName`: Specifies the file share name. Use only the file share name; do not use full path.
* `csi.nodeStageSecretRef.name`: Provide the name of the secret created in step 1 of this procedure. In this example, it is `azure-secret`.
* `csi.nodeStageSecretRef.namespace`: Specifies the namespace that the secret was created in. This must be the namespace where the PV is consumed.

. Create a PVC that references the PV using the following example file:
+
.Example PVC YAML file
[source,yaml]
----
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: <pvc-name>
  namespace: <my-namespace>
spec:
  volumeName: pv-azurefile
  storageClassName: <sc-name>
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
----
+
* `metadata.name`: Specifies the PVC name.
* `metadata.namespace`: Specifies the namespace for the PVC.
* `spec.volumeName`: Specifies the name of the PV that you created in the previous step.
* `spec.storageClassName`: Specifies the storage class name. This name is used by the PVC to bind to this specific PV. For static provisioning, a `StorageClass` object does not need to exist, but the name in the PV and PVC must match.
* `spec.accessModes`: Specifies the access mode. Defines the requested read/write access for the PVC. Claims use the same conventions as volumes when requesting storage with specific access modes. For more information, see "Access modes".
* `spec.resources.requests.storage`: Specifies the PVC size.

. Ensure that the PVC is created and in `Bound` status after a while by running the following command:
+
[source,terminal]
----
$ oc get pvc <pvc-name>
----
+
Where `<pvc-name>` is the name of your PVC.
+
.Example output
[source,terminal]
----
NAME       STATUS    VOLUME         CAPACITY   ACCESS MODES   STORAGECLASS   AGE
pvc-name   Bound     pv-azurefile   5Gi        ReadWriteMany  my-sc          7m2s
----
