Mounting Azure Files' Folder into Kubernetes: A Guide

Kubernetes has become a go-to platform for managing containerized applications at scale. However, managing persistent storage remains a challenge. In this blog post, we will guide you on how to mount an Azure Files' folder into a Kubernetes cluster, a crucial step for data scientists dealing with large datasets.

Mounting Azure Files' Folder into Kubernetes: A Guide

Kubernetes has become a go-to platform for managing containerized applications at scale. However, managing persistent storage remains a challenge. In this blog post, we will guide you on how to mount an Azure Files' folder into a Kubernetes cluster, a crucial step for data scientists dealing with large datasets.

Prerequisites

Before we start, ensure you have the following:

  • An active Azure subscription
  • A Kubernetes cluster running on Azure (AKS)
  • Azure CLI installed and configured
  • Kubernetes CLI (kubectl) installed and configured

Step 1: Create an Azure File Share

First, we need to create an Azure File Share. This will serve as our persistent storage.

# Create a resource group
az group create --name myResourceGroup --location eastus

# Create a storage account
az storage account create --name mystorageaccount --resource-group myResourceGroup --location eastus --sku Standard_LRS

# Create a file share
az storage share create --name myfileshare --account-name mystorageaccount

Step 2: Get Storage Account Key

Next, we need to retrieve the storage account key. This key will be used to access the file share.

# Get storage account key
az storage account keys list --resource-group myResourceGroup --account-name mystorageaccount --query "[0].value" --output tsv

Step 3: Create a Kubernetes Secret

We will create a Kubernetes secret to store the storage account name and key. This secret will be used to mount the Azure file share into the Kubernetes pod.

# Create a Kubernetes secret
kubectl create secret generic azure-secret --from-literal=azurestorageaccountname=mystorageaccount --from-literal=azurestorageaccountkey=<storage-account-key>

Step 4: Create a Persistent Volume

Now, we will create a Persistent Volume (PV) using the Azure file share. The PV represents the storage resource in the cluster.

# azure-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: azure-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  azureFile:
    secretName: azure-secret
    shareName: myfileshare
    readOnly: false
  mountOptions:
    - dir_mode=0777
    - file_mode=0777
    - uid=1000
    - gid=1000

Apply the PV configuration using kubectl apply -f azure-pv.yaml.

Step 5: Create a Persistent Volume Claim

Next, we create a Persistent Volume Claim (PVC). The PVC is a request for storage by a user.

# azure-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: azure-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 5Gi

Apply the PVC configuration using kubectl apply -f azure-pvc.yaml.

Step 6: Mount the Azure File Share into a Pod

Finally, we can mount the Azure file share into a Kubernetes pod.

# azure-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: azure-pod
spec:
  containers:
  - name: azure
    image: mcr.microsoft.com/oss/nginx/nginx:1.15.5-alpine
    volumeMounts:
    - name: azure
      mountPath: /mnt/azure
  volumes:
  - name: azure
    persistentVolumeClaim:
      claimName: azure-pvc

Apply the pod configuration using kubectl apply -f azure-pod.yaml.

Conclusion

In this post, we’ve walked through the process of mounting an Azure Files' folder into a Kubernetes cluster. This is a crucial step for data scientists dealing with large datasets, as it allows for persistent storage and easy data access. With this guide, you should now be able to integrate Azure Files with your Kubernetes applications seamlessly.

Keywords

  • Kubernetes
  • Azure Files
  • Persistent Storage
  • Data Science
  • Azure Kubernetes Service
  • Azure CLI
  • Kubernetes CLI
  • Persistent Volume
  • Persistent Volume Claim

About Saturn Cloud

Saturn Cloud is your all-in-one solution for data science & ML development, deployment, and data pipelines in the cloud. Spin up a notebook with 4TB of RAM, add a GPU, connect to a distributed cluster of workers, and more. Join today and get 150 hours of free compute per month.