|
| 1 | +--- |
| 2 | +title: Use Azure Files for Azure Kubernetes Workloads |
| 3 | +description: Learn how to use Azure file shares for Azure Kubernetes Service (AKS) workloads, including how to use the Azure Files CSI driver. |
| 4 | +author: khdownie |
| 5 | +ms.service: azure-file-storage |
| 6 | +ms.topic: concept-article |
| 7 | +ms.date: 07/29/2025 |
| 8 | +ms.author: kendownie |
| 9 | +ai-usage: ai-generated |
| 10 | +# Customer intent: "As a Kubernetes administrator, I want to implement Azure Files for my Azure Kubernetes Service (AKS) workloads requiring persistent, shared storage, so that I can better support my organization's containerized applications." |
| 11 | +--- |
| 12 | + |
| 13 | +# Azure Files guidance for Azure Kubernetes Service (AKS) workloads |
| 14 | + |
| 15 | +Azure Files provides fully managed file shares in the cloud that are accessible via the industry standard Server Message Block (SMB) protocol and Network File System (NFS) protocol. When integrated with Azure Kubernetes Service (AKS), Azure Files enables persistent, shared storage for containerized applications, supporting both stateful workloads and scenarios requiring shared data access across multiple pods. |
| 16 | + |
| 17 | +## What is Azure Kubernetes Service? |
| 18 | + |
| 19 | +Azure Kubernetes Service is a managed Kubernetes service that simplifies deploying, managing, and scaling containerized applications using Kubernetes on Azure. It reduces the complexity and operational overhead of managing Kubernetes by offloading much of that responsibility to Azure. As a hosted Kubernetes service, AKS handles critical tasks like health monitoring and maintenance, while you focus on your application workloads. |
| 20 | + |
| 21 | +## Why Azure Files for AKS? |
| 22 | + |
| 23 | +The combination of persistent shared storage, Kubernetes-native integration, and enterprise-grade performance and security makes Azure Files an excellent choice for stateful applications, shared data scenarios, and complex multi-pod architectures in AKS environments. Whether you're deploying content management systems, implementing centralized logging, or building data processing pipelines, Azure Files offers the flexibility and reliability needed to support your AKS infrastructure at scale. |
| 24 | + |
| 25 | +### Persistent shared storage |
| 26 | + |
| 27 | +Unlike local storage that's tied to individual nodes, Azure Files provides persistent storage that survives pod restarts, node failures, and cluster scaling events. Multiple pods across different nodes can simultaneously access the same file share, enabling shared data scenarios and stateful applications. |
| 28 | + |
| 29 | +### Kubernetes native integration |
| 30 | + |
| 31 | +Azure Files integrates seamlessly with Kubernetes through the Container Storage Interface (CSI) driver, allowing you to provision and manage file shares using standard Kubernetes constructs like persistent volumes (PV) and persistent volume claims (PVC). The CSI driver handles all the complexity of Azure API interactions, authentication, and mount operations, providing a native Kubernetes experience for storage management. |
| 32 | + |
| 33 | +### SSD file shares for optimal performance |
| 34 | + |
| 35 | +Azure Files offers two types of storage media: |
| 36 | + |
| 37 | +- **HDD (Standard)**: Cost-effective for general-purpose workloads |
| 38 | +- **SSD (Premium)**: High-performance SSD-backed storage for I/O intensive applications |
| 39 | + |
| 40 | +For optimal performance, we recommend using SSD file shares deployed in the same Azure region as your AKS cluster. This minimizes latency and maximizes throughput for file operations. |
| 41 | + |
| 42 | +### Protocol support |
| 43 | + |
| 44 | +Support for both NFS and SMB protocols ensures compatibility with a wide range of applications and operating systems, including Linux and Windows containers. |
| 45 | + |
| 46 | +### Security and compliance |
| 47 | + |
| 48 | +Azure Files provides essential security features including encryption at rest, encryption in transit, Microsoft Entra ID integration, and compliance with industry standards. |
| 49 | + |
| 50 | +## Understanding the Azure Files CSI driver |
| 51 | + |
| 52 | +The Azure Files Container Storage Interface (CSI) driver is a critical component that enables seamless integration between Azure Files and Kubernetes clusters, including AKS. The CSI specification provides a standardized interface for storage systems to expose their capabilities to containerized workloads, and the Azure Files CSI driver implements this specification specifically for Azure Files. For more information, see [Use Azure Files CSI driver in AKS](/azure/aks/azure-files-csi). |
| 53 | + |
| 54 | +### How the CSI driver works |
| 55 | + |
| 56 | +In AKS clusters, the Azure Files CSI driver is installed and managed automatically. The driver operates through several key components: |
| 57 | + |
| 58 | +- **CSI driver pod**: Runs as a DaemonSet on each node in the AKS cluster, responsible for mounting and unmounting Azure file shares |
| 59 | +- **CSI controller**: Manages the lifecycle of Azure file shares, including creation, deletion, and volume expansion |
| 60 | +- **Storage classes**: Define the parameters and policies for dynamic provisioning of Azure file shares |
| 61 | +- **Persistent volumes**: Represent the actual Azure file shares in Kubernetes |
| 62 | +- **Persistent volume claims**: User requests for storage that are bound to persistent volumes |
| 63 | + |
| 64 | +When a pod requests storage through a persistent volume claim, the CSI driver coordinates with Azure APIs to either create a new Azure file share ([dynamic provisioning](#dynamic-provisioning)) or connect to an existing share ([static provisioning](#static-provisioning)). The driver then mounts the share into the pod's filesystem namespace, making it accessible to applications. |
| 65 | + |
| 66 | +### CSI driver capabilities |
| 67 | + |
| 68 | +The Azure Files CSI driver provides several advanced capabilities: |
| 69 | + |
| 70 | +- **Dynamic volume provisioning**: Automatically creates Azure file shares based on storage class definitions |
| 71 | +- **Volume expansion**: Supports online expansion of existing Azure file shares |
| 72 | +- **Snapshot support**: Enables point-in-time snapshots for backup and recovery scenarios |
| 73 | +- **Cross-platform compatibility**: Works with both Linux and Windows node pools in AKS |
| 74 | + |
| 75 | +## Common use cases for Azure Files with AKS |
| 76 | + |
| 77 | +Some common use cases for Azure Files with AKS include: |
| 78 | + |
| 79 | +- **Shared configuration and secrets management**: Azure Files enables centralized storage of configuration files, certificates, and other shared resources that multiple pods need to access. |
| 80 | +- **Log aggregation and centralized logging**: Azure Files can serve as a central repository for application logs, enabling log aggregation from multiple pods and providing persistent storage for log analysis tools. |
| 81 | +- **Content management systems and media storage**: For applications that handle user-generated content, media files, or document management, Azure Files provides scalable shared storage accessible by multiple application instances. |
| 82 | +- **Batch processing and ETL workloads**: Azure Files enables efficient data sharing between batch processing jobs, ETL pipelines, and data processing workflows where multiple pods need access to input data and output results. |
| 83 | +- **Development and testing environments**: Shared storage for development teams to collaborate on code, share test data, and maintain consistent development environments across different pods and nodes. |
| 84 | + |
| 85 | +### Shared configuration and secrets management |
| 86 | + |
| 87 | +Azure Files is particularly useful for: |
| 88 | + |
| 89 | +- **Configuration management**: Store application configuration files that need to be shared across multiple instances. |
| 90 | +- **Certificate distribution**: Centrally manage and distribute SSL/TLS certificates. |
| 91 | +- **Shared libraries**: Store common libraries or binaries accessed by multiple applications. |
| 92 | + |
| 93 | +This YAML example creates a persistent volume claim for shared configuration storage and a deployment that mounts this storage across multiple pod replicas: |
| 94 | + |
| 95 | +```yaml |
| 96 | +apiVersion: v1 |
| 97 | +kind: PersistentVolumeClaim |
| 98 | +metadata: |
| 99 | + name: config-storage |
| 100 | +spec: |
| 101 | + accessModes: |
| 102 | + - ReadWriteMany |
| 103 | + storageClassName: azurefile-csi-premium |
| 104 | + resources: |
| 105 | + requests: |
| 106 | + storage: 10Gi |
| 107 | +--- |
| 108 | +apiVersion: apps/v1 |
| 109 | +kind: Deployment |
| 110 | +metadata: |
| 111 | + name: app-deployment |
| 112 | +spec: |
| 113 | + replicas: 3 |
| 114 | + selector: |
| 115 | + matchLabels: |
| 116 | + app: myapp |
| 117 | + template: |
| 118 | + metadata: |
| 119 | + labels: |
| 120 | + app: myapp |
| 121 | + spec: |
| 122 | + containers: |
| 123 | + - name: myapp |
| 124 | + image: myapp:latest |
| 125 | + volumeMounts: |
| 126 | + - name: config-volume |
| 127 | + mountPath: /app/config |
| 128 | + volumes: |
| 129 | + - name: config-volume |
| 130 | + persistentVolumeClaim: |
| 131 | + claimName: config-storage |
| 132 | +``` |
| 133 | +
|
| 134 | +### Log aggregation and centralized logging |
| 135 | +
|
| 136 | +Azure Files can serve as a central repository for application logs, enabling log aggregation from multiple pods and providing persistent storage for log analysis tools. |
| 137 | +
|
| 138 | +This YAML example demonstrates a DaemonSet for log collection with a shared Azure Files storage for centralized log aggregation: |
| 139 | +
|
| 140 | +```yaml |
| 141 | +apiVersion: v1 |
| 142 | +kind: PersistentVolumeClaim |
| 143 | +metadata: |
| 144 | + name: logs-storage |
| 145 | +spec: |
| 146 | + accessModes: |
| 147 | + - ReadWriteMany |
| 148 | + storageClassName: azurefile-csi-premium |
| 149 | + resources: |
| 150 | + requests: |
| 151 | + storage: 100Gi |
| 152 | +--- |
| 153 | +apiVersion: apps/v1 |
| 154 | +kind: DaemonSet |
| 155 | +metadata: |
| 156 | + name: log-collector |
| 157 | +spec: |
| 158 | + selector: |
| 159 | + matchLabels: |
| 160 | + app: log-collector |
| 161 | + template: |
| 162 | + metadata: |
| 163 | + labels: |
| 164 | + app: log-collector |
| 165 | + spec: |
| 166 | + containers: |
| 167 | + - name: log-collector |
| 168 | + image: fluent/fluent-bit:latest |
| 169 | + volumeMounts: |
| 170 | + - name: logs-volume |
| 171 | + mountPath: /logs |
| 172 | + - name: varlog |
| 173 | + mountPath: /var/log |
| 174 | + readOnly: true |
| 175 | + volumes: |
| 176 | + - name: logs-volume |
| 177 | + persistentVolumeClaim: |
| 178 | + claimName: logs-storage |
| 179 | + - name: varlog |
| 180 | + hostPath: |
| 181 | + path: /var/log |
| 182 | +``` |
| 183 | +
|
| 184 | +## Storage classes and provisioning options |
| 185 | +
|
| 186 | +Azure Files CSI driver supports both static and dynamic provisioning through Kubernetes storage classes: |
| 187 | +
|
| 188 | +### Dynamic provisioning |
| 189 | +
|
| 190 | +With dynamic provisioning, storage is automatically created when a persistent volume claim is created. |
| 191 | +
|
| 192 | +This YAML defines a storage class for dynamic provisioning of SSD (premium) Azure file shares with SMB protocol and specific mount options: |
| 193 | +
|
| 194 | +```yaml |
| 195 | +apiVersion: storage.k8s.io/v1 |
| 196 | +kind: StorageClass |
| 197 | +metadata: |
| 198 | + name: azurefile-csi-premium |
| 199 | +provisioner: file.csi.azure.com |
| 200 | +parameters: |
| 201 | + skuName: Premium_LRS |
| 202 | + protocol: smb |
| 203 | +allowVolumeExpansion: true |
| 204 | +mountOptions: |
| 205 | + - dir_mode=0777 |
| 206 | + - file_mode=0777 |
| 207 | + - uid=0 |
| 208 | + - gid=0 |
| 209 | + - mfsymlinks |
| 210 | + - cache=strict |
| 211 | + - actimeo=30 |
| 212 | +``` |
| 213 | +
|
| 214 | +### Static provisioning |
| 215 | +
|
| 216 | +For existing Azure file shares, you can create persistent volumes that reference pre-created storage. |
| 217 | +
|
| 218 | +This YAML example shows how to create a persistent volume that references an existing Azure file share using static provisioning: |
| 219 | +
|
| 220 | +```yaml |
| 221 | +apiVersion: v1 |
| 222 | +kind: PersistentVolume |
| 223 | +metadata: |
| 224 | + name: existing-azurefile-pv |
| 225 | +spec: |
| 226 | + capacity: |
| 227 | + storage: 100Gi |
| 228 | + accessModes: |
| 229 | + - ReadWriteMany |
| 230 | + persistentVolumeReclaimPolicy: Retain |
| 231 | + storageClassName: azurefile-csi |
| 232 | + csi: |
| 233 | + driver: file.csi.azure.com |
| 234 | + readOnly: false |
| 235 | + volumeHandle: existing-file-share-id |
| 236 | + volumeAttributes: |
| 237 | + resourceGroup: myResourceGroup |
| 238 | + storageAccount: mystorageaccount |
| 239 | + shareName: myfileshare |
| 240 | + protocol: smb |
| 241 | +``` |
| 242 | +
|
| 243 | +## Recommended mount options |
| 244 | +
|
| 245 | +This YAML example shows optimized mount options for Azure Files to improve performance and compatibility. However, you should configure mount options to optimize performance for your specific use case. |
| 246 | +
|
| 247 | +```yaml |
| 248 | +mountOptions: |
| 249 | + - dir_mode=0755 |
| 250 | + - file_mode=0755 |
| 251 | + - uid=1000 |
| 252 | + - gid=1000 |
| 253 | + - mfsymlinks |
| 254 | + - cache=strict # Use strict caching for better performance |
| 255 | + - actimeo=30 # Attribute cache timeout |
| 256 | + - nobrl # Disable byte range locking for better performance |
| 257 | +``` |
| 258 | +
|
| 259 | +## Security best practice: use private endpoints |
| 260 | +
|
| 261 | +This YAML example demonstrates how to create Azure file storage with private endpoint configuration for enhanced security: |
| 262 | +
|
| 263 | +```yaml |
| 264 | +apiVersion: storage.k8s.io/v1 |
| 265 | +kind: StorageClass |
| 266 | +metadata: |
| 267 | + name: azurefile-csi |
| 268 | +provisioner: file.csi.azure.com |
| 269 | +allowVolumeExpansion: true |
| 270 | +parameters: |
| 271 | + skuName: Premium_LRS # available values: Premium_LRS, Premium_ZRS, Standard_LRS, Standard_GRS, Standard_ZRS, Standard_RAGRS, Standard_RAGZRS |
| 272 | + networkEndpointType: privateEndpoint |
| 273 | +reclaimPolicy: Delete |
| 274 | +volumeBindingMode: Immediate |
| 275 | +mountOptions: |
| 276 | + - dir_mode=0777 # modify this permission if you want to enhance the security |
| 277 | + - file_mode=0777 |
| 278 | + - mfsymlinks |
| 279 | + - cache=strict # https://linux.die.net/man/8/mount.cifs |
| 280 | + - nosharesock # reduce probability of reconnect race |
| 281 | + - actimeo=30 # reduce latency for metadata-heavy workload |
| 282 | + - nobrl # disable sending byte range lock requests to the server and for applications which have challenges with posix locks |
| 283 | +``` |
| 284 | +
|
| 285 | +## See also |
| 286 | +
|
| 287 | +- [Use Azure Files CSI driver in AKS](/azure/aks/azure-files-csi) |
| 288 | +- [Create and use a volume with Azure Files in AKS](/azure/aks/azure-csi-files-storage-provision) |
0 commit comments