Automate Your Azure Disk Kubernetes Volume Backup

Yohan Belval
Workleap
Published in
2 min readNov 5, 2020

Azure Kubernetes Service uses Azure Disks as the default persistent volume storage option. If your persistent container-based application is business critical, chances are you want to regularly backup the disk volume. Microsoft’s best practice guidance suggests to use either disk snapshots or a third-party tool called Velero. Personally, I leaned towards the use of the built-in Azure snapshot mainly for simplicity’s sake. The main drawback of the disk snapshot method is that it isn’t automated. Here’s a solution to workaround this limitation.

Don’t Have The Right Tool? Then Build It! 🔧

Automating a task in Kubernetes is pretty simple; Just use the built-in CronJob resource to define a time-based scheduled task. Now, how do I execute an Azure disk snapshot from a CronJob’s container? Well, I built a .NET Core cli tool for that called az-snapshot-tool. With the help of the tool, you can create a snapshot in a few lines:

dotnet tool install --global dotnet-az-snapshot-toolaz-snapshot-tool create --tenantId xxx --subscriptionId xxx --resourceGroup myRg --diskName myDisk

Now that we have a tool to simplify the creation of disk snapshot, we can make use of the CronJob resource to schedule a recurring job:

Here’s what we can extract from the above yaml:

Example of produced disk snapshots.

There you go! Let me know of any issues and/or improvements through the github repository.

Cheers! 🍻

--

--

Yohan Belval
Workleap

Fullstack development, DevOps, SRE and Cloud is my jam.