Right now I have a cronjob that downloads data and I want to share it to another container that does the processing for the data as new ones are uploaded. I wanted to know if there was a way without any external services to share this data between the cronjob pod and my main pod?
I've tried creating a persistent volume and persistent volume claim to share the data but when the cronjob downloads the data it doesn't appear in the other pod even though the volume is mounted.
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: download
spec:
concurrencyPolicy: Forbid
suspend: false
schedule: "* * * * *"
jobTemplate:
spec:
template:
spec:
volumes:
- name: downloaded-data-claim
persistentVolumeClaim:
claimName: downloaded-data-claim
#container and image is here where it downloads
kind: PersistentVolume
metadata:
name: downloaded-data
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
claimRef:
name: downloaded-data-claim
namespace: default
hostPath:
path: "/tmp/"
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: downloaded-data-claim
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
volumeName: downloaded-data
and then the pod mounts the volume
volumes:
- name: downloaded-data-claim
presistentVolumeClaim:
claimName: downloaded-data-claim
- name: output
emptyDir: {}
containers:
- name: "rand"
image: <filler>
imagePullPolicy: <filler>
volumeMounts:
- name: downloaded-data-claim
mountPath: /input
- name: output
mountPath: /output
resources:
Make sure you have created CronJob in right namespace - where your pod and pv are. Take notice if you have access to directory where you want your data to be stored.
Actually I don't think there is other possiblity than using external services. Most useful are nfs volumes. But there are based on services and external nfs servers. NFS stands for Network File System – it's a shared filesystem that can be accessed over the network. The NFS must already exist – Kubernetes doesn't run the NFS, pods in just access it.