Azure Container Apps Mount Volume for Kubernetes Deployments

Author

Reads 1.2K

Computer server in data center room
Credit: pexels.com, Computer server in data center room

Azure Container Apps allows you to mount volumes for Kubernetes deployments, enabling you to persist data even after your app is restarted or scaled.

This is especially useful for stateful applications that require data to be stored between container restarts.

You can mount a volume from an Azure File Share or an Azure Blob Storage container to your container app.

This allows you to share data between containers in the same app or even between different apps in the same cluster.

Storage Configuration

To configure replica-scoped storage, you need to define an EmptyDir volume in the revision. This type of storage is scoped to a single replica and has characteristics such as files being persisted for the lifetime of the replica.

You can mount an ephemeral, temporary volume that is equivalent to EmptyDir in Kubernetes. This storage is scoped to a single replica and can be shared between containers in the same replica.

Credit: youtube.com, Azure Container Apps - Volumes and Storage Mounts + Azure File Shares

To configure replica-scoped storage, first define an EmptyDir volume in the revision. Then define a volume mount in one or more containers in the revision.

Here are the steps to update an existing container app to use replica-scoped storage:

  1. Export your app's specification to a YAML file named app.yaml.
  2. Make changes to your container app specification.properties to include the EmptyDir volume.
  3. Update your container app using the YAML file.

Alternatively, you can create a replica-scoped volume and mount it in a container using an ARM template. To do this, add a volumes array to the template section of your container app definition and define a volume. Then, for each container in the template that you want to mount the volume, define a volume mount in the volumeMounts array of the container definition.

Here's a summary of the requirements for mounting an NFS share in Azure Container Apps:

Azure Files

Azure Files is a fully managed file share service in Azure that allows you to store and share files across different Azure services and on-premises locations.

You can mount an Azure File share as a network file system (NFS) or Server Message Block (SMB) share, making it easy to access and use your files from your Azure Container Apps.

Credit: youtube.com, Azure File Shares as Container Volume Mounts

Azure Files supports both SMB 2.1 and SMB 3.0 protocols, ensuring compatibility with a wide range of operating systems and applications.

Azure Container Apps can mount an Azure File share as a volume, allowing you to persist data across container restarts and scaling events.

Mounting an Azure File share as a volume is a simple process that can be done using the Azure portal, Azure CLI, or Azure SDKs.

Azure File shares can be accessed from anywhere, at any time, and can be easily scaled up or down to meet changing business needs.

Kubernetes Deployment

To create a Kubernetes deployment, you'll need to define the volume mounts. This involves specifying the path you want to mount the file share inside the container. For simplicity, you can use the same name as your actual file share.

The important things to note in the deployment are: volumeMounts: specify the path to mount the file share inside the containervolumes: define the azureFile entry with the secret name, referencing the Azure File share created earlier

You'll also need to create a secret that holds the connection details to your Storage account, and a deployment that deploys your image and mounts the Azure File share to the containers.

Create Kubernetes Deployment

Credit: youtube.com, Kubernetes YAML File Explained - Deployment and Service | Kubernetes Tutorial 19

To create a Kubernetes deployment, you'll want to define the volume mounts. This involves specifying the path you want to mount the file share inside the container.

You can choose any path you like, but for simplicity, you can use the same name as your actual file share. For example, you might use "myawesomefileshare".

Next, you'll need to define the volumes. This is where you specify the azureFile entry with the secret name. Make sure to use the name of the secret you created earlier, which holds the connection details to your Storage account.

Here are the key things to note when defining the volumes:

  • volumeMounts: specify the path to mount the file share inside the container
  • volumes: define the azureFile entry with the secret name

In your deployment, you'll need to reference the secret you created earlier. This will allow your containers to access the Azure File share.

Verify Kubernetes Volume Mounts

To verify that your Kubernetes volume mounts are working correctly, you need to check the deployment and running pods. You can do this by running the following commands in sequence.

Credit: youtube.com, Kubernetes Volumes explained | Persistent Volume, Persistent Volume Claim & Storage Class

The first step is to verify the volume mounts in the Kubernetes deployment. This can be done by checking the deployment itself, and then on any running pod. You can see that your deployment has defined a mount to the Azure file share as you had hoped.

You can verify the storage mount by opening an interactive shell inside the container app and executing commands inside the running container. This will allow you to interact with the storage mount via file system commands.

Here are the steps to verify the storage mount:

  1. Open an interactive shell inside the container app using the command `az containerapp exec --name $CONTAINER_APP_NAME --resource-group $RESOURCE_GROUP`.
  2. Change into the nginx /var/log/nginx folder using the command `cd /var/log/nginx`.
  3. Return to the browser and navigate to the website, then refresh the page a few times to create log stream entries.
  4. Return to your terminal and list the values of the /var/log/nginx folder using the command `ls`.
  5. View the contents of the access.log file using the command `cat access.log`.
  6. Exit out of the container's interactive shell to return to your local terminal session using the command `exit`.

Once you've verified the storage mount, you can view the files in the Azure portal to confirm they exist in your Azure Storage account.

Automating PowerShell Tasks

Automating PowerShell tasks is a game-changer for streamlining your workflow. By leveraging tools like Task Scheduler, you can set up scripts to run automatically at specific times or intervals.

You can use Task Scheduler to run PowerShell scripts with elevated permissions, which is crucial for tasks that require administrative access. This ensures that your scripts can perform tasks that require high-level access.

Credit: youtube.com, Azure Container Apps - (End to End Automation using PowerShell & Bicep)

PowerShell's built-in support for scripting makes it an ideal choice for automating tasks. With its extensive library of cmdlets and ability to execute scripts, you can create custom solutions for repetitive tasks.

One example of automating a task is mounting a volume in Azure Container Apps, which can be achieved by using the az container app update command with the --mount flag. This allows you to automate the process of mounting a volume without having to manually intervene.

Beatrice Giannetti

Senior Writer

Beatrice Giannetti is a seasoned blogger and writer with over a decade of experience in the industry. Her writing style is engaging and relatable, making her posts widely read and shared across social media platforms. She has a passion for travel, food, and fashion, which she often incorporates into her writing.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.