// 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-cross-sub-dynamic-pre-provisioning-pv-pvc-procedure_{context}"]
= Static provisioning across subscriptions for Azure File by creating a PV and PVC:

[role="_abstract"]
Provision Azure File storage across subscriptions using static provisioning by creating a secret with storage credentials, then creating a persistent volume (PV) and persistent volume claim (PVC) referencing an Azure File share in a different subscription.

Recommendation to use a storage class::
In the following example of static provisioning across subscriptions, the storage class referenced in the PV and PVC is not strictly necessary, as storage classes are not required to accomplish static provisioning. However, it is advisable to use a storage class to avoid cases where a manually created PVC accidentally does not match a manually created PV, and thus potentially triggers dynamic provisioning of a new PV. Other ways to avoid this issue would be to create a storage class with `provisioner: kubernetes.io/no-provisioner` or reference a non-existing storage class, which in both cases ensures that dynamic provisioning does not occur. When using either of these strategies, if a mis-matched PV and PVC occurs, the PVC stays in a pending state, and you can correct the error.

.Prerequisites
* Installed {product-title} cluster on Azure with the service principal or managed identity as an Azure identity in one subscription (call it Subscription A)
* Access to another subscription (call it Subscription B) with the storage that is in the same tenant as the cluster
* Logged in to the Azure CLI

.Procedure
. For your Azure File share, record the resource group, storage account, storage account key, and Azure File name. These values are used for the next steps.

. Create a secret for the persistent volume parameter `spec.csi.nodeStageSecretRef.name` by running the following command:
+
[source, terminal]
----
$ oc create secret generic azure-storage-account-<storageaccount-name>-secret --from-literal=azurestorageaccountname="<azure-storage-account-name>" --from-literal azurestorageaccountkey="<azure-storage-account-key>" --type=Opaque
----
+
`<azure-storage-account-name>` and `<azure-storage-account-key>` are the Azure storage account name and key respectively that you recorded in Step 1.

. Create a persistent volume (PV) by using a similar configuration to the following example file:
+
.Example PV YAML file
[source,terminal]
----
apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/provisioned-by: file.csi.azure.com
  name: <pv-name>
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain  
  storageClassName: <sc-name>
  mountOptions:
    - cache=strict
    - nosharesock
    - actimeo=30
    - nobrl 
  csi:
    driver: file.csi.azure.com
    volumeHandle: "{resource-group-name}#{storage-account-name}#{file-share-name}"
    volumeAttributes:
      shareName: <existing-file-share-name>
    nodeStageSecretRef:
      name: <secret-name>
      namespace: <secret-namespace>
----
+
* `metadata.name`: Specifies the name of the PV.
* `spec.capacity.storage`: Specifies the size of the PV.
* `spec.storageClassName`: Specifies the storage class name.
* `spec.csi.volumeHandle`: Specifies the `volumeHandle` parameter. Ensure that `volumeHandle` is unique for every identical share in the cluster.
* `spec.csi.volumeAttributes.shareName`: For `<existing-file-share-name>``, use only the file share name and not the full path.
* `spec.csi.nodeStageSecretRef.name`: Specifies the secret name created in the previous step.
* `spec.csi.nodeStageSecretRef.namespace`: Specifies the namespace where the secret resides.

. Create a persistent value claim (PVC) specifying the existing Azure File share referenced in Step 1 using a similar configuration to the following:
+
.Example PVC YAML file
[source,yaml]
----
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: <pvc-name>
spec:
  storageClassName: <sc-name>
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
----
+
* `metadata.name`: Specifies the name of the PVC.
* `spec.storageClassName`: Specifies the name of the storage class that you specified for the PV in the previous step.
