|
| 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: 06/30/2025 |
| 8 | +ms.author: kendownie |
| 9 | +# 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." |
| 10 | +--- |
| 11 | + |
| 12 | +# Azure Files guidance for Azure Kubernetes Service (AKS) workloads |
| 13 | + |
| 14 | +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. |
| 15 | + |
| 16 | +## What is Azure Kubernetes Service? |
| 17 | + |
| 18 | +Azure Kubernetes Service (AKS) is a managed Kubernetes service that simplifies deploying, managing, and scaling containerized applications using Kubernetes on Azure. AKS reduces the complexity and operational overhead of managing Kubernetes by offloading much of that responsibility to Azure. As a hosted Kubernetes service, Azure handles critical tasks like health monitoring and maintenance, while you focus on your application workloads. |
| 19 | + |
| 20 | +## Why Azure Files for Azure Kubernetes Service? |
| 21 | + |
| 22 | +Azure Files is an ideal storage solution for AKS workloads due to several advantages: |
| 23 | + |
| 24 | +### Persistent shared storage |
| 25 | + |
| 26 | +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. |
| 27 | + |
| 28 | +### Kubernetes native integration |
| 29 | + |
| 30 | +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 PersistentVolumes (PV) and PersistentVolumeClaims (PVC). The CSI driver handles all the complexity of Azure API interactions, authentication, and mount operations, providing a native Kubernetes experience for storage management. |
| 31 | + |
| 32 | +### Multiple performance tiers |
| 33 | + |
| 34 | +Azure Files offers multiple performance tiers to match your workload requirements: |
| 35 | + |
| 36 | +- **HDD (Standard)**: Cost-effective for general-purpose workloads |
| 37 | +- **SSD (Premium)**: High-performance SSD-backed storage for I/O intensive applications |
| 38 | +- **Transaction optimized**: Optimized for workloads with high transaction rates |
| 39 | + |
| 40 | +### Protocol support |
| 41 | + |
| 42 | +Support for both NFS and SMB protocols ensures compatibility with a wide range of applications and operating systems, including Linux and Windows containers. |
| 43 | + |
| 44 | +### Security and compliance |
| 45 | + |
| 46 | +Azure Files provides enterprise-grade security features including encryption at rest, encryption in transit, Microsoft Entra ID integration, and compliance with industry standards. |
| 47 | + |
| 48 | +## Understanding the Azure Files CSI driver |
| 49 | + |
| 50 | +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. |
| 51 | + |
| 52 | +### How the CSI driver works |
| 53 | + |
| 54 | +The Azure Files CSI driver operates through several key components: |
| 55 | + |
| 56 | +- **CSI driver pod**: Runs as a DaemonSet on each node in the AKS cluster, responsible for mounting and unmounting Azure file shares |
| 57 | +- **CSI controller**: Manages the lifecycle of Azure Files shares, including creation, deletion, and volume expansion |
| 58 | +- **Storage classes**: Define the parameters and policies for dynamic provisioning of Azure file shares |
| 59 | +- **Persistent volumes (PV)**: Represent the actual Azure Files shares in Kubernetes |
| 60 | +- **Persistent volume claims (PVC)**: User requests for storage that are bound to persistent volumes |
| 61 | + |
| 62 | +When a pod requests storage through a PVC, the CSI driver coordinates with Azure APIs to either create a new Azure file share (dynamic provisioning) or connect to an existing share (static provisioning). The driver then mounts the share into the pod's filesystem namespace, making it accessible to applications. |
| 63 | + |
| 64 | +### CSI driver capabilities |
| 65 | + |
| 66 | +The Azure Files CSI driver provides several advanced capabilities: |
| 67 | + |
| 68 | +- **Dynamic volume provisioning**: Automatically creates Azure file shares based on storage class definitions |
| 69 | +- **Volume expansion**: Supports online expansion of existing Azure file shares |
| 70 | +- **Snapshot support**: Enables point-in-time snapshots for backup and recovery scenarios |
| 71 | +- **Cross-platform compatibility**: Works with both Linux and Windows node pools in AKS |
| 72 | + |
| 73 | +### Driver installation and management |
| 74 | + |
| 75 | +In AKS clusters, the Azure Files CSI driver is installed and managed automatically. |
| 76 | + |
| 77 | +This YAML demonstrates the DaemonSet configuration for the Azure Files CSI driver node components, which run on every node in the AKS cluster to handle volume mounting operations: |
| 78 | + |
| 79 | +```yaml |
| 80 | +# Example of CSI driver components (managed automatically in AKS) |
| 81 | +apiVersion: apps/v1 |
| 82 | +kind: DaemonSet |
| 83 | +metadata: |
| 84 | + name: csi-azurefile-node |
| 85 | + namespace: kube-system |
| 86 | +spec: |
| 87 | + selector: |
| 88 | + matchLabels: |
| 89 | + app: csi-azurefile-node |
| 90 | + template: |
| 91 | + spec: |
| 92 | + containers: |
| 93 | + - name: node-driver-registrar |
| 94 | + image: mcr.microsoft.com/oss/kubernetes-csi/node-driver-registrar:v2.5.0 |
| 95 | + - name: azurefile |
| 96 | + image: mcr.microsoft.com/oss/kubernetes-csi/azurefile-csi:v1.18.0 |
| 97 | + securityContext: |
| 98 | + privileged: true |
| 99 | +``` |
| 100 | +
|
| 101 | +## Common use cases for Azure Files with AKS |
| 102 | +
|
| 103 | +Some common use cases for Azure Files with AKS include: |
| 104 | +
|
| 105 | +- **Shared configuration and secrets management**: Azure Files enables centralized storage of configuration files, certificates, and other shared resources that multiple pods need to access. |
| 106 | +- **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. |
| 107 | +- **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. |
| 108 | +- **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. |
| 109 | +- **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. |
| 110 | +
|
| 111 | +### Shared configuration and secrets management |
| 112 | +
|
| 113 | +Azure Files is particularly useful for: |
| 114 | +
|
| 115 | +- **Configuration management**: Store application configuration files that need to be shared across multiple instances. |
| 116 | +- **Certificate distribution**: Centrally manage and distribute SSL/TLS certificates. |
| 117 | +- **Shared libraries**: Store common libraries or binaries accessed by multiple applications. |
| 118 | +
|
| 119 | +This YAML example creates a PVC for shared configuration storage and a deployment that mounts this storage across multiple pod replicas: |
| 120 | +
|
| 121 | +```yaml |
| 122 | +apiVersion: v1 |
| 123 | +kind: PersistentVolumeClaim |
| 124 | +metadata: |
| 125 | + name: config-storage |
| 126 | +spec: |
| 127 | + accessModes: |
| 128 | + - ReadWriteMany |
| 129 | + storageClassName: azurefile |
| 130 | + resources: |
| 131 | + requests: |
| 132 | + storage: 10Gi |
| 133 | +--- |
| 134 | +apiVersion: apps/v1 |
| 135 | +kind: Deployment |
| 136 | +metadata: |
| 137 | + name: app-deployment |
| 138 | +spec: |
| 139 | + replicas: 3 |
| 140 | + selector: |
| 141 | + matchLabels: |
| 142 | + app: myapp |
| 143 | + template: |
| 144 | + metadata: |
| 145 | + labels: |
| 146 | + app: myapp |
| 147 | + spec: |
| 148 | + containers: |
| 149 | + - name: myapp |
| 150 | + image: myapp:latest |
| 151 | + volumeMounts: |
| 152 | + - name: config-volume |
| 153 | + mountPath: /app/config |
| 154 | + volumes: |
| 155 | + - name: config-volume |
| 156 | + persistentVolumeClaim: |
| 157 | + claimName: config-storage |
| 158 | +``` |
| 159 | +
|
| 160 | +### Log aggregation and centralized logging |
| 161 | +
|
| 162 | +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. |
| 163 | +
|
| 164 | +This YAML example demonstrates a DaemonSet for log collection with a shared Azure Files storage for centralized log aggregation: |
| 165 | +
|
| 166 | +```yaml |
| 167 | +apiVersion: v1 |
| 168 | +kind: PersistentVolumeClaim |
| 169 | +metadata: |
| 170 | + name: logs-storage |
| 171 | +spec: |
| 172 | + accessModes: |
| 173 | + - ReadWriteMany |
| 174 | + storageClassName: azurefile |
| 175 | + resources: |
| 176 | + requests: |
| 177 | + storage: 100Gi |
| 178 | +--- |
| 179 | +apiVersion: apps/v1 |
| 180 | +kind: DaemonSet |
| 181 | +metadata: |
| 182 | + name: log-collector |
| 183 | +spec: |
| 184 | + selector: |
| 185 | + matchLabels: |
| 186 | + app: log-collector |
| 187 | + template: |
| 188 | + metadata: |
| 189 | + labels: |
| 190 | + app: log-collector |
| 191 | + spec: |
| 192 | + containers: |
| 193 | + - name: log-collector |
| 194 | + image: fluent/fluent-bit:latest |
| 195 | + volumeMounts: |
| 196 | + - name: logs-volume |
| 197 | + mountPath: /logs |
| 198 | + - name: varlog |
| 199 | + mountPath: /var/log |
| 200 | + readOnly: true |
| 201 | + volumes: |
| 202 | + - name: logs-volume |
| 203 | + persistentVolumeClaim: |
| 204 | + claimName: logs-storage |
| 205 | + - name: varlog |
| 206 | + hostPath: |
| 207 | + path: /var/log |
| 208 | +``` |
| 209 | +
|
| 210 | +
|
| 211 | +## Storage classes and provisioning options |
| 212 | +
|
| 213 | +Azure Files CSI driver supports both static and dynamic provisioning through Kubernetes storage classes: |
| 214 | +
|
| 215 | +### Dynamic provisioning |
| 216 | +
|
| 217 | +With dynamic provisioning, storage is automatically created when a persistent volume claim is created. |
| 218 | +
|
| 219 | +This YAML defines a StorageClass for dynamic provisioning of premium Azure Files shares with SMB protocol and specific mount options: |
| 220 | +
|
| 221 | +```yaml |
| 222 | +apiVersion: storage.k8s.io/v1 |
| 223 | +kind: StorageClass |
| 224 | +metadata: |
| 225 | + name: azurefile-csi-premium |
| 226 | +provisioner: file.csi.azure.com |
| 227 | +parameters: |
| 228 | + skuName: Premium_LRS |
| 229 | + protocol: smb |
| 230 | +allowVolumeExpansion: true |
| 231 | +mountOptions: |
| 232 | + - dir_mode=0777 |
| 233 | + - file_mode=0777 |
| 234 | + - uid=0 |
| 235 | + - gid=0 |
| 236 | + - mfsymlinks |
| 237 | + - cache=strict |
| 238 | + - actimeo=30 |
| 239 | +``` |
| 240 | +
|
| 241 | +### Static provisioning |
| 242 | +
|
| 243 | +For existing Azure Files shares, you can create persistent volumes that reference pre-created storage. |
| 244 | +
|
| 245 | +This YAML example shows how to create a Persistent Volume that references an existing Azure file share using static provisioning: |
| 246 | +
|
| 247 | +```yaml |
| 248 | +apiVersion: v1 |
| 249 | +kind: PersistentVolume |
| 250 | +metadata: |
| 251 | + name: existing-azurefile-pv |
| 252 | +spec: |
| 253 | + capacity: |
| 254 | + storage: 100Gi |
| 255 | + accessModes: |
| 256 | + - ReadWriteMany |
| 257 | + persistentVolumeReclaimPolicy: Retain |
| 258 | + storageClassName: azurefile-csi |
| 259 | + csi: |
| 260 | + driver: file.csi.azure.com |
| 261 | + readOnly: false |
| 262 | + volumeHandle: existing-file-share-id |
| 263 | + volumeAttributes: |
| 264 | + resourceGroup: myResourceGroup |
| 265 | + storageAccount: mystorageaccount |
| 266 | + shareName: myfileshare |
| 267 | + protocol: smb |
| 268 | +``` |
| 269 | +
|
| 270 | +
|
| 271 | +## Optimize mount options |
| 272 | +
|
| 273 | +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. |
| 274 | +
|
| 275 | +```yaml |
| 276 | +mountOptions: |
| 277 | + - dir_mode=0755 |
| 278 | + - file_mode=0755 |
| 279 | + - uid=1000 |
| 280 | + - gid=1000 |
| 281 | + - mfsymlinks |
| 282 | + - cache=strict # Use strict caching for better performance |
| 283 | + - actimeo=30 # Attribute cache timeout |
| 284 | + - nobrl # Disable byte range locking for better performance |
| 285 | +``` |
| 286 | +
|
| 287 | +## Security best practice: use private endpoints |
| 288 | +
|
| 289 | +This YAML example demonstrates how to create Azure file storage with private endpoint configuration for enhanced security: |
| 290 | +
|
| 291 | +```yaml |
| 292 | +# Example of using private endpoints with Azure Files |
| 293 | +apiVersion: v1 |
| 294 | +kind: Secret |
| 295 | +metadata: |
| 296 | + name: azure-secret |
| 297 | +type: Opaque |
| 298 | +data: |
| 299 | + azurestorageaccountname: <base64-encoded-account-name> |
| 300 | + azurestorageaccountkey: <base64-encoded-account-key> |
| 301 | +--- |
| 302 | +apiVersion: storage.k8s.io/v1 |
| 303 | +kind: StorageClass |
| 304 | +metadata: |
| 305 | + name: azurefile-csi-private |
| 306 | +provisioner: file.csi.azure.com |
| 307 | +parameters: |
| 308 | + skuName: Premium_LRS |
| 309 | + protocol: smb |
| 310 | + networkEndpointType: privateEndpoint |
| 311 | +``` |
| 312 | +
|
0 commit comments