แก้ไข

แชร์ผ่าน


How to enable your own persistent storage in Azure Spring Apps with the Standard consumption and dedicated plan

Note

The Basic, Standard, and Enterprise plans will be deprecated starting from mid-March, 2025, with a 3 year retirement period. We recommend transitioning to Azure Container Apps. For more information, see the Azure Spring Apps retirement announcement.

The Standard consumption and dedicated plan will be deprecated starting September 30, 2024, with a complete shutdown after six months. We recommend transitioning to Azure Container Apps. For more information, see Migrate Azure Spring Apps Standard consumption and dedicated plan to Azure Container Apps.

This article applies to: ✔️ Standard consumption and dedicated (Preview) ❌ Basic/Standard ❌ Enterprise

This article describes how to enable your own persistent storage in Azure Spring Apps.

Your own storage and the built-in persistent storage in Azure Spring Apps differ in the following ways:

  • In built-in storage, artifacts generated by your application get uploaded into Azure Storage accounts. In your own storage, artifacts generated by your application get uploaded into a storage account that you control.

  • In built-in storage, Microsoft Azure controls the encryption-at-rest and the lifetime management policies for those artifacts. In your own storage, you control the encryption-at-rest policy, the lifetime management policy, and network access.

You can also mount your own persistent storage not only to Azure Spring Apps but to other service instances in the environment such as Azure Container Apps. This capability is possible because your Azure Spring Apps instance is deployed in the Azure Container Apps environment.

Prerequisites

Set up the environment

Use the following commands to set the following variables to the names of your resources and current region setting.

export RESOURCE_GROUP="<resource-group-name>"
export LOCATION="eastus"
export AZURE_CONTAINER_APPS_ENVIRONMENT="<Azure-Container-Apps-environment-name>"
export AZURE_SPRING_APPS_INSTANCE="<Azure-Spring-Apps-instance-name>"
export APP_NAME="<Spring-app-name>"

Set up a storage account

Use the following steps to create a storage account and establish a file share to mount to the Spring app.

  1. Create an Azure Storage account by using the following commands. The STORAGE_ACCOUNT_NAME variable includes a randomly generated suffix to ensure uniqueness.

    export STORAGE_ACCOUNT_NAME="myasastorageaccount$RANDOM"
    
    az storage account create \
        --resource-group $RESOURCE_GROUP \
        --name $STORAGE_ACCOUNT_NAME \
        --location "$LOCATION" \
        --kind StorageV2 \
        --sku Standard_LRS \
        --query provisioningState \
        --enable-large-file-share
    

    This command returns a success message upon successful completion.

  2. Create the Azure Storage file share by using the following commands:

    export FILE_SHARE_NAME="<file-share-name>"
    
    az storage share-rm create \
        --resource-group $RESOURCE_GROUP \
        --storage-account $STORAGE_ACCOUNT_NAME \
        --name $FILE_SHARE_NAME \
        --quota 1024 \
        --enabled-protocols SMB \
        --output table
    
  3. Get the Storage Account key by using the following command:

    export STORAGE_ACCOUNT_KEY=$(az storage account keys list \
        --account-name $STORAGE_ACCOUNT_NAME \
        --query "[0].value" \
        --output tsv)
    

    The storage account key is required to create the storage link in your Azure Container Apps environment.

Create the storage link in the Azure Container Apps environment by using the following commands. The az containerapp env storage set command creates a link between the environment and the file share created with the az storage share-rm command.

export STORAGE_MOUNT_NAME="<storage-account-name>"

az containerapp env storage set \
    --resource-group $RESOURCE_GROUP \
    --name $AZURE_CONTAINER_APPS_ENVIRONMENT \
    --storage-name $STORAGE_MOUNT_NAME \
    --azure-file-account-name $STORAGE_ACCOUNT_NAME \
    --azure-file-account-key $STORAGE_ACCOUNT_KEY \
    --azure-file-share-name $FILE_SHARE_NAME \
    --access-mode ReadWrite \
    --output table

Now that the storage account and environment are linked, you can use the storage mount in your Azure Spring Apps instance.

Add storage to an app

Add the persistent storage to your existing app by using the following command:

az spring app append-persistent-storage \
    --resource-group $RESOURCE_GROUP \
    --service $AZURE_SPRING_APPS_INSTANCE \
    --name $APP_NAME \
    --persistent-storage-type AzureFileVolume \
    --mount-path /var/log/nginx \
    --storage-name $STORAGE_MOUNT_NAME

Clean up resources

Be sure to delete the resources you created in this article when you no longer need them. To delete the resources, just delete the resource group that contains them. You can delete the resource group using the Azure portal. Alternatively, to delete the resource group by using Azure CLI, use the following commands:

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."

Next steps