Anthos clusters on Azure is available for customers with an existing support relationship with Google Cloud. Contact your account representative for access.

Import a preexisting Azure volume

If you already have an Azure Disk volume to import into Anthos clusters 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

Create a PersistentVolume for a pre-existing volume

You can import an existing volume by specifying a new PV. Choose if you want to use an Azure Disk or Azure File volume.

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

    Azure Disk

    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:

    • 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.
    • STORAGE_CLASS_NAME: the name of the StorageClass that provisions the volume. For example, you can use the default standard-rwo.

    • SUBSCRIPTION_ID: the Azure subscription ID that contains the volume.

    • RESOURCE_GROUP_NAME: the Azure resource group that contains the volume.

    • DISK_NAME: the Azure Disk name of the volume.

    • FS_TYPE: the file system type of the volume. For example, ext4.

    Azure File

    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_ID
    

    Replace 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.csi section:

    # 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_NAMESPACE
    

    Replace the following:

    • NODE_STAGE_SECRET_NAME: the name of the Secret
    • NODE_STAGE_SECRET_NAMESPACE the Namespace that contains the Secret

    If you do not have a secret that contains your Azure storage account info, you must add one to your cluster. Append the following to the YAML manifest:

    ---
    apiVersion: v1
    kind: Secret
    metadata:
      name: azure-secret-account-key
    type: Opaque
    stringData:
      accountname: STORAGE_ACCOUNT_NAME
      accountkey: STORAGE_ACCOUNT_KEY
    

    Replace the following: * STORAGE_ACCOUNT_NAME: your Azure storage account name * STORAGE_ACCOUNT_KEY: your Azure storage account key

  2. Apply the YAML to your cluster

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

    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:

    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:

    • 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, use ReadWriteMany.
    • VOLUME_CAPACITY: size of the volume. For example, 30Gi.
  2. Apply the YAML to your cluster

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

    kubectl describe pod web-server
    

What's next