# Import a preexisting Azure Disk volume

If you already have an Azure Disk volume 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 volume
populated with data, and how to use the PV in a Pod.

## Before you begin

- [Connect to your cluster](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/azure/how-to/connect-and-authenticate-to-your-cluster.md.txt)

## Create a PersistentVolume for a pre-existing volume

You can import an existing volume by specifying a new PV.

1. Copy the following YAML into a file named `existing-volume.yaml`.:

   ```yaml
   apiVersion: v1
   kind: PersistentVolume
   metadata:
     name: VOLUME_NAME
     annotations:
       pv.kubernetes.io/provisioned-by: disk.csi.azure.com
   spec:
     capacity:
       storage: VOLUME_CAPACITY
     accessModes:
       - ReadWriteOnce
     persistentVolumeReclaimPolicy: Retain
     storageClassName: STORAGE_CLASS_NAME
     claimRef:
       name: my-pvc
       namespace: default
     csi:
       driver: disk.csi.azure.com
       volumeHandle: /subscriptions/SUBSCRIPTION_ID/resourcegroups/RESOURCE_GROUP_NAME/providers/microsoft.compute/disks/DISK_NAME
       fsType: FILE_SYSTEM_TYPE
   ```

   Replace the following:
   - <var translate="no">VOLUME_NAME</var>: a name for the volume
   - <var translate="no">VOLUME_CAPACITY</var>: size of the volume. For example, `30Gi`. For more information on specifying volume capacity in Kubernetes, see the [Meaning of memory](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-memory).
   - <var translate="no">STORAGE_CLASS_NAME</var>: the name of the StorageClass that
     provisions the volume.
     For example, you can use the default `standard-rwo`.

     > [!NOTE]
     > **Note:** A StorageClass is required to reference other attributes like `allowVolumeExpansion`, even if a volume is not dynamically provisioned.

   - <var translate="no">SUBSCRIPTION_ID</var>: the Azure subscription ID that contains the
     volume.

   - <var translate="no">RESOURCE_GROUP_NAME</var>: the Azure resource group that contains
     the volume.

   - <var translate="no">DISK_NAME</var>: the Azure Disk name of the volume.

   - <var translate="no">FS_TYPE</var>: the
     [file system type](https://github.com/kubernetes-sigs/azuredisk-csi-driver/blob/master/docs/driver-parameters.md#dynamic-provisioning)
     of the volume. For example, `ext4`.

2. Apply the YAML to your cluster

   ```bash
   kubectl apply -f existing-volume.yaml
   ```
3. Confirm the creation of your PV

   ```bash
   kubectl describe pv VOLUME_NAME
   ```

   The 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.

1. 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`:

   ```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-pvc
   ```

   Replace the following:
   - <var translate="no">STORAGE_CLASS</var>: the name of the StorageClass from the PersistentVolume you created previously. For example, `standard-rwo`.
   - <var translate="no">ACCESS_MODE</var>: the access mode of the volume. For Azure Disk, use `ReadWriteOnce`. For Azure File, use `ReadWriteMany`.
   - <var translate="no">VOLUME_CAPACITY</var>: size of the volume. For example, `30Gi`.
2. Apply the YAML to your cluster

   ```bash
   kubectl apply -f nginx.yaml
   ```
3. Check the status of your Nginx instance with `kubectl describe`. The output
   should have a `STATUS` of `Running`.

   ```bash
   kubectl describe pod web-server
   ```

## What's next

- Use additional [storage drivers](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/azure/how-to/storage-drivers.md.txt) with GKE on Azure.
- Read the documentation for the [Azure Disk CSI driver](https://github.com/kubernetes-sigs/azuredisk-csi-driver/tree/v1.8.0/docs).