Copy files between Kubernetes and cloud storage
Nov 4 · 2 min read
There is very nice tool ‘skbn’ to copy files and directories between Kubernetes and cloud storage. I’ve run it quickly to backup jenkins container directory ‘/mnt’ to Azure storage account ‘aks-backup’ container into directory ‘jenkins’.
export AZURE_STORAGE_ACCESS_KEY=XXX
export AZURE_STORAGE_ACCOUNT=azurestorageaccountskbn cp --src k8s://default/jenkins-659b68c99d-b29zl/jenkins/mnt --dst abs://azurestorageaccount/aks-backup/jenkins
Azure storage account name and key have to be exported into environmental variables.

The tool can be containerized and run on Kubernetes as task itself, see yaml file below.

Running the job:
$ kubectl apply -f examples/in-cluster/job.yaml
$ kubectl get jobs
NAME COMPLETIONS DURATION AGE
skbn 1/1 19s 2m46s
$ kubectl describe job skbn
....
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 3m13s job-controller Created pod: skbn-29822$ kubectl logs skbn-29822
....
2019/11/04 16:26:48 [28/28] done: k8s://default/minemeld-7795c667bb-pgc99/minemeld/opt/minemeld/local/config/running-config.yml -> abs://sta360spokeneteastus/aks-backup/minemeld/running-config.yml
To create cron job starting daily at midnight, just wrap up the job into the the relevant template:

To setup the cron job:
$ kubectl apply -f examples/in-cluster/cronjob-mm.yaml$ kubectl get cronjobs
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
skbn-mm 0 0 * * * False 0 <none> 2m23s
