How to delete large number of files on Azure Kubernetes Service volume

9/6/2021

I have a process that creates a large number (~ 1M over 7 days) of files on AKS volume. I need to delete files that are older than 7 days.

I found this answer but the problem with this is that I need to run the script somewhere, so I need a repository of some sort for the script and then the service which has azure cli.

I am also thinking of just to have kubernetes Cron Job with simple alpine image and command:

find /path/to/files -mindepth 1 -mtime +7 -delete

this is nice, but it takes quite a lot of time (and CPU) to iterate through all the files.

Ideal scenario would be to have some kind retention policy on azure storage file share, but I was not able to find that.

Is there a better way to delete files from Azure File Share which is used by Azure Kubernetes Service than those that I described above?

-- Ramūnas
azure
azure-aks
azure-files
kubernetes

1 Answer

9/6/2021

You could just add logrotate as a sidecar Container to take care of the log retention.

-- Philip Welz
Source: StackOverflow