<p>I need to copy a file (.txt) to a PersistentVolume?</p>
<pre><code>kubectl cp &lt;file-spec-src&gt; &lt;file-spec-dest&gt;
</code></pre>
<p>I need to know the <code>&lt;file-spec-dest&gt;</code> for PersistentVolume.</p>
<p>Backgroud: I have a single-node Kubernetes-Cluster<a href="https://i.stack.imgur.com/OdyjI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OdyjI.png" alt="enter image description here" /></a> (docker-desktop) running locally on my mac. I am trying to copy a .txt file to a PersistentVolume (PV). I have create the PV and the PersistentVolumeClaim (PVC).</p>
<p>Note: I have been asked if it would make more sense with a pod instead of persistentVolume. The aim is that an image that will run as a Kubernetes Job will be using the data in the .txt file.</p>
<p>PersistentVolume:</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: &quot;/mnt/data&quot;
</code></pre>
<p>PersistentVolumeClaim:</p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: task-pv-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi
</code></pre>
<p>here is what i get with <code>kubectl get pvc -o yaml</code></p>
<pre><code>apiVersion: v1
items:
- apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    annotations:
      pv.kubernetes.io/bind-completed: &quot;yes&quot;
      pv.kubernetes.io/bound-by-controller: &quot;yes&quot;
      volume.beta.kubernetes.io/storage-provisioner: docker.io/hostpath
    creationTimestamp: &quot;2021-02-18T15:06:19Z&quot;
    finalizers:
    - kubernetes.io/pvc-protection
    managedFields:
    - apiVersion: v1
      fieldsType: FieldsV1
      fieldsV1:
        f:metadata:
          f:annotations:
            .: {}
            f:pv.kubernetes.io/bind-completed: {}
            f:pv.kubernetes.io/bound-by-controller: {}
            f:volume.beta.kubernetes.io/storage-provisioner: {}
        f:spec:
          f:volumeName: {}
        f:status:
          f:accessModes: {}
          f:capacity:
            .: {}
            f:storage: {}
          f:phase: {}
      manager: kube-controller-manager
      operation: Update
      time: &quot;2021-02-18T15:06:19Z&quot;
    - apiVersion: v1
      fieldsType: FieldsV1
      fieldsV1:
        f:spec:
          f:accessModes: {}
          f:resources:
            f:requests:
              .: {}
              f:storage: {}
          f:volumeMode: {}
      manager: kubectl-create
      operation: Update
      time: &quot;2021-02-18T15:06:19Z&quot;
    name: task-pv-claim
    namespace: default
    resourceVersion: &quot;113659&quot;
    selfLink: /api/v1/namespaces/default/persistentvolumeclaims/task-pv-claim
    uid: 5b825c41-cf4f-4c08-b90e-47e3fca557a1
  spec:
    accessModes:
    - ReadWriteOnce
    resources:
      requests:
        storage: 3Gi
    storageClassName: hostpath
    volumeMode: Filesystem
    volumeName: pvc-5b825c41-cf4f-4c08-b90e-47e3fca557a1
  status:
    accessModes:
    - ReadWriteOnce
    capacity:
      storage: 3Gi
    phase: Bound
kind: List
metadata:
  resourceVersion: &quot;&quot;
  selfLink: &quot;&quot;
</code></pre>

QBits
<p>The destination directory is the one that you use in pod/job manifest as <code>mountPath</code>. So if you choose to mount it in <code>/mnt/data</code> it will be your destination directory. For example:</p>
<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:
    spec:
      volumes:
        - name: task-pv-claim
          hostPath:
            path: /mnt/data
            type: Directory
      containers:
      - name: pi
        image: nginx
        command: [&quot;some_job&quot;]
        volumeMounts:
         - name: task-pv-claim
           mountPath: /mnt/data
      restartPolicy: Never
</code></pre>
<p>So if you want to copy file from host to directory you have mounted:</p>
<pre><code>kubectl cp &lt;some_host_file&gt; &lt;pod_name&gt;/:/mnt/data
</code></pre>
<p>Besides that, if you are using <code>hostPath</code> it copies file from your host to pod in specified directory so you can just place your file there and it will be copied to the pod.</p>
