Skip to content

Commit 7d77236

Browse files
authored
Merge pull request #271870 from anthonychu/20240401-add-nfs
[Container Apps] Add NFS file shares
2 parents c0969a2 + 9c85d54 commit 7d77236

File tree

2 files changed

+182
-9
lines changed

2 files changed

+182
-9
lines changed

articles/container-apps/storage-mounts-azure-files.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ In this tutorial, you learn how to:
2424
> * Mount the storage share in an individual container
2525
> * Verify the storage mount by viewing the website access log
2626
27+
> [!NOTE]
28+
> Azure Container Apps supports mounting file shares using SMB and NFS protocols. This tutorial demonstrates mounting an Azure Files share using the SMB protocol. To learn more about mounting NFS shares, see [Use storage mounts in Azure Container Apps](storage-mounts.md).
29+
2730
## Prerequisites
2831

2932
- Install the latest version of the [Azure CLI](/cli/azure/install-azure-cli).

articles/container-apps/storage-mounts.md

Lines changed: 179 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: craigshoemaker
66
ms.service: container-apps
77
ms.custom: devx-track-azurecli
88
ms.topic: conceptual
9-
ms.date: 09/13/2023
9+
ms.date: 04/10/2024
1010
ms.author: cshoe
1111
zone_pivot_groups: arm-azure-cli-portal
1212
---
@@ -23,7 +23,7 @@ A container app has access to different types of storage. A single app can take
2323

2424
## Ephemeral storage
2525

26-
A container app can read and write temporary data to ephemeral storage. Ephermal storage can be scoped to a container or a replica. The total amount of container-scoped and replica-scoped storage available to each replica depends on the total amount of vCPUs allocated to the replica.
26+
A container app can read and write temporary data to ephemeral storage. Ephemeral storage can be scoped to a container or a replica. The total amount of container-scoped and replica-scoped storage available to each replica depends on the total amount of vCPUs allocated to the replica.
2727

2828
| vCPUs | Total ephemeral storage |
2929
|--|--|
@@ -227,12 +227,21 @@ Azure Files storage has the following characteristics:
227227
* All containers that mount the share can access files written by any other container or method.
228228
* More than one Azure Files volume can be mounted in a single container.
229229

230-
To enable Azure Files storage in your container, you need to set up your container as follows:
230+
Azure Files supports both SMB and NFS protocols. You can mount an Azure Files share using either protocol. The file share you define in the environment must be configured with the same protocol used by the file share in the storage account.
231+
232+
> [!NOTE]
233+
> Support for mounting NFS shares in Azure Container Apps is in preview.
234+
235+
To enable Azure Files storage in your container, you need to set up your environment and container app as follows:
231236

232237
* Create a storage definition in the Container Apps environment.
233-
* Define a volume of type `AzureFile` in a revision.
238+
* If you are using NFS, your environment must be configured with a custom VNet and the storage account must be configured to allow access from the VNet. For more information, see [NFS file shares in Azure Files
239+
](../storage/files/files-nfs-protocol.md).
240+
* If your environment is configured with a custom VNet, you must allow ports 445 and 2049 in the network security group (NSG) associated with the subnet.
241+
* Define a volume of type `AzureFile` (SMB) or `NfsAzureFile` (NFS) in a revision.
234242
* Define a volume mount in one or more containers in the revision.
235243
* The Azure Files storage account used must be accessible from your container app's virtual network. For more information, see [Grant access from a virtual network](/azure/storage/common/storage-network-security#grant-access-from-a-virtual-network).
244+
* If you're using NFS, you must also disable secure transfer. For more information, see [NFS file shares in Azure Files](../storage/files/files-nfs-protocol.md) and the *Create an NFS Azure file share* section in [this tutorial](../storage/files/storage-files-quick-create-use-linux.md#create-an-nfs-azure-file-share).
236245

237246
### Prerequisites
238247

@@ -248,13 +257,16 @@ To enable Azure Files storage in your container, you need to set up your contain
248257

249258
When configuring a container app to mount an Azure Files volume using the Azure CLI, you must use a YAML definition to create or update your container app.
250259

251-
For a step-by-step tutorial, refer to [Create an Azure Files storage mount in Azure Container Apps](storage-mounts-azure-files.md).
260+
For a step-by-step tutorial on mounting an SMB file share, refer to [Create an Azure Files storage mount in Azure Container Apps](storage-mounts-azure-files.md).
252261

