Copy files between Kubernetes and cloud storage

Irek Romaniuk
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=azurestorageaccount
skbn 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.

kube-task to backup jenkins into Azure Blob Storage

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

To create kube-task job

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 create kube-task cron job

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
Irek Romaniuk

Written by

Here are my ‘nanonotes’, excuse the brevity and typos. I’m based in RI, working as security and automation engineer for a fin-tech company in Boston.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade