Is there a way to run a scheduled job that would pull some files regurarly on a mounted shared volume?
I have tried cronjob but apparently it doesn't supposed external filesystems
thanks in advance.
Is there a way to run a scheduled job that would pull some files regurarly on a mounted shared volume?
I have tried cronjob but apparently it doesn't supposed external filesystems
thanks in advance.
CronJobs should be able to mount PVC just as any other resource which spawn Pods, you can just add a volumeMounts
section under the container
template, and then a volume
section under template
.
Something like the following:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: example-name
spec:
schedule: '0 * * * *'
jobTemplate:
spec:
completions: 1
template:
spec:
containers:
- name: example-container-name
image: your-docker-repo/your-docker-image:the-tag
volumeMounts:
- name: data
mountPath: /internal/path/to/mount/pvc
volumes:
- name: data
persistentVolumeClaim:
claimName: example-claim
This should mount example-claim
PVC to the CronJob's Pod when the Pod is spawned.
Basically there are two sections.. under each container volumeMounts list the volumes mounted by the container, at which path and a few more configuration. All the volumeMounts entries should be defined once in the volumes section which associate names (that act as keys for the spec) and claims or empty-dir.
As for creating the PVC, let me link you the documentation (https://kubernetes.io/docs/concepts/storage/persistent-volumes/)
What you want to do basically is to create a Persistent Volume which points to your mounted shared volume (what is it, a nfs storage? The declaration changes slightly, depending on what exactly you want to mount) and then a Claim (PVC) in the same namespace of the CronJob which will bound to the PV.
If you are unsure about the correct indentation of the various objects or where to put things, check the practical API Reference Docs (https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#cronjob-v1beta1-batch)