<p>I was successfully able to share data between a docker container and host using</p>
<pre><code>docker run -it -v /path/to/host/folder:/container/path image-name
</code></pre>
<p>Now I am trying to run this docker image through a Kubernetes cronjob every minute for which my yaml file is as follows :</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: automation
spec:
  schedule: &quot;*/1 * * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: automation
            image: localhost:32000/image-name:registry  
          restartPolicy: OnFailure
</code></pre>
<p>But here how do I share data between my local and k8s so as to basically replicate the <code>-v /path/to/host/folder:/container/path</code> functionality from the docker run command  ?
What should I add to my yaml file ?</p>
<p>Please help.</p>

nishant26900
<p>If you're just playing with <strong>one node</strong> and need to map a volume from this node to a pod running in the same node, then you need to use a <a href="https://kubernetes.io/docs/concepts/storage/volumes/#hostpath" rel="nofollow noreferrer">hostPath volume</a>.<br />
In summary, your code will look like this :</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: automation
spec:
  schedule: &quot;*/1 * * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: automation
            image: localhost:32000/image-name:registry  
            volumeMounts:
            - mountPath: /container/path
              name: test-volume
          restartPolicy: OnFailure
          volumes:
          - name: test-volume
            hostPath:
              # directory location on host
              path: /path/to/host/folder
              # this field is optional
              type: Directory

</code></pre>
<p>Warning, this will work only if you just have a <strong>one node cluster</strong>.</p>
<p>If you have a multi-node cluster, then you need to havec a look at distributed storage solution and how to use them with kubernetes.</p>
<p>Here is the <a href="https://kubernetes.io/docs/concepts/storage/volumes/" rel="nofollow noreferrer">doc about volumes in K8S</a></p>