253262
1. Add a storage definition to your Container Apps environment.
254-
263+
264+
# [SMB](#tab/smb)
265+
255266
```azure-cli
256267
az containerapp env storage set --name my-env --resource-group my-group \
257268
--storage-name mystorage \
269+
--storage-type AzureFile \
258270
--azure-file-account-name <STORAGE_ACCOUNT_NAME> \
259271
--azure-file-account-key <STORAGE_ACCOUNT_KEY> \
260272
--azure-file-share-name <STORAGE_SHARE_NAME> \
@@ -265,6 +277,28 @@ For a step-by-step tutorial, refer to [Create an Azure Files storage mount in Az
265277
266278
Valid values for `--access-mode` are `ReadWrite` and `ReadOnly`.
267279
280+
# [NFS](#tab/nfs)
281+
282+
```azure-cli
283+
az containerapp env storage set --name my-env --resource-group my-group \
284+
--storage-name mystorage \
285+
--storage-type NfsAzureFile \
286+
--server <NFS_SERVER> \
287+
--azure-file-share-name <STORAGE_SHARE_NAME> \
288+
--access-mode ReadWrite
289+
```
290+
291+
Replace `<NFS_SERVER>` with the NFS server address in the format `<STORAGE_ACCOUNT_NAME>.file.core.windows.net`. For example, if your storage account name is `mystorageaccount`, the NFS server address is `mystorageaccount.file.core.windows.net`.
292+
293+
Replace `<STORAGE_SHARE_NAME>` with the name of the file share in the format `/<STORAGE_ACCOUNT_NAME>/<STORAGE_SHARE_NAME>`. For example, if your storage account name is `mystorageaccount` and the file share name is `myshare`, the share name is `/mystorageaccount/myshare`.
294+
295+
Valid values for `--access-mode` are `ReadWrite` and `ReadOnly`.
296+
297+
> [!NOTE]
298+
> To mount NFS Azure Files, you must use a Container Apps environment with a custom VNet. The Storage account must be configured to allow access from the VNet.
299+
300+
---
301+
268302
1. To update an existing container app to mount a file share, export your app's specification to a YAML file named *app.yaml*.
269303
270304
```azure-cli
@@ -275,12 +309,14 @@ For a step-by-step tutorial, refer to [Create an Azure Files storage mount in Az
275309
276310
- Add a `volumes` array to the `template` section of your container app definition and define a volume. If you already have a `volumes` array, add a new volume to the array.
277311
- The `name` is an identifier for the volume.
278-
- For `storageType`, use `AzureFile`.
312+
- For `storageType`, use `AzureFile` for SMB, or `NfsAzureFile` for NFS. This value must match the storage type you defined in the environment.
279313
- For `storageName`, use the name of the storage you defined in the environment.
280314
- For each container in the template that you want to mount Azure Files storage, define a volume mount in the `volumeMounts` array of the container definition.
281315
- The `volumeName` is the name defined in the `volumes` array.
282316
- The `mountPath` is the path in the container to mount the volume.
283317
318+
# [SMB](#tab/smb)
319+
284320
```yaml
285321
properties:
286322
managedEnvironmentId: /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP_NAME>/providers/Microsoft.App/managedEnvironments/<ENVIRONMENT_NAME>
@@ -298,6 +334,27 @@ For a step-by-step tutorial, refer to [Create an Azure Files storage mount in Az
298334
storageName: mystorage
299335
```
300336
337+
# [NFS](#tab/nfs)
338+
339+
```yaml
340+
properties:
341+
managedEnvironmentId: /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP_NAME>/providers/Microsoft.App/managedEnvironments/<ENVIRONMENT_NAME>
342+
configuration:
343+
template:
344+
containers:
345+
- image: <IMAGE_NAME>
346+
name: my-container
347+
volumeMounts:
348+
- volumeName: azure-files-volume
349+
mountPath: /my-files
350+
volumes:
351+
- name: azure-files-volume
352+
storageType: NfsAzureFile
353+
storageName: mystorage
354+
```
355+
356+
---
357+
301358
1. Update your container app using the YAML file.
302359
303360
```azure-cli
@@ -315,6 +372,8 @@ The following ARM template snippets demonstrate how to add an Azure Files share
315372
316373
1. Add a `storages` child resource to the Container Apps environment.
317374
375+
# [SMB](#tab/smb)
376+
318377
```json
319378
{
320379
"type": "Microsoft.App/managedEnvironments",
@@ -352,11 +411,66 @@ The following ARM template snippets demonstrate how to add an Azure Files share
352411
}
353412
```
354413
414+
# [NFS](#tab/nfs)
415+
416+
```json
417+
{
418+
"type": "Microsoft.App/managedEnvironments",
419+
"apiVersion": "2023-05-01",
420+
"name": "[parameters('environment_name')]",
421+
"location": "[parameters('location')]",
422+
"properties": {
423+
"daprAIInstrumentationKey": "[parameters('dapr_ai_instrumentation_key')]",
424+
"appLogsConfiguration": {
425+
"destination": "log-analytics",
426+
"logAnalyticsConfiguration": {
427+
"customerId": "[parameters('log_analytics_customer_id')]",
428+
"sharedKey": "[parameters('log_analytics_shared_key')]"
429+
}
430+
},
431+
"workloadProfiles": [
432+
{
433+
"name": "Consumption",
434+
"workloadProfileType": "Consumption"
435+
}
436+
],
437+
"vnetConfiguration": {
438+
"infrastructureSubnetId": "[parameters('custom_vnet_subnet_id')]",
439+
"internal": false
440+
},
441+
},
442+
"resources": [
443+
{
444+
"type": "storages",
445+
"name": "myazurefiles",
446+
"apiVersion": "2023-11-02-preview",
447+
"dependsOn": [
448+
"[resourceId('Microsoft.App/managedEnvironments', parameters('environment_name'))]"
449+
],
450+
"properties": {
451+
"nfsAzureFile": {
452+
"server": "[concat(parameters('storage_account_name'), '.file.core.windows.net')]",
453+
"shareName": "[concat('/', parameters('storage_account_name'), '/', parameters('storage_share_name'))]",
454+
"accessMode": "ReadWrite"
455+
}
456+
}
457+
}
458+
]
459+
}
460+
```
461+
462+
> [!NOTE]
463+
> To mount NFS Azure Files, you must use a Container Apps environment with a custom VNet. The Storage account must be configured to allow access from the VNet.
464+
465+
---
466+
355467
1. Update the container app resource to add a volume and volume mount.
356468
469+
# [SMB](#tab/smb)
470+
357471
```json
358472
{
359-
"apiVersion": "2022-03-01",
473+
"apiVersion": "2023-05-01",
360474
"type": "Microsoft.App/containerApps",
361475
"name": "[parameters('containerappName')]",
362476
"location": "[parameters('location')]",
@@ -398,9 +512,57 @@ The following ARM template snippets demonstrate how to add an Azure Files share
398512
}
399513
```
400514
515+
# [NFS](#tab/nfs)
516+
517+
```json
518+
{
519+
"apiVersion": "2023-11-02-preview",
520+
"type": "Microsoft.App/containerApps",
521+
"name": "[parameters('containerappName')]",
522+
"location": "[parameters('location')]",
523+
"properties": {
524+
525+
...
526+
527+
"template": {
528+
"revisionSuffix": "myrevision",
529+
"containers": [
530+
{
531+
"name": "main",
532+
"image": "[parameters('container_image')]",
533+
"resources": {
534+
"cpu": 0.5,
535+
"memory": "1Gi"
536+
},
537+
"volumeMounts": [
538+
{
539+
"mountPath": "/myfiles",
540+
"volumeName": "azure-files-volume"
541+
}
542+
]
543+
}
544+
],
545+
"scale": {
546+
"minReplicas": 1,
547+
"maxReplicas": 3
548+
},
549+
"volumes": [
550+
{
551+
"name": "azure-files-volume",
552+
"storageType": "NfsAzureFile",
553+
"storageName": "myazurefiles"
554+
}
555+
]
556+
}
557+
}
558+
}
559+
```
560+
561+
---
562+
401563
- Add a `volumes` array to the `template` section of your container app definition and define a volume. If you already have a `volumes` array, add a new volume to the array.
402564
- The `name` is an identifier for the volume.
403-
- For `storageType`, use `AzureFile`.
565+
- For `storageType`, use `AzureFile` for SMB, or `NfsAzureFile` for NFS. This value must match the storage type you defined in the environment.
404566
- For `storageName`, use the name of the storage you defined in the environment.
405567
- For each container in the template that you want to mount Azure Files storage, define a volume mount in the `volumeMounts` array of the container definition.
406568
- The `volumeName` is the name defined in the `volumes` array.
@@ -412,6 +574,8 @@ See the [ARM template API specification](azure-resource-manager-api-spec.md) for
412574
413575
::: zone pivot="azure-portal"
414576
577+
# [SMB](#tab/smb)
578+
415579
To configure a volume mount for Azure Files storage in the Azure portal, add a file share to your Container Apps environment and then add a volume mount to your container app by creating a new revision.
416580
417581
1. In the Azure portal, navigate to your Container Apps environment.
@@ -451,4 +615,10 @@ To configure a volume mount for Azure Files storage in the Azure portal, add a f
451615
452616
1. Select **Create** to create the new revision.
453617
618+
# [NFS](#tab/nfs)
619+
620+
Azure portal doesn't support creating NFS Azure Files volumes. To create an NFS Azure Files volume, use the [Azure CLI](storage-mounts.md?tabs=nfs&pivots=azure-cli#azure-files) or [ARM template](storage-mounts.md?tabs=nfs&pivots=azure-resource-manager#azure-files).
621+
622+
---
623+
454624
::: zone-end

0 commit comments

Comments
 (0)